From 00487a0048b6c70ef3ec62f95336ec2a0c8e78d3 Mon Sep 17 00:00:00 2001 From: Ilya Andreev <18560147+andreev-io@users.noreply.github.com> Date: Mon, 8 Apr 2024 13:10:32 +0100 Subject: [PATCH] Fix #237: Use Prometheus type Counter instead of Gauge for forward module's packet and byte counters --- pkg/metrics/metrics.go | 4 ++-- pkg/metrics/types.go | 4 ++-- pkg/module/metrics/forward.go | 6 +++--- pkg/module/metrics/forward_test.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 44e19f8619..db2792cba4 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -30,12 +30,12 @@ func InitializeMetrics() { dropBytesTotalDescription, utils.Reason, utils.Direction) - ForwardCounter = exporter.CreatePrometheusGaugeVecForMetric( + ForwardCounter = exporter.CreatePrometheusCounterVecForMetric( exporter.DefaultRegistry, utils.ForwardCountTotalName, forwardCountTotalDescription, utils.Direction) - ForwardBytesCounter = exporter.CreatePrometheusGaugeVecForMetric( + ForwardBytesCounter = exporter.CreatePrometheusCounterVecForMetric( exporter.DefaultRegistry, utils.ForwardBytesTotalName, forwardBytesTotalDescription, diff --git a/pkg/metrics/types.go b/pkg/metrics/types.go index 5e4de07f92..8bac058843 100644 --- a/pkg/metrics/types.go +++ b/pkg/metrics/types.go @@ -53,8 +53,8 @@ var ( // Common counters across os distributions DropCounter IGaugeVec DropBytesCounter IGaugeVec - ForwardCounter IGaugeVec - ForwardBytesCounter IGaugeVec + ForwardCounter ICounterVec + ForwardBytesCounter ICounterVec WindowsCounter IGaugeVec diff --git a/pkg/module/metrics/forward.go b/pkg/module/metrics/forward.go index e16710172a..8995297b03 100644 --- a/pkg/module/metrics/forward.go +++ b/pkg/module/metrics/forward.go @@ -27,7 +27,7 @@ const ( type ForwardMetrics struct { baseMetricObject - forwardMetric metricsinit.IGaugeVec + forwardMetric metricsinit.ICounterVec // bytesMetric metricsinit.IGaugeVec metricName string } @@ -47,13 +47,13 @@ func NewForwardCountMetrics(ctxOptions *api.MetricsContextOptions, fl *log.ZapLo func (f *ForwardMetrics) Init(metricName string) { switch metricName { case utils.ForwardCountTotalName: - f.forwardMetric = exporter.CreatePrometheusGaugeVecForMetric( + f.forwardMetric = exporter.CreatePrometheusCounterVecForMetric( exporter.AdvancedRegistry, TotalCountName, TotalCountDesc, f.getLabels()...) case utils.ForwardBytesTotalName: - f.forwardMetric = exporter.CreatePrometheusGaugeVecForMetric( + f.forwardMetric = exporter.CreatePrometheusCounterVecForMetric( exporter.AdvancedRegistry, TotalBytesName, TotalBytesDesc, diff --git a/pkg/module/metrics/forward_test.go b/pkg/module/metrics/forward_test.go index e93e571cef..a5e0c6879f 100644 --- a/pkg/module/metrics/forward_test.go +++ b/pkg/module/metrics/forward_test.go @@ -290,7 +290,7 @@ func TestNewForward(t *testing.T) { assert.NotNil(t, f, "forward metrics should not be nil Test Name: %s", tc.name) } - forwardMock := metricsinit.NewMockIGaugeVec(ctrl) //nolint:typecheck + forwardMock := metricsinit.NewMockICounterVec(ctrl) //nolint:typecheck f.forwardMetric = forwardMock