Drop metrics with mixed tagging styles

Signed-off-by: Tony Wooster <twooster@gmail.com>
This commit is contained in:
Tony Wooster 2019-09-18 13:14:57 +02:00
parent e01507a57c
commit 0e000fe833
3 changed files with 26 additions and 18 deletions

View file

@ -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

View file

@ -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",

View file

@ -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], ":")