Improve doc comment for NewGaugeFunc

- Simplify confusing wording about concurrency safety.
- Add link to example for info metric.

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2019-12-09 18:20:27 +01:00
parent 0da4c3a935
commit de74638693
1 changed files with 6 additions and 3 deletions

View File

@ -273,9 +273,12 @@ type GaugeFunc interface {
// NewGaugeFunc creates a new GaugeFunc based on the provided GaugeOpts. The // NewGaugeFunc creates a new GaugeFunc based on the provided GaugeOpts. The
// value reported is determined by calling the given function from within the // value reported is determined by calling the given function from within the
// Write method. Take into account that metric collection may happen // Write method. Take into account that metric collection may happen
// concurrently. If that results in concurrent calls to Write, like in the case // concurrently. Therefore, it must be safe to call the provided function
// where a GaugeFunc is directly registered with Prometheus, the provided // concurrently.
// function must be concurrency-safe. //
// NewGaugeFunc is a good way to create an “info” style metric with a constant
// value of 1. Example:
// https://github.com/prometheus/common/blob/8558a5b7db3c84fa38b4766966059a7bd5bfa2ee/version/info.go#L36-L56
func NewGaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc { func NewGaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc {
return newValueFunc(NewDesc( return newValueFunc(NewDesc(
BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),