Skip to content

Add label name to labelValueTooLongError #4855

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
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pkg/util/validation/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/validation/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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 @@ -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"},
Expand Down