Skip to content

Commit

Permalink
fix marshaling error on invalid label value (#9828) (#9830)
Browse files Browse the repository at this point in the history
* fix marshaling error on invalid label value

Signed-off-by: Mauro Stettler <[email protected]>

* only return label and metric

Signed-off-by: Mauro Stettler <[email protected]>

* changelog

Signed-off-by: Mauro Stettler <[email protected]>

---------

Signed-off-by: Mauro Stettler <[email protected]>
(cherry picked from commit c7ce088)

Co-authored-by: Mauro Stettler <[email protected]>
  • Loading branch information
grafanabot and replay authored Nov 4, 2024
1 parent ebd284e commit c72946f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* [ENHANCEMENT] Storage: Allow HTTP client settings to be tuned for GCS and Azure backends via an `http` block or corresponding CLI flags. This was already supported by the S3 backend. #9778
* [ENHANCEMENT] Ruler: Support `group_limit` and `group_next_token` parameters in the `<prometheus-http-prefix>/api/v1/rules` endpoint. #9563
* [ENHANCEMENT] Ingester: improved lock contention affecting read and write latencies during TSDB head compaction. #9822
* [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
Expand Down
4 changes: 2 additions & 2 deletions pkg/distributor/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 1 addition & 7 deletions pkg/distributor/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
},
{
Expand Down

0 comments on commit c72946f

Please sign in to comment.