mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-12-24 14:30:29 +00:00
Replace regex in escapeMetricName with loop over runes
Signed-off-by: Brian Akins <brian@akins.org>
This commit is contained in:
parent
71df5a3198
commit
d371436f01
1 changed files with 15 additions and 6 deletions
21
exporter.go
21
exporter.go
|
@ -21,7 +21,6 @@ import (
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -44,8 +43,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
|
|
||||||
|
|
||||||
hash = fnv.New64a()
|
hash = fnv.New64a()
|
||||||
strBuf bytes.Buffer // Used for hashing.
|
strBuf bytes.Buffer // Used for hashing.
|
||||||
intBuf = make([]byte, 8)
|
intBuf = make([]byte, 8)
|
||||||
|
@ -284,9 +281,21 @@ func escapeMetricName(metricName string) string {
|
||||||
metricName = "_" + metricName
|
metricName = "_" + metricName
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace all illegal metric chars with underscores.
|
out := make([]byte, len(metricName))
|
||||||
metricName = illegalCharsRE.ReplaceAllString(metricName, "_")
|
j := 0
|
||||||
return metricName
|
for _, c := range metricName {
|
||||||
|
if (c >= 'a' && c <= 'z') ||
|
||||||
|
(c >= 'A' && c <= 'Z') ||
|
||||||
|
(c >= '0' && c <= '9') {
|
||||||
|
out[j] = byte(c)
|
||||||
|
} else {
|
||||||
|
out[j] = byte('_')
|
||||||
|
}
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(out[:j])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen handles all events sent to the given channel sequentially. It
|
// Listen handles all events sent to the given channel sequentially. It
|
||||||
|
|
Loading…
Reference in a new issue