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

Function Test_gauge_onUpdate

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

Source from the content-addressed store, hash-verified

379}
380
381func Test_gauge_onUpdate(t *testing.T) {
382 var seriesUpdated int
383 lifecycler := &mockLimiter{
384 onAddFunc: func(hash uint64, _ uint32, lbls labels.Labels) (labels.Labels, uint64) {
385 return lbls, hash
386 },
387 onUpdateFunc: func(_ uint64, count uint32) {
388 assert.Equal(t, uint32(1), count)
389 seriesUpdated++
390 },
391 }
392
393 g := newGauge("my_gauge", lifecycler, map[string]string{}, 15*time.Minute)
394
395 // Add initial series
396 g.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0)
397 g.Set(buildTestLabels([]string{"label"}, []string{"value-2"}), 5.0)
398
399 // No updates yet (new series don't trigger OnUpdate)
400 assert.Equal(t, 0, seriesUpdated)
401
402 // Update existing series with Inc
403 g.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 2.0)
404 assert.Equal(t, 1, seriesUpdated)
405
406 // Update existing series with Set
407 g.Set(buildTestLabels([]string{"label"}, []string{"value-2"}), 10.0)
408 assert.Equal(t, 2, seriesUpdated)
409
410 // Update both series
411 g.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0)
412 g.Set(buildTestLabels([]string{"label"}, []string{"value-2"}), 15.0)
413 assert.Equal(t, 4, seriesUpdated)
414}

Callers

nothing calls this directly

Calls 5

newGaugeFunction · 0.85
buildTestLabelsFunction · 0.85
IncMethod · 0.65
SetMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected