Add NewUntypedFunc to promauto

This constructor was simply forgotten.

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2020-02-13 22:08:18 +01:00
parent 92c1ac77e7
commit 1c2884b807
1 changed files with 19 additions and 0 deletions

View File

@ -234,6 +234,14 @@ func NewHistogramVec(opts prometheus.HistogramOpts, labelNames []string) *promet
return With(prometheus.DefaultRegisterer).NewHistogramVec(opts, labelNames) 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 // Factory provides factory methods to create Collectors that are automatically
// registered with a Registerer. Create a Factory with the With function, // registered with a Registerer. Create a Factory with the With function,
// providing a Registerer to auto-register created Collectors with. The zero // providing a Registerer to auto-register created Collectors with. The zero
@ -353,3 +361,14 @@ func (f Factory) NewHistogramVec(opts prometheus.HistogramOpts, labelNames []str
} }
return h 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
}