segmentio / stats

Go package for abstracting stats collection
https://godoc.org/github.com/segmentio/stats
MIT License
208 stars 32 forks source link

add influxdb client #49

Closed achille-roussel closed 7 years ago

achille-roussel commented 7 years ago

This PR adds support for InfluxDB to the stats package. The intent here is to have a InfluxDB client so I can start experimenting with it without having to rewrite any instrumentation code.

The client API is very similar to the one for datadog, basically:

stats.Register(influxdb.NewClient("localhost:8086"))

I spent a bit of time profiling and optimizing the code, basically I was thinking of taking two different approaches to manage the batches of metrics:

I ended going for the first solution because it was the most time-efficient implementation (~200ns per metric), however it requires sorting the tags when handling the metrics, which is on the hot path here... if sorting ends up being a bottleneck we can revisit and see if we can optimize the second approach. The implementation also is fully wait-free, it uses atomic operations to synchronize concurrent operations on shared resources, this prevents having a high contention point if we were using a mutex in HandleMetrics.

Please take a look and let me know if you'd like to see anything changed.

achille-roussel commented 7 years ago

Thanks for the review!