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

Function Test_gauge_removeStaleSeries

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

Source from the content-addressed store, hash-verified

155}
156
157func Test_gauge_removeStaleSeries(t *testing.T) {
158 var removedSeries int
159 lifecycler := &mockLimiter{
160 onDeleteFunc: func(_ uint64, count uint32) {
161 assert.Equal(t, uint32(1), count)
162 removedSeries++
163 },
164 }
165
166 c := newGauge("my_gauge", lifecycler, map[string]string{}, 15*time.Minute)
167
168 timeMs := time.Now().UnixMilli()
169 c.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0)
170 c.Inc(buildTestLabels([]string{"label"}, []string{"value-2"}), 2.0)
171
172 c.removeStaleSeries(timeMs)
173
174 assert.Equal(t, 0, removedSeries)
175
176 collectionTimeMs := time.Now().UnixMilli()
177 expectedSamples := []sample{
178 newSample(map[string]string{"__name__": "my_gauge", "label": "value-1"}, collectionTimeMs, 1),
179 newSample(map[string]string{"__name__": "my_gauge", "label": "value-2"}, collectionTimeMs, 2),
180 }
181 collectMetricAndAssert(t, c, collectionTimeMs, 2, expectedSamples, nil)
182
183 time.Sleep(10 * time.Millisecond)
184 timeMs = time.Now().UnixMilli()
185
186 // update value-2 series
187 c.Inc(buildTestLabels([]string{"label"}, []string{"value-2"}), 2.0)
188
189 c.removeStaleSeries(timeMs)
190
191 assert.Equal(t, 1, removedSeries)
192
193 collectionTimeMs = time.Now().UnixMilli()
194 expectedSamples = []sample{
195 newSample(map[string]string{"__name__": "my_gauge", "label": "value-2"}, collectionTimeMs, 4),
196 }
197 collectMetricAndAssert(t, c, collectionTimeMs, 1, expectedSamples, nil)
198}
199
200func Test_gauge_externalLabels(t *testing.T) {
201 c := newGauge("my_gauge", noopLimiter, map[string]string{"external_label": "external_value"}, 15*time.Minute)

Callers

nothing calls this directly

Calls 9

newGaugeFunction · 0.85
buildTestLabelsFunction · 0.85
newSampleFunction · 0.85
collectMetricAndAssertFunction · 0.85
NowMethod · 0.65
IncMethod · 0.65
removeStaleSeriesMethod · 0.65
SleepMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected