From ef4f495311db992b5755077ccc5cae197ebe128f Mon Sep 17 00:00:00 2001 From: Sam DeHaan Date: Wed, 27 Nov 2024 14:39:23 -0500 Subject: [PATCH] Don't panic in loki journal source for re-registered prom metrics --- .../loki/source/journal/internal/target/metrics.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/component/loki/source/journal/internal/target/metrics.go b/internal/component/loki/source/journal/internal/target/metrics.go index 27804ae6e2..d0c3ad876f 100644 --- a/internal/component/loki/source/journal/internal/target/metrics.go +++ b/internal/component/loki/source/journal/internal/target/metrics.go @@ -4,7 +4,10 @@ package target // configure and run the targets that can read journal entries and forward them // to other loki components. -import "github.com/prometheus/client_golang/prometheus" +import ( + "github.com/grafana/alloy/internal/util" + "github.com/prometheus/client_golang/prometheus" +) // Metrics holds a set of journal target metrics. type Metrics struct { @@ -30,10 +33,8 @@ func NewMetrics(reg prometheus.Registerer) *Metrics { }) if reg != nil { - reg.MustRegister( - m.journalErrors, - m.journalLines, - ) + m.journalErrors = util.MustRegisterOrGet(reg, m.journalErrors).(*prometheus.CounterVec) + m.journalLines = util.MustRegisterOrGet(reg, m.journalLines).(prometheus.Counter) } return &m