diff --git a/bridge_test.go b/bridge_test.go index cb4b7af..aae7bf2 100644 --- a/bridge_test.go +++ b/bridge_test.go @@ -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", diff --git a/pkg/line/line.go b/pkg/line/line.go index ddea1da..de299be 100644 --- a/pkg/line/line.go +++ b/pkg/line/line.go @@ -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 {