From 7731f8d9c64d4e43ee6ea3c3985cd7c5d47c5d68 Mon Sep 17 00:00:00 2001 From: Mohamed Mahmoud Date: Mon, 15 Apr 2024 11:32:44 -0400 Subject: [PATCH] reset ebpf global counters after reading them Signed-off-by: Mohamed Mahmoud --- pkg/ebpf/tracer.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/ebpf/tracer.go b/pkg/ebpf/tracer.go index f21d144f4..4a15b7771 100644 --- a/pkg/ebpf/tracer.go +++ b/pkg/ebpf/tracer.go @@ -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") @@ -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 + } } }