-
Notifications
You must be signed in to change notification settings - Fork 7
Add global label length limits #84
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,9 @@ var ( | |
| ExtraScrapeMetrics: boolPtr(false), | ||
| MetricNameValidationScheme: model.UTF8Validation, | ||
| MetricNameEscapingScheme: model.AllowUTF8, | ||
| // Default to 1 MiB to avoid crashes from the 16 MiB encoding limit. | ||
| LabelNameLengthLimit: 1 << 20, | ||
| LabelValueLengthLimit: 1 << 21, | ||
| } | ||
|
|
||
| DefaultRuntimeConfig = RuntimeConfig{ | ||
|
|
@@ -698,6 +701,9 @@ func (c *GlobalConfig) UnmarshalYAML(unmarshal func(any) error) error { | |
| return fmt.Errorf("%w for global config", err) | ||
| } | ||
| } | ||
| if gc.LabelNameLengthLimit == 0 { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LabelValueLengthLimit also isn't set in the default perhaps we should be adding this default there aswell. |
||
| gc.LabelNameLengthLimit = DefaultGlobalConfig.LabelNameLengthLimit | ||
| } | ||
|
|
||
| *c = *gc | ||
| return nil | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2000,6 +2000,9 @@ func (ev *evaluator) evalLabelReplace(ctx context.Context, args parser.Expressio | |
| indexes := regex.FindStringSubmatchIndex(srcVal) | ||
| if indexes != nil { // Only replace when regexp matches. | ||
| res := regex.ExpandString([]byte{}, repl, srcVal, indexes) | ||
| if len(res) > 1<<24 { | ||
| ev.errorf("label_replace: replacement value too long (%d bytes)", len(res)) | ||
| } | ||
| lb.Reset(el.Metric) | ||
| lb.Set(dst, string(res)) | ||
| matrix[i].Metric = lb.Labels() | ||
|
|
@@ -2051,6 +2054,9 @@ func (ev *evaluator) evalLabelJoin(ctx context.Context, args parser.Expressions) | |
| srcVals[i] = el.Metric.Get(src) | ||
| } | ||
| strval := strings.Join(srcVals, sep) | ||
| if len(strval) > 1<<24 { | ||
| ev.errorf("label_join: joined value too long (%d bytes)", len(strval)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps mentioning that the combined value now exceeds the sane limit and state that limit? |
||
| } | ||
| lb.Reset(el.Metric) | ||
| lb.Set(dst, strval) | ||
| matrix[i].Metric = lb.Labels() | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1713,6 +1713,12 @@ loop: | |||||
| lset = ce.lset | ||||||
| hash = ce.hash | ||||||
| } else { | ||||||
| // The label encoding format cannot represent strings longer than | ||||||
| // 2^24-1 bytes. Reject before constructing Labels to avoid a panic. | ||||||
| if len(met) > 1<<24 { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't do 1^24-1 bytes. It does 1<<24+1.
Suggested change
|
||||||
| err = fmt.Errorf("metric string too long to encode (%d bytes)", len(met)) | ||||||
| break loop | ||||||
| } | ||||||
| p.Labels(&lset) | ||||||
| hash = lset.Hash() | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seemingly this is set to 2MiB is this not supposed to be 1MiB?