-
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
Ensure that nil registers are treat as a no-op, even when wrapping. #764
Conversation
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
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.
TBH I think we might instead of this go for noop
pattern instead. If we would have just prometheus.NoopRegistry
we could just remove all nil checks and go for it - it would much cleaner nicer.
Also technically those are two separate packages, so no need to be consistent logic wise, but it makes sense to me. 👍
So LGTM, although I would prefer noop pattern - we can changed that later I guess.
Also: I think this might deserve some comment on those method, but probably @beorn7 might know more where and if required, so deffering to him (:
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
I'm a fan of the NoopRegisterer approach too, but I spoke with @beorn7 and he preferred this approach, and I kinda agree with him now. We already assume nil is safe in promauto, and therefore adding a NoopRegisterer would not allow us to remove these checks, in effect doing it both ways. Plus this way the zero value for Registerer is a valid, which is mode idiomatic, no? |
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.
Could you also add to the doc comment of WrapRegistererWith
and WrapRegistererWithPrefix
that wrapping a nil
value is valid, resulting in a no-op Registerer?
It's trivial to implement a no-op implementation of a |
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
Will merge on green! |
|
Thanks for this discussion, overall I agree with the way to go for now, but I would be curious what would be the best approach for future (e.g
I don't get why import is the problem. Anyway, I think I agree with this direction going forward. While I definitely like explicitly marking no instrumentation with |
Passing a
nil
is useful in tests, but our treatment ofnil
is inconsistent.This code does not panic:
Where as the following does panic.
Signed-off-by: Tom Wilkie tom.wilkie@gmail.com