Skip to content

Commit 2e79824

Browse files
committed
Add label name to labelValueTooLongError
Signed-off-by: Xiaochao Dong (@damnever) <[email protected]>
1 parent 5742f57 commit 2e79824

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* [ENHANCEMENT] Cortex now built with Go 1.18. #4829
4646
* [ENHANCEMENT] Ingester: Prevent ingesters to become unhealthy during wall replay. #4847
4747
* [ENHANCEMENT] Compactor: Introduced visit marker file for blocks so blocks are under compaction will not be picked up by another compactor. #4805
48+
* [ENHANCEMENT] Distributor: Add label name to labelValueTooLongError. #4855
4849
* [FEATURE] Compactor: Added `-compactor.block-files-concurrency` allowing to configure number of go routines for download/upload block files during compaction. #4784
4950
* [FEATURE] Compactor: Added -compactor.blocks-fetch-concurrency` allowing to configure number of go routines for blocks during compaction. #4787
5051
* [FEATURE] Compactor: Added configurations for Azure MSI in blocks-storage, ruler-storage and alertmanager-storage. #4818

pkg/util/validation/errors.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,20 @@ func newLabelNameTooLongError(series []cortexpb.LabelAdapter, labelName string,
5151
// labelValueTooLongError is a customized ValidationError, in that the cause and the series are
5252
// formatted in different order in Error.
5353
type labelValueTooLongError struct {
54+
labelName string
5455
labelValue string
5556
series []cortexpb.LabelAdapter
5657
limit int
5758
}
5859

5960
func (e *labelValueTooLongError) Error() string {
60-
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)
61+
return fmt.Sprintf("label value too long for metric (actual: %d, limit: %d) metric: %.200q label name: %.200q label value: %.200q",
62+
len(e.labelValue), e.limit, formatLabelSet(e.series), e.labelName, e.labelValue)
6163
}
6264

63-
func newLabelValueTooLongError(series []cortexpb.LabelAdapter, labelValue string, limit int) ValidationError {
65+
func newLabelValueTooLongError(series []cortexpb.LabelAdapter, labelName, labelValue string, limit int) ValidationError {
6466
return &labelValueTooLongError{
67+
labelName: labelName,
6568
labelValue: labelValue,
6669
series: series,
6770
limit: limit,

pkg/util/validation/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func ValidateLabels(cfg LabelValidationConfig, userID string, ls []cortexpb.Labe
209209
return newLabelNameTooLongError(ls, l.Name, maxLabelNameLength)
210210
} else if len(l.Value) > maxLabelValueLength {
211211
DiscardedSamples.WithLabelValues(labelValueTooLong, userID).Inc()
212-
return newLabelValueTooLongError(ls, l.Value, maxLabelValueLength)
212+
return newLabelValueTooLongError(ls, l.Name, l.Value, maxLabelValueLength)
213213
} else if cmp := strings.Compare(lastLabelName, l.Name); cmp >= 0 {
214214
if cmp == 0 {
215215
DiscardedSamples.WithLabelValues(duplicateLabelNames, userID).Inc()

pkg/util/validation/validate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestValidateLabels(t *testing.T) {
109109
newLabelValueTooLongError([]cortexpb.LabelAdapter{
110110
{Name: model.MetricNameLabel, Value: "badLabelValue"},
111111
{Name: "much_shorter_name", Value: "test_value_please_ignore_no_really_nothing_to_see_here"},
112-
}, "test_value_please_ignore_no_really_nothing_to_see_here", cfg.maxLabelValueLength),
112+
}, "much_shorter_name", "test_value_please_ignore_no_really_nothing_to_see_here", cfg.maxLabelValueLength),
113113
},
114114
{
115115
map[model.LabelName]model.LabelValue{model.MetricNameLabel: "foo", "bar": "baz", "blip": "blop"},

0 commit comments

Comments
 (0)