X-pack/metricbeat/module/statsd: Unable to parse float values (statsd module) of counter metric type

I was exploring statsd's module code in beats while making some changes to the same and I noticed that the for metrics of type counter, we just support integers (of base 10 and 64 bitsize) and in case it is not the same, it errors out. But ideally it should be able to handle float values as well.

If we refer statsd'd official repository's docs: GitHub - statsd/statsd: Daemon for easy but powerful stats aggregation then we can see the following as the definition of values:

  • values

Each stat will have a value. How it is interpreted depends on modifiers. In general values should be integers.

So in general the values are integers but ideally the parsers should handle other scenarios as well. Looking at the code, changes look simple and I'd like to volunteer for the same. Also, several statsd client packages allow setting counter or gauge values with float64.

Example error that we get if we try to parse float values:

strconv.ParseInt: parsing "11.0": invalid syntax failed to process counter counter1 with value 11.0 github.com/elastic/beats/v7/x-pack/metricbeat/module/statsd/server.

Also, do see this: Statsd counter float values · Issue #556 · influxdata/telegraf · GitHub; telegraf also had a same issue when parsing metrics from consul. The fix was done as part of this PR: statsd: If parsing a value to int fails, try to float and cast to int by sparrc · Pull Request #561 · influxdata/telegraf · GitHub.

So, in case we are making this change, then what should be the approach:

  • Parse float values and keep it as it is.
  • Parse float values and cast it to int like telegraf is doing?

Related code: https://github.com/elastic/beats/blob/main/x-pack/metricbeat/module/statsd/server/data.go#L175

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

Fixed by x-pack/metricbeat/module/statsd: Add support for float64 values for metrics of counter type by shmsr · Pull Request #35099 · elastic/beats · GitHub