Skip to content

Commit 4e406a7

Browse files
committed
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>
1 parent e0b7a44 commit 4e406a7

3 files changed

Lines changed: 3 additions & 6 deletions

File tree

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)