MCPcopy
hub / github.com/prometheus/client_golang / TestTimerObserve

Function TestTimerObserve

prometheus/timer_test.go:25–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestTimerObserve(t *testing.T) {
26 var (
27 his = NewHistogram(HistogramOpts{Name: "test_histogram"})
28 sum = NewSummary(SummaryOpts{Name: "test_summary"})
29 gauge = NewGauge(GaugeOpts{Name: "test_gauge"})
30 )
31
32 func() {
33 hisTimer := NewTimer(his)
34 sumTimer := NewTimer(sum)
35 gaugeTimer := NewTimer(ObserverFunc(gauge.Set))
36 defer hisTimer.ObserveDuration()
37 defer sumTimer.ObserveDuration()
38 defer gaugeTimer.ObserveDuration()
39 }()
40
41 m := &dto.Metric{}
42 his.Write(m)
43 if want, got := uint64(1), m.GetHistogram().GetSampleCount(); want != got {
44 t.Errorf("want %d observations for histogram, got %d", want, got)
45 }
46 m.Reset()
47 sum.Write(m)
48 if want, got := uint64(1), m.GetSummary().GetSampleCount(); want != got {
49 t.Errorf("want %d observations for summary, got %d", want, got)
50 }
51 m.Reset()
52 gauge.Write(m)
53 if got := m.GetGauge().GetValue(); got <= 0 {
54 t.Errorf("want value > 0 for gauge, got %f", got)
55 }
56}
57
58func TestTimerObserveWithExemplar(t *testing.T) {
59 var (

Callers

nothing calls this directly

Calls 9

ObserveDurationMethod · 0.95
NewTimerFunction · 0.85
ObserverFuncFuncType · 0.85
NewHistogramFunction · 0.70
NewSummaryFunction · 0.70
NewGaugeFunction · 0.70
WriteMethod · 0.65
ResetMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected