-
Notifications
You must be signed in to change notification settings - Fork 495
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
Add ObserverEffect and Nil* metrics. #17
Conversation
See the comment on ObserverEffect in metrics.go for more. Note that this changes the signature of New* for all metrics to return the interface type. I remember a discussion on the mailing list long ago that convinced me to change the return value of those functions to a concrete type but I can't recall why and this is a good reason to change it back.
Would love to see the mailing list discussion that made you go with a regular struct. This looks good, other than the fact that you're breaking master Of course, I encourage this as each time this happens, we move closer to a point where the community starts to converge on a solution for versioning. |
I like this and the patch looks good. I'm not sure I like the name |
Alright, ETOOCLEVER, I'll change it. |
type NilCounter struct{} | ||
|
||
// Force the compiler to check that NilCounter implements Counter. | ||
var _ Counter = NilCounter{} |
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.
This is cool trick, but unnecessary here since NewCounter will enforce the same thing.
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 actually was gonna say something about ObserverEffect
but then I
remembered getFletcherFromDayCare
and decided I had no platform whence to
speak.
On Fri, Sep 13, 2013 at 11:51 AM, Wade Simmons notifications@github.comwrote:
In counter.go:
@@ -13,6 +13,32 @@ type Counter interface {
Inc(int64)
}+// Create a new Counter.
+func NewCounter() Counter {
- if UseNilMetrics {
return NilCounter{}
- }
- return &StandardCounter{0}
+}
+// No-op Counter.
+type NilCounter struct{}
+
+// Force the compiler to check that NilCounter implements Counter.
+var _ Counter = NilCounter{}This is cool trick, but unnecessary here since NewCounter will enforce the
same thing.—
Reply to this email directly or view it on GitHubhttps://github.com//pull/17/files#r6355966
.
This bug was already fixed by rcrowley#20 (and reported in rcrowley#19) but was rolled back after merging rcrowley#17. `uncounted` has been moved to top with a comment explaining that it should stay at top. This is not mandatory but this is the easiest way to ensure a good alignment in the future without taking too much care. This alignment is required to use atomic functions as explained here: http://godoc.org/sync/atomic#pkg-note-bug
See the comment on ObserverEffect in metrics.go for more.
Note that this changes the signature of New* for all metrics to return the interface type. I remember a discussion on the mailing list long ago that convinced me to change the return value of those functions to a concrete type but I can't recall why and this is a good reason to change it back.