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

Function TestManagedRegistry_limited

modules/generator/registry/registry_test.go:243–281  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

241}
242
243func TestManagedRegistry_limited(t *testing.T) {
244 appender := &capturingAppender{}
245
246 overrides := &mockOverrides{}
247 atLimit := false
248 overflowLabels := labels.FromStrings("metric_overflow", "true")
249 overflowHash := overflowLabels.Hash()
250 limiter := &mockLimiter{
251 onAddFunc: func(hash uint64, _ uint32, lbls labels.Labels) (labels.Labels, uint64) {
252 if !atLimit {
253 return lbls, hash
254 }
255 return overflowLabels, overflowHash
256 },
257 }
258 registry := New(&Config{}, overrides, "test", appender, log.NewNopLogger(), limiter)
259 defer registry.Close()
260
261 counter1 := registry.NewCounter("metric_1")
262 counter2 := registry.NewCounter("metric_2")
263
264 counter1.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0)
265 atLimit = true
266 // these series should be mapped to overflow
267 counter1.Inc(buildTestLabels([]string{"label"}, []string{"value-2"}), 1.0)
268 counter2.Inc(labels.New(), 1.0)
269
270 // 1 accepted series + 2 overflow series (one per metric) = 3 total
271 assert.Equal(t, uint32(3), registry.activeSeries())
272 expectedSamples := []sample{
273 newSample(map[string]string{"__name__": "metric_1", "label": "value-1", "__metrics_gen_instance": mustGetHostname()}, 0, 0),
274 newSample(map[string]string{"__name__": "metric_1", "label": "value-1", "__metrics_gen_instance": mustGetHostname()}, 0, 1),
275 newSample(map[string]string{"__name__": "metric_1", "metric_overflow": "true", "__metrics_gen_instance": mustGetHostname()}, 0, 0),
276 newSample(map[string]string{"__name__": "metric_1", "metric_overflow": "true", "__metrics_gen_instance": mustGetHostname()}, 0, 1),
277 newSample(map[string]string{"__name__": "metric_2", "metric_overflow": "true", "__metrics_gen_instance": mustGetHostname()}, 0, 0),
278 newSample(map[string]string{"__name__": "metric_2", "metric_overflow": "true", "__metrics_gen_instance": mustGetHostname()}, 0, 1),
279 }
280 collectRegistryMetricsAndAssert(t, registry, appender, expectedSamples)
281}
282
283func TestManagedRegistry_maxEntities(t *testing.T) {
284 appender := &capturingAppender{}

Callers

nothing calls this directly

Calls 11

IncMethod · 0.95
buildTestLabelsFunction · 0.85
newSampleFunction · 0.85
mustGetHostnameFunction · 0.85
HashMethod · 0.80
activeSeriesMethod · 0.80
NewFunction · 0.70
CloseMethod · 0.65
NewCounterMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected