Skip to content

Commit

Permalink
eventcachemetrics: Constrain error label values
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
  • Loading branch information
lambdanis committed Feb 26, 2024
1 parent d9c9a7a commit 79dd881
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/grpc/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func GetProcessExec(event *MsgExecveEventUnix, useCache bool) *tetragon.ProcessE
}

if tetragonProcess.Pid == nil {
eventcachemetrics.EventCacheError("GetProcessExec: nil Process.Pid", notify.EventType(tetragonEvent)).Inc()
eventcachemetrics.EventCacheError(eventcachemetrics.NilProcessPid, notify.EventType(tetragonEvent)).Inc()
return nil
}

Expand Down Expand Up @@ -394,7 +394,7 @@ func GetProcessExit(event *MsgExitEventUnix) *tetragon.ProcessExit {
}

if tetragonProcess.Pid == nil {
eventcachemetrics.EventCacheError("GetProcessExit: nil Process.Pid", notify.EventType(tetragonEvent)).Inc()
eventcachemetrics.EventCacheError(eventcachemetrics.NilProcessPid, notify.EventType(tetragonEvent)).Inc()
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/grpc/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func GetProcessKprobe(event *MsgGenericKprobeUnix) *tetragon.ProcessKprobe {
}

if tetragonProcess.Pid == nil {
eventcachemetrics.EventCacheError("GetProcessKprobe: nil Process.Pid", notify.EventType(tetragonEvent)).Inc()
eventcachemetrics.EventCacheError(eventcachemetrics.NilProcessPid, notify.EventType(tetragonEvent)).Inc()
return nil
}

Expand Down Expand Up @@ -447,7 +447,7 @@ func (msg *MsgGenericTracepointUnix) HandleMessage() *tetragon.GetEventsResponse
}

if tetragonProcess.Pid == nil {
eventcachemetrics.EventCacheError("GetProcessTracepoint: nil Process.Pid", notify.EventType(tetragonEvent)).Inc()
eventcachemetrics.EventCacheError(eventcachemetrics.NilProcessPid, notify.EventType(tetragonEvent)).Inc()
return nil
}

Expand Down Expand Up @@ -574,7 +574,7 @@ func GetProcessLoader(msg *MsgProcessLoaderUnix) *tetragon.ProcessLoader {
}

if tetragonProcess.Pid == nil {
eventcachemetrics.EventCacheError("GetProcessLoader: nil Process.Pid", notify.EventType(notifyEvent)).Inc()
eventcachemetrics.EventCacheError(eventcachemetrics.NilProcessPid, notify.EventType(notifyEvent)).Inc()
return nil
}

Expand Down Expand Up @@ -683,7 +683,7 @@ func GetProcessUprobe(event *MsgGenericUprobeUnix) *tetragon.ProcessUprobe {
}

if tetragonProcess.Pid == nil {
eventcachemetrics.EventCacheError("GetProcessUprobe: nil Process.Pid", notify.EventType(tetragonEvent)).Inc()
eventcachemetrics.EventCacheError(eventcachemetrics.NilProcessPid, notify.EventType(tetragonEvent)).Inc()
return nil
}

Expand Down
14 changes: 12 additions & 2 deletions pkg/metrics/eventcachemetrics/eventcachemetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ var cacheEntryTypeLabelValues = map[CacheEntryType]string{
PodInfo: "pod_info",
}

type CacheError int

const (
NilProcessPid CacheError = iota
)

var cacheErrorLabelValues = map[CacheError]string{
NilProcessPid: "nil_process_pid",
}

var (
processInfoErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: consts.MetricsNamespace,
Expand Down Expand Up @@ -97,8 +107,8 @@ func PodInfoError(eventType tetragon.EventType) prometheus.Counter {
}

// Get a new handle on an processInfoErrors metric for an eventType
func EventCacheError(err string, eventType tetragon.EventType) prometheus.Counter {
return eventCacheErrorsTotal.WithLabelValues(err, eventType.String())
func EventCacheError(t CacheError, eventType tetragon.EventType) prometheus.Counter {
return eventCacheErrorsTotal.WithLabelValues(cacheErrorLabelValues[t], eventType.String())
}

// Get a new handle on the eventCacheRetriesTotal metric for an entryType
Expand Down

0 comments on commit 79dd881

Please sign in to comment.