From ae77d82d88424108650cfcfc99b9aa3e52a2cd1e Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 28 Feb 2017 11:13:17 -0400 Subject: [PATCH] Fix invalid Timer (gauge) example The example method is assumed to be used as main() function. As a main() function doesn't have any return values, the example doesn't compile and is invalid. --- prometheus/example_timer_gauge_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/prometheus/example_timer_gauge_test.go b/prometheus/example_timer_gauge_test.go index dd91066..7184a0d 100644 --- a/prometheus/example_timer_gauge_test.go +++ b/prometheus/example_timer_gauge_test.go @@ -13,7 +13,11 @@ package prometheus_test -import "github.com/prometheus/client_golang/prometheus" +import ( + "os" + + "github.com/prometheus/client_golang/prometheus" +) var ( // 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. timer := prometheus.NewTimer(prometheus.ObserverFunc(funcDuration.Set)) defer timer.ObserveDuration() @@ -36,3 +40,9 @@ func ExampleTimer_gauge() error { // makes sure the function is still timed properly. return nil } + +func ExampleTimer_gauge() { + if err := run(); err != nil { + os.Exit(1) + } +}