MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestValidateLabelOrder

Function TestValidateLabelOrder

pkg/util/validation/validate_test.go:338–364  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

336}
337
338func TestValidateLabelOrder(t *testing.T) {
339 cfg := new(Limits)
340 cfg.MaxLabelNameLength = 10
341 cfg.MaxLabelNamesPerSeries = 10
342 cfg.MaxLabelValueLength = 10
343 reg := prometheus.NewRegistry()
344 validateMetrics := NewValidateMetrics(reg)
345 userID := "testUser"
346
347 actual := ValidateLabels(validateMetrics, cfg, userID, []cortexpb.LabelAdapter{
348 {Name: model.MetricNameLabel, Value: "m"},
349 {Name: "b", Value: "b"},
350 {Name: "a", Value: "a"},
351 }, false, model.LegacyValidation)
352 expected := newLabelsNotSortedError([]cortexpb.LabelAdapter{
353 {Name: model.MetricNameLabel, Value: "m"},
354 {Name: "b", Value: "b"},
355 {Name: "a", Value: "a"},
356 }, "a")
357 assert.Equal(t, expected, actual)
358
359 require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
360 # HELP cortex_discarded_samples_total The total number of samples that were discarded.
361 # TYPE cortex_discarded_samples_total counter
362 cortex_discarded_samples_total{reason="labels_not_sorted",user="testUser"} 1
363 `), "cortex_discarded_samples_total"))
364}
365
366func TestValidateLabelDuplication(t *testing.T) {
367 cfg := new(Limits)

Callers

nothing calls this directly

Calls 4

NewValidateMetricsFunction · 0.85
ValidateLabelsFunction · 0.85
newLabelsNotSortedErrorFunction · 0.85
EqualMethod · 0.65

Tested by

no test coverage detected