Skip to content

Commit

Permalink
Add NewUntypedFunc to promauto
Browse files Browse the repository at this point in the history
This constructor was simply forgotten.

Signed-off-by: beorn7 <beorn@grafana.com>
  • Loading branch information
beorn7 committed Feb 13, 2020
1 parent 92c1ac7 commit 1c2884b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions prometheus/promauto/auto.go
Expand Up @@ -234,6 +234,14 @@ func NewHistogramVec(opts prometheus.HistogramOpts, labelNames []string) *promet
return With(prometheus.DefaultRegisterer).NewHistogramVec(opts, labelNames)
}

// NewUntypedFunc works like the function of the same name in the prometheus
// package but it automatically registers the UntypedFunc with the
// prometheus.DefaultRegisterer. If the registration fails, NewUntypedFunc
// panics.
func NewUntypedFunc(opts prometheus.UntypedOpts, function func() float64) prometheus.UntypedFunc {
return With(prometheus.DefaultRegisterer).NewUntypedFunc(opts, function)
}

// Factory provides factory methods to create Collectors that are automatically
// registered with a Registerer. Create a Factory with the With function,
// providing a Registerer to auto-register created Collectors with. The zero
Expand Down Expand Up @@ -353,3 +361,14 @@ func (f Factory) NewHistogramVec(opts prometheus.HistogramOpts, labelNames []str
}
return h
}

// NewUntypedFunc works like the function of the same name in the prometheus
// package but it automatically registers the UntypedFunc with the Factory's
// Registerer.
func (f Factory) NewUntypedFunc(opts prometheus.UntypedOpts, function func() float64) prometheus.UntypedFunc {
u := prometheus.NewUntypedFunc(opts, function)
if f.r != nil {
f.r.MustRegister(u)
}
return u
}

0 comments on commit 1c2884b

Please sign in to comment.