label/metric name validation: use prometheus legacy validation scheme, avoid global variable#11629
label/metric name validation: use prometheus legacy validation scheme, avoid global variable#11629
Conversation
303af79 to
b62fd81
Compare
|
aknuds1
left a comment
There was a problem hiding this comment.
Looks like a promising start, although I only had the time for a quick review. Please follow the Mimir project standard of testify assertions in tests though.
Also, we probably want a faillint rule to make sure that your validation functions are used instead of the Prometheus library equivalents.
d668023 to
251c8d6
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR replaces Prometheus’s global NameValidationScheme overrides by introducing explicit validation wrappers for legacy and UTF-8 schemes, then updates callers to use the new wrappers.
- Add
IsValidLabelName,IsValidMetricName, andIsValidUTF8LabelNameinpkg/util/validation - Replace direct uses of
model.LabelName.IsValidandmodel.IsValidMetricNamewith the new wrappers - Remove all
initblocks that setmodel.NameValidationScheme = model.LegacyValidation
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/util/validation/labels.go | New wrappers for legacy and UTF-8 label/metric validation |
| pkg/util/validation/labels_test.go | Tests for the new validation functions |
| pkg/streamingpromql/operators/functions/label.go | Updated label_join and label_replace to use validation APIs |
| pkg/streamingpromql/operators/aggregations/count_values.go | Switched aggregation label checks to validation APIs |
| pkg/querier/stats_renderer_test.go | Removed legacy validation override in tests |
| pkg/mimir/promexts.go | Removed legacy validation override |
| pkg/frontend/querymiddleware/request_validation.go | Removed legacy validation override |
| pkg/distributor/validate.go | Replaced model validation with wrappers for labels and metrics |
| pkg/distributor/distributor.go | Removed legacy validation override |
| pkg/cardinality/request.go | Updated label_names extraction to use validation wrapper |
Comments suppressed due to low confidence (2)
pkg/streamingpromql/operators/functions/label.go:32
- The error for an invalid source label prints
dstinstead of thesrcvalue. Update the format argument to usesrc.
return nil, fmt.Errorf("invalid source label name in label_join(): %s", dst)
pkg/util/validation/labels_test.go:38
- TestIsValidLabelName is missing a case for names starting with a digit (e.g., "123label"), which should be invalid under the legacy scheme. Consider adding it.
for _, tc := range testCases {
There was a problem hiding this comment.
I don't understand the use of IsValidUTF8LabelName in some code paths here. Could you explain the reason?
Also, could you please add a faillint rule (in Makefile) to ensure we always use validation.IsValidLabelName and validation.IsValidMetricName?
The mimir/pkg/streamingpromql/testdata/ours/functions.test Lines 293 to 303 in 8ae678c |
That must mean that I guess it's not important though, as what matters is we don't ingest anything but "legacy" metric and label names. |
|
@charleskorn Can you shed some light on why |
Can you provide a list of Prometheus internal functions using the |
We cannot add
Yes, during unit tests. When running mimir, this behavior is overridden by
Sure, this is a list of all the references I found that are also used by mimir: Call hierarchy with depth=2
|
I wonder whether this rule can be implemented in golangci-lint instead. I think one of the included linters has the same type of functionality as faillint. |
I think this is true by accident - I would expect
Very possibly - try switching to the classic scheme and see what tests in the
I think we should change the affected tests to work with either the classic or UTF-8 scheme, and then use |
251c8d6 to
d330f06
Compare
|
Thanks for the feedback @charleskorn, @aknuds1. Force pushed a couple of changes:
|
| promqlext.ExtendPromQL() | ||
| // Mimir doesn't support Prometheus' UTF-8 metric/label name scheme yet. | ||
| // nolint:staticcheck | ||
| model.NameValidationScheme = model.LegacyValidation |
There was a problem hiding this comment.
I think we need to retain this for Prometheus code that relies on the global variable (eg. Prometheus' query engine).
495dfad to
b8a3aeb
Compare
b8a3aeb to
d10316a
Compare
|
Duplicate of: #11848 |
What this PR does
Mimir does not support prometheus
UTF8Validationname validation scheme. Validation helpersin prometheus
common/modelpackage rely on a global variableNameValidationSchemewhichdefaults to
UTF8Validation.This PR replaces direct calls to prometheus
LabelName.IsValidandIsValidMetricNamewitha validation wrapper that always uses
LegacyValidationscheme and does not rely on the globalvariable.
Where I need feedback:
Many of prometheus internal functions still rely on the
NameValidationSchemevariable. Mimiruses those functions in
distributor,mimirtool,querierandruler. Hence, I'm not sure ifremoving global overrides (see below) introduces side effects.
Which issue(s) this PR fixes or relates to
Fixes #11503
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX].about-versioning.mdupdated with experimental features.