diff --git a/README.md b/README.md index dd0800a..5714bd3 100644 --- a/README.md +++ b/README.md @@ -65,16 +65,12 @@ metric.name:0|c|#tagName=val,tag2Name=val2 See [Tags](https://docs.datadoghq.com/developers/dogstatsd/data_types/#tagging) in the DogStatsD documentation for the concept description and [Datagram Format](https://docs.datadoghq.com/developers/dogstatsd/datagram_shell/). -Note that this tagging style is incompatible with the original `statsd` -implementation, you will be unable to use it as a repeater in front of the -statsd-to-prometheus exporter. +If you encounter problems, note that this tagging style is incompatible with +the original `statsd` implementation. -Although you can use both name-appended tags (Librato or InfluxDB) and -metric-appended tags simultaneously, this is not recommended. If you do, be -aware that DogStatsD `name=value` pairs will take priority over Librato tags -with the same name. - -Tags without values (`#some_tag`) are not supported and will be dropped. +Be aware: If you mix tag styles (e.g., Librato/InfluxDB with DogStatsD), the +exporter will consider this an error and the sample will be discarded. Also, +tags without values (`#some_tag`) are not supported and will be ignored. ## Building and Running diff --git a/bridge_test.go b/bridge_test.go index 03cd2e1..75826fa 100644 --- a/bridge_test.go +++ b/bridge_test.go @@ -238,15 +238,17 @@ func TestHandlePacket(t *testing.T) { }, }, }, { - name: "librato and datadog tag extension with sampling", + name: "librato/dogstatsd mixed tag styles without sampling", + in: "foo#tag1=foo,tag3=bing:100|c|#tag1:bar,#tag2:baz", + out: Events{}, + }, { + name: "influxdb/dogstatsd mixed tag styles without sampling", + in: "foo,tag1=foo,tag3=bing:100|c|#tag1:bar,#tag2:baz", + out: Events{}, + }, { + name: "mixed tag styles with sampling", in: "foo#tag1=foo,tag3=bing:100|c|@0.1|#tag1:bar,#tag2:baz", - out: Events{ - &CounterEvent{ - metricName: "foo", - value: 1000, - labels: map[string]string{"tag1": "bar", "tag3": "bing", "tag2": "baz"}, - }, - }, + out: Events{}, }, { name: "histogram with sampling", in: "foo:0.01|h|@0.2|#tag1:bar,#tag2:baz", diff --git a/exporter.go b/exporter.go index 8f4041d..a589f17 100644 --- a/exporter.go +++ b/exporter.go @@ -399,9 +399,19 @@ func lineToEvents(line string) Events { labels := map[string]string{} metric := parseNameAndLabels(elements[0], labels) + var samples []string if strings.Contains(elements[1], "|#") { - // using datadog extensions, disable multi-metrics + // using datadog extensions + + // don't allow mixed tagging styles + if len(labels) > 0 { + sampleErrors.WithLabelValues("malformed_line").Inc() + log.Debugln("Bad line (multiple tagging styles) from StatsD:", line) + return events + } + + // disable multi-metrics samples = elements[1:] } else { samples = strings.Split(elements[1], ":")