forked from mirrors/statsd_exporter
Add comments explaining escapeMetricName
Signed-off-by: Brian Akins <brian@akins.org>
This commit is contained in:
parent
d371436f01
commit
e6bdf13407
|
@ -275,12 +275,16 @@ type Exporter struct {
|
||||||
labelValues map[string]map[uint64]*LabelValues
|
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 {
|
func escapeMetricName(metricName string) string {
|
||||||
// If a metric starts with a digit, prepend an underscore.
|
// If a metric starts with a digit, prepend an underscore.
|
||||||
if len(metricName) > 0 && metricName[0] >= '0' && metricName[0] <= '9' {
|
if len(metricName) > 0 && metricName[0] >= '0' && metricName[0] <= '9' {
|
||||||
metricName = "_" + metricName
|
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))
|
out := make([]byte, len(metricName))
|
||||||
j := 0
|
j := 0
|
||||||
for _, c := range metricName {
|
for _, c := range metricName {
|
||||||
|
|
Loading…
Reference in a new issue