Skip to content

Commit

Permalink
reset ebpf global counters after reading them (#316)
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 committed Apr 15, 2024
1 parent 0b0d95a commit 3e78d9c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/ebpf/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (m *FlowFetcher) ReadGlobalCounter(met *metrics.Metrics) {
"FlowFilterAcceptCounter",
"FlowFilterNoMatchCounter",
}

zeroCounters := make([]uint32, ebpf.MustPossibleCPU())
for key := BpfGlobalCountersKeyTHASHMAP_FLOWS_DROPPED_KEY; key < BpfGlobalCountersKeyTMAX_DROPPED_FLOWS_KEY; key++ {
if err := m.objects.GlobalCounters.Lookup(key, &allCPUValue); err != nil {
log.WithError(err).Warnf("couldn't read global counter")
Expand All @@ -497,6 +497,11 @@ func (m *FlowFetcher) ReadGlobalCounter(met *metrics.Metrics) {
met.FilteredFlowsCounter.WithSourceAndReason("flow-fetcher", reasons[key]).Add(float64(counter))
}
}
// reset the global counter map entry
if err := m.objects.GlobalCounters.Put(key, zeroCounters); err != nil {
log.WithError(err).Warnf("coudn't reset global counter")
return
}
}
}

Expand Down

0 comments on commit 3e78d9c

Please sign in to comment.