From 46c03b4e8dc580ea63496d62658fb02aa8a2dec2 Mon Sep 17 00:00:00 2001 From: shantanualshi Date: Mon, 18 Nov 2024 18:13:49 +0530 Subject: [PATCH] Fix test --- pkg/pattern/aggregation/metrics.go | 24 +++++++++++++++++++++++- pkg/pattern/aggregation/push_test.go | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/pattern/aggregation/metrics.go b/pkg/pattern/aggregation/metrics.go index 90fd8378c3baf..b90e2b5875f69 100644 --- a/pkg/pattern/aggregation/metrics.go +++ b/pkg/pattern/aggregation/metrics.go @@ -6,6 +6,8 @@ import ( ) type Metrics struct { + reg prometheus.Registerer + chunks *prometheus.GaugeVec samples *prometheus.CounterVec @@ -24,7 +26,10 @@ type Metrics struct { } func NewMetrics(r prometheus.Registerer, metricsNamespace string) *Metrics { - return &Metrics{ + var m Metrics + m.reg = r + + m = Metrics{ chunks: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{ Namespace: metricsNamespace, Subsystem: "pattern_ingester", @@ -96,4 +101,21 @@ func NewMetrics(r prometheus.Registerer, metricsNamespace string) *Metrics { Help: "Total number of write timeouts.", }, []string{"tenant_id"}), } + + if m.reg != nil { + m.reg.MustRegister( + m.chunks, + m.samples, + m.pushErrors, + m.pushRetries, + m.pushSuccesses, + m.payloadSize, + m.streamsPerPush, + m.entriesPerPush, + m.servicesTracked, + m.writeTimeout, + ) + } + + return &m } diff --git a/pkg/pattern/aggregation/push_test.go b/pkg/pattern/aggregation/push_test.go index cf45dbe0dabdd..4d60e83db6771 100644 --- a/pkg/pattern/aggregation/push_test.go +++ b/pkg/pattern/aggregation/push_test.go @@ -124,6 +124,7 @@ func Test_Push(t *testing.T) { quit: make(chan struct{}), backoff: &backoff, entries: entries{}, + metrics: NewMetrics(nil, ""), } lbls1 := labels.New(labels.Label{Name: "test", Value: "test"})