segmentio / stats

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

Ambiguity in README.md #89

Closed yerden closed 4 years ago

yerden commented 6 years ago

I have a question regarding this part of README.md:

m := &funcMetrics{}
m.calls.count = 1
m.calls.time = callTime

// Equivalent to:
//
//   stats.Incr("func.calls.count")
//   stats.Observe("func.calls.time", callTime)
//
stats.Report(m)

As stated here, setting counter to 1 in the struct is equivalent to calling stats.Incr(). Does it mean that counters in structs should always be deltas from previous values? Perhaps that should be stated explicitly. If so, how can I provide new measure as an absolute value?

achille-roussel commented 6 years ago

There is currently no way to provide absolute values for counters, the program would have to keep track of the last value it reported and compute the delta before submitting the next value.

This design decision results from the statsd/dogstatsd model that this package was initially designed around.

If you have a generic solution for a counter that would automatically manage the delta feel free to open a pull request, I'll be happy to review and merge your contribution!

yerden commented 6 years ago

Thanks for the answer. I guess managing absolute values would require new FieldType, like AbsCounter or so in order to maintain backward compatibility.

abraithwaite commented 6 years ago

You could also use a Gauge as a pseudo-counter. I think that would probably be the best option given that no metrics implementations (that I know of) have the concept of an absolute counter.