diff --git a/bridge_test.go b/bridge_test.go index 8864a76..4f180a2 100644 --- a/bridge_test.go +++ b/bridge_test.go @@ -66,6 +66,26 @@ func TestHandlePacket(t *testing.T) { labels: map[string]string{"tag1": "bar", "tag2": "baz", "tag3": ".", "tag4": "."}, }, }, + }, { + name: "datadog tag extension with # in all keys (as sent by datadog php client)", + in: "foo:100|c|#tag1:bar,#tag2:baz,#tag3,#tag4", + out: Events{ + &CounterEvent{ + metricName: "foo", + value: 100, + labels: map[string]string{"tag1": "bar", "tag2": "baz", "tag3": ".", "tag4": "."}, + }, + }, + }, { + name: "datadog tag extension with tags unsupported by prometheus", + in: "foo:100|c|#09digits:0,tag.with.dots,tag_with_empty_value:", + out: Events{ + &CounterEvent{ + metricName: "foo", + value: 100, + labels: map[string]string{"_09digits": "0", "tag_with_dots": ".", "tag_with_empty_value": "."}, + }, + }, }, { name: "datadog tag extension with sampling", in: "foo:100|c|@0.1|#tag1:bar,tag2,tag3:baz", diff --git a/exporter.go b/exporter.go index 5ed24ca..1a0b369 100644 --- a/exporter.go +++ b/exporter.go @@ -360,17 +360,25 @@ func (l *StatsDListener) handlePacket(packet []byte, e chan<- Events) { } value /= samplingFactor case '#': - networkStats.WithLabelValues("dogstasd_tags").Inc() - tags := strings.Split(component[1:], ",") + networkStats.WithLabelValues("dogstatsd_tags").Inc() + tags := strings.Split(component, ",") for _, t := range tags { + t = strings.TrimPrefix(t, "#") kv := strings.Split(t, ":") + tag_key := kv[0] + tag_key = escapeMetricName(tag_key) + + var tag_value string if len(kv) == 2 { if len(kv[1]) > 0 { - labels[kv[0]] = kv[1] + tag_value = kv[1] + } else { + tag_value = "." } } else if len(kv) == 1 { - labels[kv[0]] = "." + tag_value = "." } + labels[tag_key] = tag_value } default: log.Printf("Invalid sampling factor or tag section %s on line %s", components[2], line)