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

Function Test_gauge_demandVsActiveSeries

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

Source from the content-addressed store, hash-verified

315}
316
317func Test_gauge_demandVsActiveSeries(t *testing.T) {
318 limitReached := false
319 overflowLabels := labels.FromStrings("metric_overflow", "true")
320 overflowHash := overflowLabels.Hash()
321
322 lifecycler := &mockLimiter{
323 onAddFunc: func(hash uint64, _ uint32, lbls labels.Labels) (labels.Labels, uint64) {
324 if !limitReached {
325 return lbls, hash
326 }
327 return overflowLabels, overflowHash
328 },
329 }
330 g := newGauge("my_gauge", lifecycler, map[string]string{}, 15*time.Minute)
331
332 // Add series up to a point
333 for i := 0; i < 30; i++ {
334 lbls := buildTestLabels([]string{"label"}, []string{fmt.Sprintf("value-%d", i)})
335 g.Set(lbls, float64(i))
336 }
337
338 assert.Equal(t, 30, g.countActiveSeries())
339
340 // Hit the limit
341 limitReached = true
342
343 // Try to add more series (they should be mapped to overflow)
344 for i := 30; i < 60; i++ {
345 lbls := buildTestLabels([]string{"label"}, []string{fmt.Sprintf("value-%d", i)})
346 g.Set(lbls, float64(i))
347 }
348
349 // Active series should be 30 accepted + 1 overflow = 31 total
350 assert.Equal(t, 31, g.countActiveSeries())
351
352 // But demand should show all attempted series
353 demand := g.countSeriesDemand()
354 assert.Greater(t, demand, 50, "demand should track all attempted series")
355 assert.Greater(t, demand, g.countActiveSeries(), "demand should exceed active series")
356}
357
358func Test_gauge_demandDecay(t *testing.T) {
359 lifecycler := &mockLimiter{}

Callers

nothing calls this directly

Calls 7

newGaugeFunction · 0.85
buildTestLabelsFunction · 0.85
HashMethod · 0.80
SetMethod · 0.65
countActiveSeriesMethod · 0.65
countSeriesDemandMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected