MCPcopy
hub / github.com/grafana/tempo / TestCounterDifferentLabels

Function TestCounterDifferentLabels

modules/generator/registry/counter_test.go:58–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestCounterDifferentLabels(t *testing.T) {
59 var seriesAdded int
60 lifecycler := &mockLimiter{
61 onAddFunc: func(hash uint64, _ uint32, lbls labels.Labels) (labels.Labels, uint64) {
62 seriesAdded++
63 return lbls, hash
64 },
65 }
66
67 c := newCounter("my_counter", lifecycler, map[string]string{}, 15*time.Minute)
68
69 c.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0)
70 c.Inc(buildTestLabels([]string{"another_label"}, []string{"another_value"}), 2.0)
71
72 assert.Equal(t, 2, seriesAdded)
73
74 collectionTimeMs := time.Now().UnixMilli()
75 endOfLastMinuteMs := getEndOfLastMinuteMs(collectionTimeMs)
76 expectedSamples := []sample{
77 newSample(map[string]string{"__name__": "my_counter", "label": "value-1"}, endOfLastMinuteMs, 0),
78 newSample(map[string]string{"__name__": "my_counter", "label": "value-1"}, collectionTimeMs, 1),
79 newSample(map[string]string{"__name__": "my_counter", "another_label": "another_value"}, endOfLastMinuteMs, 0),
80 newSample(map[string]string{"__name__": "my_counter", "another_label": "another_value"}, collectionTimeMs, 2),
81 }
82 collectMetricAndAssert(t, c, collectionTimeMs, 2, expectedSamples, nil)
83}
84
85func Test_counter_cantAdd(t *testing.T) {
86 canAdd := false

Callers

nothing calls this directly

Calls 8

newCounterFunction · 0.85
buildTestLabelsFunction · 0.85
getEndOfLastMinuteMsFunction · 0.85
newSampleFunction · 0.85
collectMetricAndAssertFunction · 0.85
IncMethod · 0.65
NowMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected