cactus / go-statsd-client

statsd client for Go
MIT License
188 stars 56 forks source link

Gauge accepts int64 #36

Closed jkrez closed 6 years ago

jkrez commented 6 years ago

Hi- I was wondering why the interface for Gauge doesn't accept float64.

dropwhile commented 6 years ago

The statsd spec implies (or did long ago) integers, as well as many of the example client implementations (and server implementations). ref: https://github.com/etsy/statsd/blob/master/docs/metric_types.md#gauges

My recollection (this client is now 6 years old in fact!) is that I erred on the side of caution due to the wide range of servers out there at the time.

So, you currently have a few options:

  1. One option with the current api is to convert your float value to a whole number before submitting to the gauge (e.g. change precision on your gauge).

  2. A second option is to use the Raw method to submit your own preformatted value.

  3. A third option is to add your own GaugeFloat type to your own class via embedding, and utilize that for your values.


All that said, I would be willing to accept a new pair of methods for a float gauge (submit and delta) -- the current methods can't change types, due to api compatibility requirements.

Something like GaugeFloat (and GaugeFloatDelta) that takes a float64. Perhaps with a documented caveat that not all servers are guaranteed to support a float64 gauge.

jkrez commented 6 years ago

Awesome. Thanks for the response. I agree it's not clear in the spec if floats are supported or not, but I've seen quite a few clients / servers that supported it. I'll probably get along for now with with int64 and if needed i'll go with approach 2 or 3.

dropwhile commented 6 years ago

@jkrez I created a branch with a GaugeFloat method, that you could try as well, if needed.

jkrez commented 6 years ago

For now I've forked the repo and added support for float timers, counters, gauges here: https://github.com/jkrez/go-statsd-client I'll probably refactor this at some point. I was thinking of doing what alexcesaro did with just allowing the client to log anything via interface{} and push validation logic to the server.

billygout commented 2 years ago

@dropwhile looks like this GaugeFloat() method would be great for my application. Could it be merged into master?

dropwhile commented 2 years ago

@billygout The branch probably need a bit of cleanup, but I'll take a look at it.

dropwhile commented 2 years ago

This is now added as part of https://github.com/cactus/go-statsd-client/issues/57