statsd icon indicating copy to clipboard operation
statsd copied to clipboard

How to escape metrics with colon in the name

Open pataquets opened this issue 9 years ago • 6 comments

I'm sending metrics which use colon char as a namespace hierarchical separator in their names. Since it is also the field separator for StatsD, I get DEBUG: Bad line: a in msg "foo:a:b:1|c" when debuging with echo "foo:a:b:1|c" | nc -u -w0 127.0.0.1 8125. Tried escaping colons with preceding backslashes (\:) but same error. Is there any escape sequence? If not, would not it be desirable/acceptable as a feature request and/or patch? TIA.

pataquets avatar Aug 22 '16 18:08 pataquets

Bump. With my limited JS knowledge, in statsd.js looks like there isn't any code to deal with metrics containing colons. Would be grateful if someone knowledgeable could confirm and, those who can, provide feedback on the chances of having colons to be accepted.

pataquets avatar Aug 31 '16 19:08 pataquets

The StatsD protocol relies on the ':' character to separate the metric name from the metric value. Having ':' characters in the incoming metric name is not supported.

Is it possible to replace that character before sending the metric to StatsD?

benburry avatar Sep 16 '16 03:09 benburry

Thanks for confirming, Ben. Currently, that's what I'm doing as a workaround. But, since in my case colons are used everywhere as namespace separators, I would like to know if accepting colons in metric names would be desirable/acceptable as a feature request and/or patch. If I'm not wrong, just escaping them with a backslash would do the trick. What do you think?

pataquets avatar Sep 16 '16 12:09 pataquets

This is tricky, one way to potentially solve this is to use percent encoding. Which means the parser should be aware of such thing.

juneidy avatar Oct 31 '18 14:10 juneidy

What if the parser just "waits" for the last colon by splitting the metrics name or something like that - wouldn't that be a seamless solution?

You know that everything that comes after the last colon, is the metrics value. Everything else before is the name

I mean something like that

> echo "some:metrics:name.timestamp:12.3456|ms" | grep -o '[^:]*$'
12.3456|ms

sgohl avatar Dec 05 '22 13:12 sgohl

Would replacing the following https://github.com/statsd/statsd/blob/9cf77d87855bcb69a8663135f59aa23825db9797/stats.js#L261-L262 with something like that

let key;
({ key, bits } = bits[0].match(/^(?<key>.*):(?<bits>[^:]*)$/).groups);

do the trick?

serge-medvedev avatar Feb 19 '23 23:02 serge-medvedev