Skip to content

Commit

Permalink
Issue go-kit#937 : Using prometheus collector MustRegister in New{Cou…
Browse files Browse the repository at this point in the history
…nter,Gauge} and possible panic
  • Loading branch information
prasadghagare committed Jun 16, 2020
1 parent ef2f77e commit 577ddf0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions metrics/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type Counter struct {
// and returns a usable Counter object.
func NewCounterFrom(opts prometheus.CounterOpts, labelNames []string) *Counter {
cv := prometheus.NewCounterVec(opts, labelNames)
prometheus.MustRegister(cv)
return NewCounter(cv)
return NewCounter(prometheus.DefaultRegisterer, cv)
}

// NewCounter wraps the CounterVec and returns a usable Counter object.
func NewCounter(cv *prometheus.CounterVec) *Counter {
func NewCounter(registerer prometheus.Registerer, cv *prometheus.CounterVec) *Counter {
registerer.Register(cv)
return &Counter{
cv: cv,
}
Expand Down Expand Up @@ -55,12 +55,12 @@ type Gauge struct {
// and returns a usable Gauge object.
func NewGaugeFrom(opts prometheus.GaugeOpts, labelNames []string) *Gauge {
gv := prometheus.NewGaugeVec(opts, labelNames)
prometheus.MustRegister(gv)
return NewGauge(gv)
return NewGauge(prometheus.DefaultRegisterer, gv)
}

// NewGauge wraps the GaugeVec and returns a usable Gauge object.
func NewGauge(gv *prometheus.GaugeVec) *Gauge {
func NewGauge(registerer prometheus.Registerer, gv *prometheus.GaugeVec) *Gauge {
registerer.Register(gv)
return &Gauge{
gv: gv,
}
Expand Down

0 comments on commit 577ddf0

Please sign in to comment.