Skip to content

Commit 78f5a69

Browse files
committed
Use explicit name validation schemes
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
1 parent d8d6345 commit 78f5a69

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

prometheus/desc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, const
9595
help: help,
9696
variableLabels: variableLabels.compile(),
9797
}
98-
if !model.IsValidMetricName(model.LabelValue(fqName)) {
98+
//nolint:staticcheck. // TODO: Don't use deprecated model.NameValidationScheme.
99+
if !model.NameValidationScheme.IsValidMetricName(fqName) {
99100
d.err = fmt.Errorf("%q is not a valid metric name", fqName)
100101
return d
101102
}

prometheus/internal/go_runtime_metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func RuntimeMetricsToProm(d *metrics.Description) (string, string, string, bool)
6767
}
6868

6969
// Our current conversion moves to legacy naming, so use legacy validation.
70-
valid := model.IsValidLegacyMetricName(namespace + "_" + subsystem + "_" + name)
70+
valid := model.LegacyValidation.IsValidMetricName(namespace + "_" + subsystem + "_" + name)
7171
switch d.Kind {
7272
case metrics.KindUint64:
7373
case metrics.KindFloat64:

prometheus/labels.go

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

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

prometheus/push/push.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ 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-
if !model.LabelName(name).IsValid() {
185+
//nolint:staticcheck // TODO: Don't use deprecated model.NameValidationScheme.
186+
if !model.NameValidationScheme.IsValidLabelName(name) {
186187
p.error = fmt.Errorf("grouping label has invalid name: %s", name)
187188
return p
188189
}

0 commit comments

Comments
 (0)