Skip to content

Commit

Permalink
Don't panic in loki journal source for re-registered prom metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dehaansa committed Nov 27, 2024
1 parent a319983 commit ef4f495
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit ef4f495

Please sign in to comment.