forked from mirrors/statsd_exporter
Replace SplitN w/special purpose implementation
This improves performance per call in the a-z case from around 5533 ns/op to 3169ns/op. It also drops allocations per call from 57 to 31 in the a-z case. Signed-off-by: Clayton O'Neill <claytono@github.com>
This commit is contained in:
parent
052beaa3ac
commit
a441eac07a
1 changed files with 14 additions and 3 deletions
17
exporter.go
17
exporter.go
|
@ -600,14 +600,25 @@ func parseDogStatsDTagsToLabels(component string) map[string]string {
|
||||||
t = t[1:]
|
t = t[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
kv := strings.SplitN(t, ":", 2)
|
// find the first comma and split the tag into key and value.
|
||||||
if len(kv) < 2 || len(kv[1]) == 0 {
|
var k, v string
|
||||||
|
for i, c := range t {
|
||||||
|
if c == ':' {
|
||||||
|
k = t[0:i]
|
||||||
|
v = t[(i + 1):]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If either of them is empty, then either the k or v is empty, or we
|
||||||
|
// didn't find a colon, either way, throw an error and skip ahead.
|
||||||
|
if len(k) == 0 || len(v) == 0 {
|
||||||
tagErrors.Inc()
|
tagErrors.Inc()
|
||||||
log.Debugf("Malformed or empty DogStatsD tag %s in component %s", t, component)
|
log.Debugf("Malformed or empty DogStatsD tag %s in component %s", t, component)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
labels[escapeMetricName(kv[0])] = kv[1]
|
labels[escapeMetricName(k)] = v
|
||||||
}
|
}
|
||||||
return labels
|
return labels
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue