Skip to content
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

Merged
merged 1 commit into from
Nov 18, 2016

Conversation

beorn7
Copy link
Member

@beorn7 beorn7 commented Nov 18, 2016

  • 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 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.

@brian-brazil for guideline compliance
@stuartnelson3 for Go

Copy link
Contributor

@brian-brazil brian-brazil left a 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.
Copy link
Contributor

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.

Copy link
Member Author

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.
@beorn7
Copy link
Member Author

beorn7 commented Nov 18, 2016

I'll merge this for now. If radical Gophers have issues with the new method, we can discuss later.

@beorn7 beorn7 merged commit 87297c8 into master Nov 18, 2016
@beorn7 beorn7 deleted the beorn7/guideline-compliance branch November 18, 2016 18:33

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...
Copy link
Contributor

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.

@stuartnelson3
Copy link
Contributor

👍

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.

None yet

3 participants