From 48d3ae798bd09680713b606fab423f55d8fe6b40 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Mon, 3 Dec 2018 21:10:34 +0100 Subject: [PATCH] Return observed duration from Timer.ObserveDuration Signed-off-by: beorn7 --- prometheus/timer.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/prometheus/timer.go b/prometheus/timer.go index b8fc5f18c..8d5f10523 100644 --- a/prometheus/timer.go +++ b/prometheus/timer.go @@ -39,13 +39,16 @@ func NewTimer(o Observer) *Timer { // ObserveDuration records the duration passed since the Timer was created with // NewTimer. It calls the Observe method of the Observer provided during -// construction with the duration in seconds as an argument. ObserveDuration is -// usually called with a defer statement. +// construction with the duration in seconds as an argument. The observed +// duration is also returned. ObserveDuration is usually called with a defer +// statement. // // Note that this method is only guaranteed to never observe negative durations // if used with Go1.9+. -func (t *Timer) ObserveDuration() { +func (t *Timer) ObserveDuration() time.Duration { + d := time.Since(t.begin) if t.observer != nil { - t.observer.Observe(time.Since(t.begin).Seconds()) + t.observer.Observe(d.Seconds()) } + return d }