Skip to content

Commit a9acdc7

Browse files
committed
use basic string in IsValidLegacyMetricName
Parameter didn't even match the function name. Signed-off-by: Owen Williams <[email protected]>
1 parent 0b924af commit a9acdc7

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

expfmt/openmetrics_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ func writeOpenMetricsNameAndLabelPairs(
477477
if name != "" {
478478
// If the name does not pass the legacy validity check, we must put the
479479
// metric name inside the braces, quoted.
480-
if !model.IsValidLegacyMetricName(model.LabelValue(name)) {
480+
if !model.IsValidLegacyMetricName(name) {
481481
metricInsideBraces = true
482482
err := w.WriteByte(separator)
483483
written++

expfmt/text_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func writeNameAndLabelPairs(
354354
if name != "" {
355355
// If the name does not pass the legacy validity check, we must put the
356356
// metric name inside the braces.
357-
if !model.IsValidLegacyMetricName(model.LabelValue(name)) {
357+
if !model.IsValidLegacyMetricName(name) {
358358
metricInsideBraces = true
359359
err := w.WriteByte(separator)
360360
written++
@@ -498,7 +498,7 @@ func writeInt(w enhancedWriter, i int64) (int, error) {
498498
// writeName writes a string as-is if it complies with the legacy naming
499499
// scheme, or escapes it in double quotes if not.
500500
func writeName(w enhancedWriter, name string) (int, error) {
501-
if model.IsValidLegacyMetricName(model.LabelValue(name)) {
501+
if model.IsValidLegacyMetricName(name) {
502502
return w.WriteString(name)
503503
}
504504
var written int

model/metric.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (m Metric) FastFingerprint() Fingerprint {
161161
func IsValidMetricName(n LabelValue) bool {
162162
switch NameValidationScheme {
163163
case LegacyValidation:
164-
return IsValidLegacyMetricName(n)
164+
return IsValidLegacyMetricName(string(n))
165165
case UTF8Validation:
166166
if len(n) == 0 {
167167
return false
@@ -176,7 +176,7 @@ func IsValidMetricName(n LabelValue) bool {
176176
// legacy validation scheme regardless of the value of NameValidationScheme.
177177
// This function, however, does not use MetricNameRE for the check but a much
178178
// faster hardcoded implementation.
179-
func IsValidLegacyMetricName(n LabelValue) bool {
179+
func IsValidLegacyMetricName(n string) bool {
180180
if len(n) == 0 {
181181
return false
182182
}
@@ -208,7 +208,7 @@ func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricF
208208
}
209209

210210
// If the name is nil, copy as-is, don't try to escape.
211-
if v.Name == nil || IsValidLegacyMetricName(LabelValue(v.GetName())) {
211+
if v.Name == nil || IsValidLegacyMetricName(v.GetName()) {
212212
out.Name = v.Name
213213
} else {
214214
out.Name = proto.String(EscapeName(v.GetName(), scheme))
@@ -230,7 +230,7 @@ func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricF
230230

231231
for _, l := range m.Label {
232232
if l.GetName() == MetricNameLabel {
233-
if l.Value == nil || IsValidLegacyMetricName(LabelValue(l.GetValue())) {
233+
if l.Value == nil || IsValidLegacyMetricName(l.GetValue()) {
234234
escaped.Label = append(escaped.Label, l)
235235
continue
236236
}
@@ -240,7 +240,7 @@ func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricF
240240
})
241241
continue
242242
}
243-
if l.Name == nil || IsValidLegacyMetricName(LabelValue(l.GetName())) {
243+
if l.Name == nil || IsValidLegacyMetricName(l.GetName()) {
244244
escaped.Label = append(escaped.Label, l)
245245
continue
246246
}
@@ -256,10 +256,10 @@ func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricF
256256

257257
func metricNeedsEscaping(m *dto.Metric) bool {
258258
for _, l := range m.Label {
259-
if l.GetName() == MetricNameLabel && !IsValidLegacyMetricName(LabelValue(l.GetValue())) {
259+
if l.GetName() == MetricNameLabel && !IsValidLegacyMetricName(l.GetValue()) {
260260
return true
261261
}
262-
if !IsValidLegacyMetricName(LabelValue(l.GetName())) {
262+
if !IsValidLegacyMetricName(l.GetName()) {
263263
return true
264264
}
265265
}
@@ -283,7 +283,7 @@ func EscapeName(name string, scheme EscapingScheme) string {
283283
case NoEscaping:
284284
return name
285285
case UnderscoreEscaping:
286-
if IsValidLegacyMetricName(LabelValue(name)) {
286+
if IsValidLegacyMetricName(name) {
287287
return name
288288
}
289289
for i, b := range name {
@@ -309,7 +309,7 @@ func EscapeName(name string, scheme EscapingScheme) string {
309309
}
310310
return escaped.String()
311311
case ValueEncodingEscaping:
312-
if IsValidLegacyMetricName(LabelValue(name)) {
312+
if IsValidLegacyMetricName(name) {
313313
return name
314314
}
315315
escaped.WriteString("U__")

0 commit comments

Comments
 (0)