Add comments explaining escapeMetricName

Signed-off-by: Brian Akins <brian@akins.org>
This commit is contained in:
Brian Akins 2019-04-09 11:52:31 -04:00
parent d371436f01
commit e6bdf13407

View file

@ -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 {