Skip to content

Commit

Permalink
Fix #237: Use Prometheus type Counter instead of Gauge for forward mo…
Browse files Browse the repository at this point in the history
…dule's packet and byte counters
  • Loading branch information
andreev-io committed Apr 8, 2024
1 parent ef779b6 commit 00487a0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/metrics/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ var (
// Common counters across os distributions
DropCounter IGaugeVec
DropBytesCounter IGaugeVec
ForwardCounter IGaugeVec
ForwardBytesCounter IGaugeVec
ForwardCounter ICounterVec
ForwardBytesCounter ICounterVec

WindowsCounter IGaugeVec

Expand Down
6 changes: 3 additions & 3 deletions pkg/module/metrics/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (

type ForwardMetrics struct {
baseMetricObject
forwardMetric metricsinit.IGaugeVec
forwardMetric metricsinit.ICounterVec
// bytesMetric metricsinit.IGaugeVec
metricName string
}
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/module/metrics/forward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 00487a0

Please sign in to comment.