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

Function Test_gauge_demandDecay

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

Source from the content-addressed store, hash-verified

356}
357
358func Test_gauge_demandDecay(t *testing.T) {
359 lifecycler := &mockLimiter{}
360 g := newGauge("my_gauge", lifecycler, map[string]string{}, 15*time.Minute)
361
362 // Add series
363 for i := 0; i < 40; i++ {
364 lbls := buildTestLabels([]string{"label"}, []string{fmt.Sprintf("value-%d", i)})
365 g.Inc(lbls, 1.0)
366 }
367
368 initialDemand := g.countSeriesDemand()
369 assert.Greater(t, initialDemand, 0)
370
371 // Advance the cardinality tracker enough times to clear the window
372 for i := 0; i < 5; i++ {
373 g.removeStaleSeries(time.Now().Add(time.Hour).UnixMilli())
374 }
375
376 // Demand should have decreased or be zero
377 finalDemand := g.countSeriesDemand()
378 assert.LessOrEqual(t, finalDemand, initialDemand/2, "demand should significantly decay")
379}
380
381func Test_gauge_onUpdate(t *testing.T) {
382 var seriesUpdated int

Callers

nothing calls this directly

Calls 7

newGaugeFunction · 0.85
buildTestLabelsFunction · 0.85
IncMethod · 0.65
countSeriesDemandMethod · 0.65
removeStaleSeriesMethod · 0.65
AddMethod · 0.65
NowMethod · 0.65

Tested by

no test coverage detected