Skip to content

Commit

Permalink
fix: processLru migrated towards ProcessCacheTotal as separate metric
Browse files Browse the repository at this point in the history
processLru migrated towards ProcessCacheTotal as separate metric

Signed-off-by: sadath-12 <sadathsadu2002@gmail.com>
  • Loading branch information
sadath-12 committed Feb 22, 2024
1 parent 36d7177 commit 51688bb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
8 changes: 4 additions & 4 deletions pkg/metrics/eventcachemetrics/eventcachemetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ func InitMetrics(registry *prometheus.Registry) {
registry.MustRegister(parentInfoErrors)
}

// Get a new handle on an processInfoErrors metric for an eventType
// Get a new handle on a processInfoErrors metric for an eventType
func ProcessInfoError(eventType string) prometheus.Counter {
return processInfoErrors.WithLabelValues(eventType)
}

// Get a new handle on an processInfoErrors metric for an eventType
// Get a new handle on a podInfoErrors metric for an eventType
func PodInfoError(eventType string) prometheus.Counter {
return podInfoErrors.WithLabelValues(eventType)
}

// Get a new handle on an processInfoErrors metric for an eventType
// Get a new handle on an eventCacheErrorsTotal metric for an error
func EventCacheError(err string) prometheus.Counter {
return eventCacheErrorsTotal.WithLabelValues(err)
}

// Get a new handle on the eventCacheRetriesTotal metric for an entryType
// Get a new handle on an eventCacheRetriesTotal metric for an entryType
func EventCacheRetries(entryType string) prometheus.Counter {
return eventCacheRetriesTotal.WithLabelValues(entryType)
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/metrics/metricsconfig/initmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/cilium/tetragon/pkg/metrics/syscallmetrics"
"github.com/cilium/tetragon/pkg/metrics/watchermetrics"
"github.com/cilium/tetragon/pkg/observer"
"github.com/cilium/tetragon/pkg/process"
"github.com/cilium/tetragon/pkg/version"
grpcmetrics "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -46,7 +45,6 @@ func InitAllMetrics(registry *prometheus.Registry) {
// register BPF collectors
registry.MustRegister(mapmetrics.NewBPFCollector(
observer.NewBPFCollector(),
process.NewBPFCollector(),
))
registry.MustRegister(eventmetrics.NewBPFCollector())

Expand Down
29 changes: 9 additions & 20 deletions pkg/process/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,17 @@
package process

import (
"fmt"

"github.com/cilium/tetragon/pkg/metrics/mapmetrics"
"github.com/cilium/tetragon/pkg/metrics/consts"
"github.com/prometheus/client_golang/prometheus"
)

// bpfCollector implements prometheus.Collector. It collects metrics directly from BPF maps.
type bpfCollector struct{}

func NewBPFCollector() prometheus.Collector {
return &bpfCollector{}
}

func (c *bpfCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- mapmetrics.MapSize.Desc()
}
var ProcessCacheTotal = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: consts.MetricsNamespace,
Name: "process_cache_size",
Help: "The size of the process cache",
ConstLabels: nil,
})

func (c *bpfCollector) Collect(ch chan<- prometheus.Metric) {
if procCache != nil {
ch <- mapmetrics.MapSize.MustMetric(
float64(procCache.len()),
"processLru", fmt.Sprint(procCache.size),
)
}
func InitMetrics(registry *prometheus.Registry) {
registry.MustRegister(ProcessCacheTotal)
}
3 changes: 3 additions & 0 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func InitCache(w watcher.K8sResourceWatcher, size int) error {
func FreeCache() {
procCache.Purge()
procCache = nil
ProcessCacheTotal.Set(0)
}

// GetProcessCopy() duplicates tetragon.Process and returns it
Expand Down Expand Up @@ -462,6 +463,7 @@ func AddExecEvent(event *tetragonAPI.MsgExecveEventUnix) *ProcessInternal {
}

procCache.add(proc)
ProcessCacheTotal.Inc()
return proc
}

Expand All @@ -485,6 +487,7 @@ func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) error {

parent.RefInc()
procCache.add(proc)
ProcessCacheTotal.Inc()
return nil
}

Expand Down

0 comments on commit 51688bb

Please sign in to comment.