Skip to content

Commit 1c2884b

Browse files
committed
Add NewUntypedFunc to promauto
This constructor was simply forgotten. Signed-off-by: beorn7 <[email protected]>
1 parent 92c1ac7 commit 1c2884b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

prometheus/promauto/auto.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ func NewHistogramVec(opts prometheus.HistogramOpts, labelNames []string) *promet
234234
return With(prometheus.DefaultRegisterer).NewHistogramVec(opts, labelNames)
235235
}
236236

237+
// NewUntypedFunc works like the function of the same name in the prometheus
238+
// package but it automatically registers the UntypedFunc with the
239+
// prometheus.DefaultRegisterer. If the registration fails, NewUntypedFunc
240+
// panics.
241+
func NewUntypedFunc(opts prometheus.UntypedOpts, function func() float64) prometheus.UntypedFunc {
242+
return With(prometheus.DefaultRegisterer).NewUntypedFunc(opts, function)
243+
}
244+
237245
// Factory provides factory methods to create Collectors that are automatically
238246
// registered with a Registerer. Create a Factory with the With function,
239247
// providing a Registerer to auto-register created Collectors with. The zero
@@ -353,3 +361,14 @@ func (f Factory) NewHistogramVec(opts prometheus.HistogramOpts, labelNames []str
353361
}
354362
return h
355363
}
364+
365+
// NewUntypedFunc works like the function of the same name in the prometheus
366+
// package but it automatically registers the UntypedFunc with the Factory's
367+
// Registerer.
368+
func (f Factory) NewUntypedFunc(opts prometheus.UntypedOpts, function func() float64) prometheus.UntypedFunc {
369+
u := prometheus.NewUntypedFunc(opts, function)
370+
if f.r != nil {
371+
f.r.MustRegister(u)
372+
}
373+
return u
374+
}

0 commit comments

Comments
 (0)