mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-12-23 22:10:30 +00:00
Add comments explaining escapeMetricName
Signed-off-by: Brian Akins <brian@akins.org>
This commit is contained in:
parent
d371436f01
commit
e6bdf13407
1 changed files with 4 additions and 0 deletions
|
@ -275,12 +275,16 @@ type Exporter struct {
|
|||
labelValues map[string]map[uint64]*LabelValues
|
||||
}
|
||||
|
||||
// Replace invalid characters in the metric name with "_"
|
||||
// Valid characters are a-z, A-Z, 0-9, and _
|
||||
func escapeMetricName(metricName string) string {
|
||||
// If a metric starts with a digit, prepend an underscore.
|
||||
if len(metricName) > 0 && metricName[0] >= '0' && metricName[0] <= '9' {
|
||||
metricName = "_" + metricName
|
||||
}
|
||||
|
||||
// this is an character replacement method optimized for this limited
|
||||
// use case. It is much faster than using a regex.
|
||||
out := make([]byte, len(metricName))
|
||||
j := 0
|
||||
for _, c := range metricName {
|
||||
|
|
Loading…
Reference in a new issue