Skip to content

Commit

Permalink
watcher: add metrics for deleted pod cache
Browse files Browse the repository at this point in the history
Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Sep 19, 2024
1 parent 27df62b commit 3cefc44
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/content/en/docs/reference/metrics.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pkg/metrics/watchermetrics/watchermetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,26 @@ var (
Help: "The total number of events for a given watcher type.",
ConstLabels: nil,
}, []string{"watcher"})

WatcherDeletedPodCacheHits = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: consts.MetricsNamespace,
Name: "watcher_delete_pod_cache_hits",
Help: "The total hits for pod information in the deleted pod cache.",
ConstLabels: nil,
})
)

func RegisterMetrics(group metrics.Group) {
group.MustRegister(WatcherErrors)
group.MustRegister(WatcherEvents)
group.MustRegister(WatcherDeletedPodCacheHits)
}

func InitMetrics() {
// Initialize metrics with labels
GetWatcherEvents(K8sWatcher).Add(0)
GetWatcherErrors(K8sWatcher, FailedToGetPodError).Add(0)
GetWatcherDeletedPodCacheHits().Add(0)
}

// Get a new handle on an WatcherEvents metric for a watcher type
Expand All @@ -66,3 +75,7 @@ func GetWatcherEvents(watcherType Watcher) prometheus.Counter {
func GetWatcherErrors(watcherType Watcher, watcherError ErrorType) prometheus.Counter {
return WatcherErrors.WithLabelValues(watcherType.String(), string(watcherError))
}

func GetWatcherDeletedPodCacheHits() prometheus.Counter {
return WatcherDeletedPodCacheHits
}
2 changes: 2 additions & 0 deletions pkg/watcher/deleted_pod_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package watcher

import (
"github.com/cilium/tetragon/pkg/logger"
"github.com/cilium/tetragon/pkg/metrics/watchermetrics"
lru "github.com/hashicorp/golang-lru/v2"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -81,5 +82,6 @@ func (c *deletedPodCache) findContainer(containerID string) (*corev1.Pod, *corev
return nil, nil, false
}

watchermetrics.GetWatcherDeletedPodCacheHits().Inc()
return v.pod, v.contStatus, true
}

0 comments on commit 3cefc44

Please sign in to comment.