Merge pull request #282 from prometheus/grobie/fix-vet-issues

Fix invalid Timer (gauge) example
This commit is contained in:
Björn Rabenstein 2017-02-28 17:20:01 +01:00 committed by GitHub
commit aace68cde2
1 changed files with 12 additions and 2 deletions

View File

@ -13,7 +13,11 @@
package prometheus_test package prometheus_test
import "github.com/prometheus/client_golang/prometheus" import (
"os"
"github.com/prometheus/client_golang/prometheus"
)
var ( var (
// If a function is called rarely (i.e. not more often than scrapes // If a function is called rarely (i.e. not more often than scrapes
@ -27,7 +31,7 @@ var (
}) })
) )
func ExampleTimer_gauge() error { func run() error {
// The Set method of the Gauge is used to observe the duration. // The Set method of the Gauge is used to observe the duration.
timer := prometheus.NewTimer(prometheus.ObserverFunc(funcDuration.Set)) timer := prometheus.NewTimer(prometheus.ObserverFunc(funcDuration.Set))
defer timer.ObserveDuration() defer timer.ObserveDuration()
@ -36,3 +40,9 @@ func ExampleTimer_gauge() error {
// makes sure the function is still timed properly. // makes sure the function is still timed properly.
return nil return nil
} }
func ExampleTimer_gauge() {
if err := run(); err != nil {
os.Exit(1)
}
}