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

Function Test_gauge_cantAdd

modules/generator/registry/gauge_test.go:113–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

111}
112
113func Test_gauge_cantAdd(t *testing.T) {
114 canAdd := false
115 overflowLabels := labels.FromStrings("metric_overflow", "true")
116 overflowHash := overflowLabels.Hash()
117 lifecycler := &mockLimiter{
118 onAddFunc: func(_ uint64, count uint32, lbls labels.Labels) (labels.Labels, uint64) {
119 assert.Equal(t, uint32(1), count)
120 if canAdd {
121 return lbls, lbls.Hash()
122 }
123 return overflowLabels, overflowHash
124 },
125 }
126
127 c := newGauge("my_gauge", lifecycler, map[string]string{}, 15*time.Minute)
128
129 // allow adding new series
130 canAdd = true
131
132 c.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0)
133 c.Inc(buildTestLabels([]string{"label"}, []string{"value-2"}), 2.0)
134
135 collectionTimeMs := time.Now().UnixMilli()
136 expectedSamples := []sample{
137 newSample(map[string]string{"__name__": "my_gauge", "label": "value-1"}, collectionTimeMs, 1),
138 newSample(map[string]string{"__name__": "my_gauge", "label": "value-2"}, collectionTimeMs, 2),
139 }
140 collectMetricAndAssert(t, c, collectionTimeMs, 2, expectedSamples, nil)
141
142 // block new series - existing series can still be updated, new series map to overflow
143 canAdd = false
144
145 c.Inc(buildTestLabels([]string{"label"}, []string{"value-2"}), 2.0)
146 c.Inc(buildTestLabels([]string{"label"}, []string{"value-3"}), 3.0)
147
148 collectionTimeMs = time.Now().UnixMilli()
149 expectedSamples = []sample{
150 newSample(map[string]string{"__name__": "my_gauge", "label": "value-1"}, collectionTimeMs, 1),
151 newSample(map[string]string{"__name__": "my_gauge", "label": "value-2"}, collectionTimeMs, 4),
152 newSample(map[string]string{"__name__": "my_gauge", "metric_overflow": "true"}, collectionTimeMs, 3),
153 }
154 collectMetricAndAssert(t, c, collectionTimeMs, 3, expectedSamples, nil)
155}
156
157func Test_gauge_removeStaleSeries(t *testing.T) {
158 var removedSeries int

Callers

nothing calls this directly

Calls 8

newGaugeFunction · 0.85
buildTestLabelsFunction · 0.85
newSampleFunction · 0.85
collectMetricAndAssertFunction · 0.85
HashMethod · 0.80
IncMethod · 0.65
NowMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected