Skip to content

Commit

Permalink
Improve doc comment for NewGaugeFunc
Browse files Browse the repository at this point in the history
- Simplify confusing wording about concurrency safety.
- Add link to example for info metric.

Signed-off-by: beorn7 <[email protected]>
  • Loading branch information
beorn7 committed Dec 9, 2019
1 parent 0da4c3a commit de74638
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions prometheus/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,12 @@ type GaugeFunc interface {
// NewGaugeFunc creates a new GaugeFunc based on the provided GaugeOpts. The
// value reported is determined by calling the given function from within the
// Write method. Take into account that metric collection may happen
// concurrently. If that results in concurrent calls to Write, like in the case
// where a GaugeFunc is directly registered with Prometheus, the provided
// function must be concurrency-safe.
// concurrently. Therefore, it must be safe to call the provided function
// concurrently.
//
// 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 {
return newValueFunc(NewDesc(
BuildFQName(opts.Namespace, opts.Subsystem, opts.Name),
Expand Down

0 comments on commit de74638

Please sign in to comment.