-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bring Gauges and Counters in line with client library guidelines #259
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -30,7 +30,8 @@ type Counter interface { | |||
Metric | |||
Collector | |||
|
|||
// Inc increments the counter by 1. | |||
// Inc increments the counter by 1. Use Add to increment it by arbitrary | |||
// positive values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-negative
Zero is okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
- Deprecate Untyped for direct instrumentation. - Add a SetToCurrentTime method to Gauge Note that adding the SetToCurrentTime method is not really following Go's principle of lean interfaces. However, the Gauge interface is already quite fat. (The only methods really required are Set and Add. Everything else could be expressed in terms of those two.) So we have already quite a few "convenience" methods traditionally, so I think we should stay consistent here. The alternatives would be: - Not support SetToCurrentTime at all (it's only a SHOULD in the guidelines). - A top level function `SetToCurrentTime(Gauge)`. - Just a helper `CurrentTime()` that returns the curent unix time in seconds as a float (which is pretty verbose using the standard library, see code in this commit). This would allow `myGauge.Set(CurrentTime)`. Weighing all circumstances, I believe the way in this commit is the least evil. Issue #223 could be used to rework interfaces more fundamentally in a breaking change if feasible.
d32b70d
to
606b8f8
Compare
I'll merge this for now. If radical Gophers have issues with the new method, we can discuss later. |
|
||
delta := unixTime - m.GetGauge().GetValue() | ||
// This is just a smoke test to make sure SetToCurrentTime is not | ||
// totally off. Tests with current time involved are hard... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is fine, especially given the simplicity of the method invoked.
👍 |
Point from Inc and Dec to Add and Sub in doc comments.
Deprecate Untyped for direct instrumentation.
Add a SetToCurrentTime method to Gauge
Note that adding the SetToCurrentTime method is not really following
Go's principle of lean interfaces. However, the Gauge interface is
already quite fat. (The only methods really required are Set and
Add. Everything else could be expressed in terms of those two.) So we
have already quite a few "convenience" methods traditionally, so I
think we should stay consistent here.
The alternatives would be:
Not support SetToCurrentTime at all (it's only a SHOULD in the
guidelines).
A top level function
SetToCurrentTime(Gauge)
.Just a helper
CurrentTime()
that returns the curent unix time inseconds as a float (which is pretty verbose using the standard
library, see code in this commit). This would allow
myGauge.Set(CurrentTime)
.Weighing all circumstances, I believe the way in this commit is the
least evil. Issue #223 could be used to rework interfaces more
fundamentally in a breaking change if feasible.
@brian-brazil for guideline compliance
@stuartnelson3 for Go