Skip to content

Commit b0d896b

Browse files
authored
Replace deprecated model.NameValidationScheme with explicit UTF8Validation (#2051)
* fix(prometheus): use explicit UTF8 validation instead of deprecated NameValidationScheme model.NameValidationScheme is deprecated in prometheus/common. Replace its three uses (desc.go, labels.go, push/push.go) with the explicit model.UTF8Validation scheme and drop the now-unneeded //nolint:staticcheck directives. The global already defaults to UTF8Validation, so default validation behavior is unchanged; setups that set it to LegacyValidation no longer have that enforced at construction, and UTF-8 validation is more permissive, so no currently-valid name starts failing. Signed-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com> * docs(changelog): add entry for UTF-8 validation change Signed-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com> --------- Signed-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com>
1 parent e0b7a44 commit b0d896b

4 files changed

Lines changed: 4 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Unreleased
22

3+
* [CHANGE] prometheus: Name validation now always uses the UTF-8 scheme instead of the deprecated `model.NameValidationScheme` global. Default behavior is unchanged; code that set `NameValidationScheme = LegacyValidation` no longer gets legacy enforcement at metric, label, and push-grouping construction. #2051
34
* [FEATURE] HTTP handlers created by `promhttp` package now support metrics filtering by providing one or more `name[]` query parameters. The default behavior when none are provided remains the same, returning all metrics. #1925
45
* [BUGFIX] promhttp: `InstrumentHandlerDuration` and `InstrumentHandlerCounter` no longer panic when given an observer/counter that does not implement `ExemplarObserver`/`ExemplarAdder` (e.g. a `SummaryVec`). The exemplar is dropped and the value is recorded via the plain `Observe`/`Add` path, matching the safe-cast already used by `Timer.ObserveDurationWithExemplar`. #2005
56

prometheus/desc.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, const
111111
for _, opt := range opts {
112112
opt(d)
113113
}
114-
//nolint:staticcheck // TODO: Don't use deprecated model.NameValidationScheme.
115-
if !model.NameValidationScheme.IsValidMetricName(fqName) {
114+
if !model.UTF8Validation.IsValidMetricName(fqName) {
116115
d.err = fmt.Errorf("%q is not a valid metric name", fqName)
117116
return d
118117
}

prometheus/labels.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,5 @@ func validateLabelValues(vals []string, expectedNumberOfValues int) error {
184184
}
185185

186186
func checkLabelName(l string) bool {
187-
//nolint:staticcheck // TODO: Don't use deprecated model.NameValidationScheme.
188-
return model.NameValidationScheme.IsValidLabelName(l) && !strings.HasPrefix(l, reservedLabelPrefix)
187+
return model.UTF8Validation.IsValidLabelName(l) && !strings.HasPrefix(l, reservedLabelPrefix)
189188
}

prometheus/push/push.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ func (p *Pusher) Error() error {
182182
// For convenience, this method returns a pointer to the Pusher itself.
183183
func (p *Pusher) Grouping(name, value string) *Pusher {
184184
if p.error == nil {
185-
//nolint:staticcheck // TODO: Don't use deprecated model.NameValidationScheme.
186-
if !model.NameValidationScheme.IsValidLabelName(name) {
185+
if !model.UTF8Validation.IsValidLabelName(name) {
187186
p.error = fmt.Errorf("grouping label has invalid name: %s", name)
188187
return p
189188
}

0 commit comments

Comments
 (0)