Skip to content

Change 'too many labels' error message to play nicely with Prometheus logs #3718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
* [ENHANCEMENT] New /runtime_config endpoint that returns the defined runtime configuration in YAML format. The returned configuration includes overrides. #3639
* [ENHANCEMENT] Query-frontend: included the parameter name failed to validate in HTTP 400 message. #3703
* [ENHANCEMENT] Fail to startup Cortex if provided runtime config is invalid. #3707
* [ENHANCEMENT] Distributor: change the error message returned when a received series has too many label values. The new message format has the series at the end and this plays better with Prometheus logs truncation. #3718
- From: `sample for '<series>' has <value> label names; limit <value>`
- To: `series has too many labels (actual: <value>, limit: <value>) series: '<series>'`
* [BUGFIX] Allow `-querier.max-query-lookback` use `y|w|d` suffix like deprecated `-store.max-look-back-period`. #3598
* [BUGFIX] Memberlist: Entry in the ring should now not appear again after using "Forget" feature (unless it's still heartbeating). #3603
* [BUGFIX] Ingester: do not close idle TSDBs while blocks shipping is in progress. #3630
Expand Down
4 changes: 2 additions & 2 deletions pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ func TestDistributorValidation(t *testing.T) {
TimestampMs: int64(now),
Value: 2,
}},
err: httpgrpc.Errorf(http.StatusBadRequest, `sample for 'testmetric{foo2="bar2", foo="bar"}' has 3 label names; limit 2`),
err: httpgrpc.Errorf(http.StatusBadRequest, `series has too many labels (actual: 3, limit: 2) series: 'testmetric{foo2="bar2", foo="bar"}'`),
},
// Test multiple validation fails return the first one.
{
Expand All @@ -1614,7 +1614,7 @@ func TestDistributorValidation(t *testing.T) {
{TimestampMs: int64(now), Value: 2},
{TimestampMs: int64(past), Value: 2},
},
err: httpgrpc.Errorf(http.StatusBadRequest, `sample for 'testmetric{foo2="bar2", foo="bar"}' has 3 label names; limit 2`),
err: httpgrpc.Errorf(http.StatusBadRequest, `series has too many labels (actual: 3, limit: 2) series: 'testmetric{foo2="bar2", foo="bar"}'`),
},
// Test metadata validation fails
{
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/validation/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
errInvalidLabel = "sample invalid label: %.200q metric %.200q"
errLabelNameTooLong = "label name too long: %.200q metric %.200q"
errLabelValueTooLong = "label value too long: %.200q metric %.200q"
errTooManyLabels = "sample for '%s' has %d label names; limit %d"
errTooManyLabels = "series has too many labels (actual: %d, limit: %d) series: '%s'"
errTooOld = "sample for '%s' has timestamp too old: %d"
errTooNew = "sample for '%s' has timestamp too new: %d"
errDuplicateLabelName = "duplicate label name: %.200q metric %.200q"
Expand Down Expand Up @@ -132,7 +132,7 @@ func ValidateLabels(cfg LabelValidationConfig, userID string, ls []client.LabelA
numLabelNames := len(ls)
if numLabelNames > cfg.MaxLabelNamesPerSeries(userID) {
DiscardedSamples.WithLabelValues(maxLabelNamesPerSeries, userID).Inc()
return httpgrpc.Errorf(http.StatusBadRequest, errTooManyLabels, client.FromLabelAdaptersToMetric(ls).String(), numLabelNames, cfg.MaxLabelNamesPerSeries(userID))
return httpgrpc.Errorf(http.StatusBadRequest, errTooManyLabels, numLabelNames, cfg.MaxLabelNamesPerSeries(userID), client.FromLabelAdaptersToMetric(ls).String())
}

maxLabelNameLength := cfg.MaxLabelNameLength(userID)
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/validation/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestValidateLabels(t *testing.T) {
{
map[model.LabelName]model.LabelValue{model.MetricNameLabel: "foo", "bar": "baz", "blip": "blop"},
false,
httpgrpc.Errorf(http.StatusBadRequest, errTooManyLabels, `foo{bar="baz", blip="blop"}`, 3, 2),
httpgrpc.Errorf(http.StatusBadRequest, errTooManyLabels, 3, 2, `foo{bar="baz", blip="blop"}`),
},
{
map[model.LabelName]model.LabelValue{model.MetricNameLabel: "foo", "invalid%label&name": "bar"},
Expand Down