mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-26 17:21:01 +00:00
Extract individual tag parsing into new function
Signed-off-by: Clayton O'Neill <claytono@github.com>
This commit is contained in:
parent
a441eac07a
commit
e3cdd85a09
1 changed files with 23 additions and 21 deletions
44
exporter.go
44
exporter.go
|
@ -584,32 +584,34 @@ func buildEvent(statType, metric string, value float64, relative bool, labels ma
|
|||
}
|
||||
}
|
||||
|
||||
func parseDogStatsDTagToKeyValue(tag string) (k, v string) {
|
||||
// Bail early if the tag is empty
|
||||
if len(tag) == 0 {
|
||||
return
|
||||
}
|
||||
// Skip hash if found.
|
||||
if tag[0] == '#' {
|
||||
tag = tag[1:]
|
||||
}
|
||||
|
||||
// find the first comma and split the tag into key and value.
|
||||
for i, c := range tag {
|
||||
if c == ':' {
|
||||
k = tag[0:i]
|
||||
v = tag[(i + 1):]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func parseDogStatsDTagsToLabels(component string) map[string]string {
|
||||
labels := map[string]string{}
|
||||
tagsReceived.Inc()
|
||||
tags := strings.Split(component, ",")
|
||||
for _, t := range tags {
|
||||
// Bail early if the tag is empty
|
||||
if len(t) == 0 {
|
||||
tagErrors.Inc()
|
||||
log.Debugf("Empty tag found in '%s'", component)
|
||||
continue
|
||||
}
|
||||
// Skip hash if found.
|
||||
if t[0] == '#' {
|
||||
t = t[1:]
|
||||
}
|
||||
|
||||
// find the first comma and split the tag into key and value.
|
||||
var k, v string
|
||||
for i, c := range t {
|
||||
if c == ':' {
|
||||
k = t[0:i]
|
||||
v = t[(i + 1):]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
k, v := parseDogStatsDTagToKeyValue(t)
|
||||
// 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 {
|
||||
|
|
Loading…
Reference in a new issue