diff --git a/CHANGELOG.md b/CHANGELOG.md index facf8ed3ac3..8ec85a4aa9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ * [ENHANCEMENT] Cortex now built with Go 1.18. #4829 * [ENHANCEMENT] Ingester: Prevent ingesters to become unhealthy during wall replay. #4847 * [ENHANCEMENT] Compactor: Introduced visit marker file for blocks so blocks are under compaction will not be picked up by another compactor. #4805 +* [ENHANCEMENT] Distributor: Add label name to labelValueTooLongError. #4855 * [FEATURE] Compactor: Added `-compactor.block-files-concurrency` allowing to configure number of go routines for download/upload block files during compaction. #4784 * [FEATURE] Compactor: Added -compactor.blocks-fetch-concurrency` allowing to configure number of go routines for blocks during compaction. #4787 * [FEATURE] Compactor: Added configurations for Azure MSI in blocks-storage, ruler-storage and alertmanager-storage. #4818 diff --git a/pkg/util/validation/errors.go b/pkg/util/validation/errors.go index a00f078d56b..483bf6acc5e 100644 --- a/pkg/util/validation/errors.go +++ b/pkg/util/validation/errors.go @@ -51,17 +51,20 @@ func newLabelNameTooLongError(series []cortexpb.LabelAdapter, labelName string, // labelValueTooLongError is a customized ValidationError, in that the cause and the series are // formatted in different order in Error. type labelValueTooLongError struct { + labelName string labelValue string series []cortexpb.LabelAdapter limit int } func (e *labelValueTooLongError) Error() string { - return fmt.Sprintf("label value too long for metric (actual: %d, limit: %d) metric: %.200q label value: %.200q", len(e.labelValue), e.limit, formatLabelSet(e.series), e.labelValue) + return fmt.Sprintf("label value too long for metric (actual: %d, limit: %d) metric: %.200q label name: %.200q label value: %.200q", + len(e.labelValue), e.limit, formatLabelSet(e.series), e.labelName, e.labelValue) } -func newLabelValueTooLongError(series []cortexpb.LabelAdapter, labelValue string, limit int) ValidationError { +func newLabelValueTooLongError(series []cortexpb.LabelAdapter, labelName, labelValue string, limit int) ValidationError { return &labelValueTooLongError{ + labelName: labelName, labelValue: labelValue, series: series, limit: limit, diff --git a/pkg/util/validation/validate.go b/pkg/util/validation/validate.go index b8fb44ece19..9f4b5e306df 100644 --- a/pkg/util/validation/validate.go +++ b/pkg/util/validation/validate.go @@ -209,7 +209,7 @@ func ValidateLabels(cfg LabelValidationConfig, userID string, ls []cortexpb.Labe return newLabelNameTooLongError(ls, l.Name, maxLabelNameLength) } else if len(l.Value) > maxLabelValueLength { DiscardedSamples.WithLabelValues(labelValueTooLong, userID).Inc() - return newLabelValueTooLongError(ls, l.Value, maxLabelValueLength) + return newLabelValueTooLongError(ls, l.Name, l.Value, maxLabelValueLength) } else if cmp := strings.Compare(lastLabelName, l.Name); cmp >= 0 { if cmp == 0 { DiscardedSamples.WithLabelValues(duplicateLabelNames, userID).Inc() diff --git a/pkg/util/validation/validate_test.go b/pkg/util/validation/validate_test.go index 298b190a2d4..16532166067 100644 --- a/pkg/util/validation/validate_test.go +++ b/pkg/util/validation/validate_test.go @@ -109,7 +109,7 @@ func TestValidateLabels(t *testing.T) { newLabelValueTooLongError([]cortexpb.LabelAdapter{ {Name: model.MetricNameLabel, Value: "badLabelValue"}, {Name: "much_shorter_name", Value: "test_value_please_ignore_no_really_nothing_to_see_here"}, - }, "test_value_please_ignore_no_really_nothing_to_see_here", cfg.maxLabelValueLength), + }, "much_shorter_name", "test_value_please_ignore_no_really_nothing_to_see_here", cfg.maxLabelValueLength), }, { map[model.LabelName]model.LabelValue{model.MetricNameLabel: "foo", "bar": "baz", "blip": "blop"},