Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.1] Fix tetragon_process_cache_size metric #2910

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/process/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ func (pc *Cache) refInc(p *ProcessInternal) {
atomic.AddUint32(&p.refcnt, 1)
}

func (pc *Cache) Purge() {
func (pc *Cache) purge() {
pc.stopChan <- true
processCacheTotal.Set(0)
}

func NewCache(
Expand Down Expand Up @@ -159,12 +160,17 @@ func (pc *Cache) get(processID string) (*ProcessInternal, error) {
// clone or execve events
func (pc *Cache) add(process *ProcessInternal) bool {
evicted := pc.cache.Add(process.process.ExecId, process)
if !evicted {
processCacheTotal.Inc()
}
return evicted
}

func (pc *Cache) remove(process *tetragon.Process) bool {
present := pc.cache.Remove(process.ExecId)
if !present {
if present {
processCacheTotal.Dec()
} else {
errormetrics.ErrorTotalInc(errormetrics.ProcessCacheMissOnRemove)
}
return present
Expand Down
4 changes: 2 additions & 2 deletions pkg/process/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

var ProcessCacheTotal = prometheus.NewGauge(prometheus.GaugeOpts{
var processCacheTotal = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: consts.MetricsNamespace,
Name: "process_cache_size",
Help: "The size of the process cache",
Expand Down Expand Up @@ -46,6 +46,6 @@ func NewCacheCollector() prometheus.Collector {
}

func InitMetrics(registry *prometheus.Registry) {
registry.MustRegister(ProcessCacheTotal)
registry.MustRegister(processCacheTotal)
registry.MustRegister(NewCacheCollector())
}
5 changes: 1 addition & 4 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ func InitCache(w watcher.K8sResourceWatcher, size int) error {
}

func FreeCache() {
procCache.Purge()
procCache.purge()
procCache = nil
ProcessCacheTotal.Set(0)
}

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

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

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

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

Expand Down
Loading