From a940e30be3eb9f53bfedc5b07fe023ef37bfc85a Mon Sep 17 00:00:00 2001 From: Mauro Stettler Date: Mon, 4 Nov 2024 17:46:10 +0100 Subject: [PATCH] fix marshaling error on invalid label value (#9828) * fix marshaling error on invalid label value Signed-off-by: Mauro Stettler * only return label and metric Signed-off-by: Mauro Stettler * changelog Signed-off-by: Mauro Stettler --------- Signed-off-by: Mauro Stettler --- CHANGELOG.md | 1 + pkg/distributor/validate.go | 4 ++-- pkg/distributor/validate_test.go | 8 +------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b14173e455..4b2c550ee1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ * `-memberlist.acquire-writer-timeout` * [ENHANCEMENT] memberlist: Notifications can now be processed once per interval specified by `-memberlist.notify-interval` to reduce notify storm CPU activity in large clusters. #9594 * [ENHANCEMENT] Return server-side total bytes processed statistics as a header through query frontend. #9645 +* [ENHANCEMENT] Distributor: when a label value fails validation due to invalid UTF-8 characters, don't include the invalid characters in the returned error. #9828 * [BUGFIX] Fix issue where functions such as `rate()` over native histograms could return incorrect values if a float stale marker was present in the selected range. #9508 * [BUGFIX] Fix issue where negation of native histograms (eg. `-some_native_histogram_series`) did nothing. #9508 * [BUGFIX] Fix issue where `metric might not be a counter, name does not end in _total/_sum/_count/_bucket` annotation would be emitted even if `rate` or `increase` did not have enough samples to compute a result. #9508 diff --git a/pkg/distributor/validate.go b/pkg/distributor/validate.go index 21ce5adc2c4..c3c9b2d1a6b 100644 --- a/pkg/distributor/validate.go +++ b/pkg/distributor/validate.go @@ -72,7 +72,7 @@ var ( validation.MaxLabelValueLengthFlag, ) invalidLabelMsgFormat = globalerror.SeriesInvalidLabel.Message("received a series with an invalid label: '%.200s' series: '%.200s'") - invalidLabelValueMsgFormat = globalerror.SeriesInvalidLabelValue.Message("received a series with invalid value in label '%.200s': '%.200s' series: '%.200s'") + invalidLabelValueMsgFormat = globalerror.SeriesInvalidLabelValue.Message("received a series with invalid value in label '%.200s': '%.200s' metric: '%.200s'") duplicateLabelMsgFormat = globalerror.SeriesWithDuplicateLabelNames.Message("received a series with duplicate label name, label: '%.200s' series: '%.200s'") tooManyLabelsMsgFormat = globalerror.MaxLabelNamesPerSeries.MessageWithPerTenantLimitConfig( "received a series whose number of labels exceeds the limit (actual: %d, limit: %d) series: '%.200s%s'", @@ -404,7 +404,7 @@ func validateLabels(m *sampleValidationMetrics, cfg labelValidationConfig, userI return fmt.Errorf(labelNameTooLongMsgFormat, l.Name, mimirpb.FromLabelAdaptersToString(ls)) } else if !skipLabelValidation && !model.LabelValue(l.Value).IsValid() { m.invalidLabelValue.WithLabelValues(userID, group).Inc() - return fmt.Errorf(invalidLabelValueMsgFormat, l.Name, l.Value, mimirpb.FromLabelAdaptersToString(ls)) + return fmt.Errorf(invalidLabelValueMsgFormat, l.Name, strings.ToValidUTF8(l.Value, ""), unsafeMetricName) } else if len(l.Value) > maxLabelValueLength { m.labelValueTooLong.WithLabelValues(userID, group).Inc() return fmt.Errorf(labelValueTooLongMsgFormat, l.Name, l.Value, mimirpb.FromLabelAdaptersToString(ls)) diff --git a/pkg/distributor/validate_test.go b/pkg/distributor/validate_test.go index ffb91b9d626..77c674ac9b4 100644 --- a/pkg/distributor/validate_test.go +++ b/pkg/distributor/validate_test.go @@ -181,13 +181,7 @@ func TestValidateLabels(t *testing.T) { skipLabelCountValidation: false, err: fmt.Errorf( invalidLabelValueMsgFormat, - "label1", "abc\xfe\xfddef", - mimirpb.FromLabelAdaptersToString( - []mimirpb.LabelAdapter{ - {Name: model.MetricNameLabel, Value: "foo"}, - {Name: "label1", Value: "abc\xfe\xfddef"}, - }, - ), + "label1", "abcdef", "foo", ), }, {