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

Function Test_counter_removeStaleSeries

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

Source from the content-addressed store, hash-verified

132}
133
134func Test_counter_removeStaleSeries(t *testing.T) {
135 var removedSeries int
136 lifecycler := &mockLimiter{
137 onDeleteFunc: func(_ uint64, count uint32) {
138 assert.Equal(t, uint32(1), count)
139 removedSeries++
140 },
141 }
142
143 c := newCounter("my_counter", lifecycler, map[string]string{}, 15*time.Minute)
144
145 timeMs := time.Now().UnixMilli()
146 c.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0)
147 c.Inc(buildTestLabels([]string{"label"}, []string{"value-2"}), 2.0)
148
149 c.removeStaleSeries(timeMs)
150
151 assert.Equal(t, 0, removedSeries)
152
153 collectionTimeMs := time.Now().UnixMilli()
154 endOfLastMinuteMs := getEndOfLastMinuteMs(collectionTimeMs)
155 expectedSamples := []sample{
156 newSample(map[string]string{"__name__": "my_counter", "label": "value-1"}, endOfLastMinuteMs, 0),
157 newSample(map[string]string{"__name__": "my_counter", "label": "value-1"}, collectionTimeMs, 1),
158 newSample(map[string]string{"__name__": "my_counter", "label": "value-2"}, endOfLastMinuteMs, 0),
159 newSample(map[string]string{"__name__": "my_counter", "label": "value-2"}, collectionTimeMs, 2),
160 }
161 collectMetricAndAssert(t, c, collectionTimeMs, 2, expectedSamples, nil)
162
163 time.Sleep(10 * time.Millisecond)
164 timeMs = time.Now().UnixMilli()
165
166 // update value-2 series
167 c.Inc(buildTestLabels([]string{"label"}, []string{"value-2"}), 2.0)
168
169 c.removeStaleSeries(timeMs)
170
171 assert.Equal(t, 1, removedSeries)
172
173 collectionTimeMs = time.Now().UnixMilli()
174 expectedSamples = []sample{
175 newSample(map[string]string{"__name__": "my_counter", "label": "value-2"}, collectionTimeMs, 4),
176 }
177 collectMetricAndAssert(t, c, collectionTimeMs, 1, expectedSamples, nil)
178}
179
180func Test_counter_externalLabels(t *testing.T) {
181 c := newCounter("my_counter", noopLimiter, map[string]string{"external_label": "external_value"}, 15*time.Minute)

Callers

nothing calls this directly

Calls 10

newCounterFunction · 0.85
buildTestLabelsFunction · 0.85
getEndOfLastMinuteMsFunction · 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