(t *testing.T)
| 364 | } |
| 365 | |
| 366 | func TestValidateLabelDuplication(t *testing.T) { |
| 367 | cfg := new(Limits) |
| 368 | cfg.MaxLabelNameLength = 10 |
| 369 | cfg.MaxLabelNamesPerSeries = 10 |
| 370 | cfg.MaxLabelValueLength = 10 |
| 371 | reg := prometheus.NewRegistry() |
| 372 | validateMetrics := NewValidateMetrics(reg) |
| 373 | userID := "testUser" |
| 374 | |
| 375 | actual := ValidateLabels(validateMetrics, cfg, userID, []cortexpb.LabelAdapter{ |
| 376 | {Name: model.MetricNameLabel, Value: "a"}, |
| 377 | {Name: model.MetricNameLabel, Value: "b"}, |
| 378 | }, false, model.LegacyValidation) |
| 379 | expected := newDuplicatedLabelError([]cortexpb.LabelAdapter{ |
| 380 | {Name: model.MetricNameLabel, Value: "a"}, |
| 381 | {Name: model.MetricNameLabel, Value: "b"}, |
| 382 | }, model.MetricNameLabel) |
| 383 | assert.Equal(t, expected, actual) |
| 384 | |
| 385 | actual = ValidateLabels(validateMetrics, cfg, userID, []cortexpb.LabelAdapter{ |
| 386 | {Name: model.MetricNameLabel, Value: "a"}, |
| 387 | {Name: "a", Value: "a"}, |
| 388 | {Name: "a", Value: "a"}, |
| 389 | }, false, model.LegacyValidation) |
| 390 | expected = newDuplicatedLabelError([]cortexpb.LabelAdapter{ |
| 391 | {Name: model.MetricNameLabel, Value: "a"}, |
| 392 | {Name: "a", Value: "a"}, |
| 393 | {Name: "a", Value: "a"}, |
| 394 | }, "a") |
| 395 | assert.Equal(t, expected, actual) |
| 396 | |
| 397 | require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(` |
| 398 | # HELP cortex_discarded_samples_total The total number of samples that were discarded. |
| 399 | # TYPE cortex_discarded_samples_total counter |
| 400 | cortex_discarded_samples_total{reason="duplicate_label_names",user="testUser"} 2 |
| 401 | `), "cortex_discarded_samples_total")) |
| 402 | } |
| 403 | |
| 404 | func TestValidateNativeHistogram(t *testing.T) { |
| 405 | userID := "fake" |
nothing calls this directly
no test coverage detected