MCPcopy
hub / github.com/bnb-chain/bsc / TestCollector

Function TestCollector

metrics/prometheus/collector_test.go:16–117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14}
15
16func TestCollector(t *testing.T) {
17 c := newCollector()
18
19 counter := metrics.NewCounter()
20 counter.Inc(12345)
21 c.addCounter("test/counter", counter)
22
23 counterfloat64 := metrics.NewCounterFloat64()
24 counterfloat64.Inc(54321.98)
25 c.addCounterFloat64("test/counter_float64", counterfloat64)
26
27 gauge := metrics.NewGauge()
28 gauge.Update(23456)
29 c.addGauge("test/gauge", gauge)
30
31 gaugeFloat64 := metrics.NewGaugeFloat64()
32 gaugeFloat64.Update(34567.89)
33 c.addGaugeFloat64("test/gauge_float64", gaugeFloat64)
34
35 histogram := metrics.NewHistogram(&metrics.NilSample{})
36 c.addHistogram("test/histogram", histogram)
37
38 meter := metrics.NewMeter()
39 defer meter.Stop()
40 meter.Mark(9999999)
41 c.addMeter("test/meter", meter)
42
43 timer := metrics.NewTimer()
44 defer timer.Stop()
45 timer.Update(20 * time.Millisecond)
46 timer.Update(21 * time.Millisecond)
47 timer.Update(22 * time.Millisecond)
48 timer.Update(120 * time.Millisecond)
49 timer.Update(23 * time.Millisecond)
50 timer.Update(24 * time.Millisecond)
51 c.addTimer("test/timer", timer)
52
53 resettingTimer := metrics.NewResettingTimer()
54 resettingTimer.Update(10 * time.Millisecond)
55 resettingTimer.Update(11 * time.Millisecond)
56 resettingTimer.Update(12 * time.Millisecond)
57 resettingTimer.Update(120 * time.Millisecond)
58 resettingTimer.Update(13 * time.Millisecond)
59 resettingTimer.Update(14 * time.Millisecond)
60 c.addResettingTimer("test/resetting_timer", resettingTimer.Snapshot())
61
62 emptyResettingTimer := metrics.NewResettingTimer().Snapshot()
63 c.addResettingTimer("test/empty_resetting_timer", emptyResettingTimer)
64
65 const expectedOutput = `# TYPE test_counter gauge
66test_counter 12345
67
68# TYPE test_counter_float64 gauge
69test_counter_float64 54321.98
70
71# TYPE test_gauge gauge
72test_gauge 23456
73

Callers

nothing calls this directly

Calls 15

IncMethod · 0.95
IncMethod · 0.95
UpdateMethod · 0.95
UpdateMethod · 0.95
StopMethod · 0.95
MarkMethod · 0.95
StopMethod · 0.95
UpdateMethod · 0.95
UpdateMethod · 0.95
SnapshotMethod · 0.95
NewCounterFunction · 0.92
NewCounterFloat64Function · 0.92

Tested by

no test coverage detected