mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-12-25 23:10:29 +00:00
abort parsing tags if malformed signalfx format, add tests
Signed-off-by: glightfoot <glightfoot@rsglab.com>
This commit is contained in:
parent
5b863848dd
commit
9faa4898de
2 changed files with 28 additions and 1 deletions
|
@ -220,6 +220,26 @@ func TestHandlePacket(t *testing.T) {
|
|||
CLabels: map[string]string{},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "SignalFx tag extension, missing closing bracket",
|
||||
in: "[tag1=bar,tag2=bazfoo.test:100|c",
|
||||
out: event.Events{
|
||||
&event.CounterEvent{
|
||||
CMetricName: "[tag1=bar,tag2=bazfoo.test",
|
||||
CValue: 100,
|
||||
CLabels: map[string]string{},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "SignalFx tag extension, missing opening bracket",
|
||||
in: "tag1=bar,tag2=baz]foo.test:100|c",
|
||||
out: event.Events{
|
||||
&event.CounterEvent{
|
||||
CMetricName: "tag1=bar,tag2=baz]foo.test",
|
||||
CValue: 100,
|
||||
CLabels: map[string]string{},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "influxdb tag extension with tag keys unsupported by prometheus",
|
||||
in: "foo,09digits=0,tag.with.dots=1:100|c",
|
||||
|
|
|
@ -139,9 +139,16 @@ func parseNameAndTags(name string, labels map[string]string, tagErrors prometheu
|
|||
startIdx := strings.IndexRune(name, '[')
|
||||
endIdx := strings.IndexRune(name, ']')
|
||||
|
||||
if startIdx != -1 && endIdx != -1 {
|
||||
switch {
|
||||
case startIdx != -1 && endIdx != -1:
|
||||
// good signalfx tags
|
||||
parseNameTags(name[startIdx+1:endIdx], labels, tagErrors, logger)
|
||||
return name[:startIdx] + name[endIdx+1:]
|
||||
case (startIdx != -1) != (endIdx != -1):
|
||||
// only one bracket, return unparsed
|
||||
level.Debug(logger).Log("msg", "invalid SignalFx tags, not parsing", "metric", name)
|
||||
tagErrors.Inc()
|
||||
return name
|
||||
}
|
||||
|
||||
for i, c := range name {
|
||||
|
|
Loading…
Reference in a new issue