-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Timer helpers #1854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Timer helpers #1854
Conversation
Signed-off-by: Vladimir Buyanov <[email protected]>
Signed-off-by: Vladimir Buyanov <[email protected]>
1777cf3
to
eb20df1
Compare
Thanks for this proposal! BTW: Likely here or Slack is a better place for those discussions. I have some questions around benefit vs cons (code to maintain, 2 ways of doing same thing). Correct if I'm wrong, but I see you proposed: 1)
|
func NewCounterFunc(opts CounterOpts, function func() float64) CounterFunc { |
NewCounterTimer
etc. Questions is... should add typed versions OR try write generic ones (Timer and TimerVec only would work for observers, perhaps even for all metrics if we use ObserveDuration for adding and setting logic).If we want to make NewTimer work for counters/gauges it could be possible without braking changes with any
, so
func NewTimer(o Observer) *Timer {
into
func NewTimer(o any) *Timer {
.. but maybe it's too much -- maybe it's ok to have per metric type functions with corresponding opts, similar to *Func types
Hello. 1) Wrap methods.Yes, it does exactly that. But with a few caveats.
VS
I understand that the difference is not very big, but it is there.
Can be mistakenly converted to:
And although this is 100% the fault of the programmer who did this, but it seems to me that a good API should protect against errors, and not push towards them. 2) TimerHistogram typeYou are right, this type is made to maintain a uniform API and does not provide new functionality. 3) TimerHistogramVec typeYes, we can do it like this:
Do you like this? 4) TimerCounter typeYes, we can call the method AddDuration instead of Observe. 5) TimerContinuous typeI poked around for 10 minutes and couldn't figure out how to use CounterFunc to implement a ticking timer. I'll think about it some more, but if you have an idea of what it might look like, that would help. |
Hello.
I'm proposing to add several helper functions to make working with timers more convenient.
I haven’t brought this up on the mailing list yet, but I’d like to hear your feedback.
The code is still a draft; if you like the approach, I’ll add more detailed comments, tests, and documentation.
Here are a few examples of how the new timers could be used: