Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/promutil/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package promutil

import (
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -105,6 +106,8 @@
"%", "_percent",
)

var metricNumberPrefixRE = regexp.MustCompile(`^\d`)

type PrometheusMetric struct {
Name string
Labels map[string]string
Expand Down Expand Up @@ -194,6 +197,12 @@

// sanitize replaces some invalid chars with an underscore
func sanitize(text string) string {

Check failure on line 200 in pkg/promutil/prometheus.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofumpt)
// metrics starting with a digit violate the prometheus metric naming convention, so we add an underscore
if metricNumberPrefixRE.MatchString(text) {
text = "_" + text
}

if strings.ContainsAny(text, "“%") {
// fallback to the replacer for complex cases:
// - '“' is non-ascii rune
Expand Down
Loading