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

Pull out ...WithExemplar methods into separate interfaces #708

Merged
merged 1 commit into from Jan 27, 2020

Conversation

beorn7
Copy link
Member

@beorn7 beorn7 commented Jan 25, 2020

This is, sadly, the only way to avoid a breaking change. The cost is
that anyone using exemplars has to perform a type assertion. This is,
however, a common pattern where interfaces turn out to need additional
methods in a stable library or only some implementations can provide
the additional methods (AKA "interface upgrade").

Needless to say that in v2 of this library, we'll do things in a more
straight forward way.

By now, I'm fairly confident we need to go down this way. It would be extremely confusing and damaging if enough users got bitten by the original approach so that we had to revert to the approach in this PR anyway.

The trade-off in this PR is the following: I'd expect relatively few users to use exemplars. And those who do are most likely advanced users who are not shocked by a type assertion. Thus, the collective cost is relatively low, but it buys as the benefit of not risking breakage.

On top of all that, a user of a HistogramVec has to do the type assertion anyway.

In different news, I'm still torn about the naming. The interface name should follow the pattern with the ...er suffix, but ObserveWithExemplarer is not really an option. ExemplarObserver is not too bad, but perhaps we should rename the method to ExemplarObserve then? Not quite as descriptive, but the upside is that it is shorter.

WDYT?

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this much more and I don't feel it adds much of complexity for the users. Given the proper support for exemplars will take for backends months, we will probably have already a v2 where we can change things.

I am fully on board with this replacing the incompatibility we added previously 👍 Thanks!

// Demonstrate exemplar support with a dummy ID. This would be
// something like a trace ID in a real application.
// Note the necessary type assertion.
rpcDurationsHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar(
Copy link
Member

@bwplotka bwplotka Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe in this example check if it's actually implementing this? So:

if e, ok := rpcDurationsHistogram.(prometheus.ExemplarObserver); ok {
  e..ObserveWithExemplar( ...
}

Copy link
Member

@bwplotka bwplotka Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because encouraging avoiding panics in user's code is nice... But one can argue that we directly call our library constructor, so up to you here, not a blocker (:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's all in the same file. I have added a comment now that explains why we don't check the type assertion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I'll also fix the "tipo". :o(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

This is, sadly, the only way to avoid a breaking change. The cost is
that anyone using exemplars has to perform a type assertion. This is,
however, a common pattern where interfaces turn out to need additional
methods in a stable library or only some implementations can provide
the additional methods (AKA "interface upgrade").

Needless to say that in v2 of this library, we'll do things in a more
straight forward way.

Signed-off-by: beorn7 <beorn@grafana.com>
@beorn7
Copy link
Member Author

beorn7 commented Jan 27, 2020

Given the proper support for exemplars will take for backends months, we will probably have already a v2 where we can change things.

I wouldn't be that optimistic. I expect v2 to take a while to reach a usable state. And even after that has happened, we'll need some time where the v2 branch can be used experimentally but will still need some time to stabilize for a real v2 release. And ever after that, I'd expect v1 to be used by a significant fraction of the current ~12k known importers for a long time…

Anyway, I assume that the above won't swing your otherwise quite clear verdict here. I'm fairly confident this is the way to go, too. I'll merge this and then adjust the release PR for final approval.

@beorn7 beorn7 merged commit e951d7b into master Jan 27, 2020
@beorn7 beorn7 deleted the beorn7/exemplars branch January 27, 2020 14:44
@bwplotka
Copy link
Member

Awesome, yup same opinion on my side.

@beorn7 beorn7 mentioned this pull request Jan 27, 2020
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

2 participants