Skip to content

Conversation

@jonatlib
Copy link

@jonatlib jonatlib commented Jan 16, 2017

Support for float metrics

Statsd server supports gauges and timers to contains float values.

Why

  • Gauges can store float values for many reasons.
  • This is needed for timers - because without float values you cannot send values which are less than 1 [ms].

Implementation

Implementation is done by:

  1. Changes type value in gauge and timer methods to float.
  2. adding new class FloatMetric which holds a float value.
  3. Extracted value formating from Metric::encodeTo to new virtual method Metric::formatValue
  4. Implement FloatMetric::formatValue
  5. Added ability to store both types of metrics in SampledMetric::metric_.
    - This is changing SampledMetric::metric_ to a pointer.
    - Then a destructor for SampledMetric is implemented and copy constructors for: Metric, FloatMetric and SampledMetric
  6. Update tests in python and added test for float numbers

Which metric is being used is decided by constructor overloading.

Conclusion

Implementation using templates in C++ part would be much nicer, but it would introduce more pointers and dynamic memory allocation, which i tried to avoid.

This solution uses only one pointer which is created in constructor of SampledMetric and then removed in it's destructor so it is still easily manageable and it follow RAII.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant