diff --git a/exporter.go b/exporter.go index c225fcf..a2ad52f 100644 --- a/exporter.go +++ b/exporter.go @@ -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 {