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

Add ObservationValidator #5300

Merged

Conversation

jonatan-ivanov
Copy link
Member

Closes gh-5239

Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

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

Looks good. I think it'd be good to have some test cases of expected instrumentation patterns and assert that there is no invalid message - we want to make sure we don't introduce false positive validation issues.

@jonatan-ivanov
Copy link
Member Author

Added some tests to cover those cases too.

@shakuzen shakuzen merged commit 4f21e1e into micrometer-metrics:main Jul 12, 2024
6 checks passed
private final Predicate<Context> supportsContextPredicate;

ObservationValidator() {
this(validationResult -> LOGGER.warn(validationResult.toString()));
Copy link
Member

Choose a reason for hiding this comment

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

I approved and merged, but I wonder if it would be better to throw an exception by default (what gets used with TestObservationRegistry). I worry that a log message in tests will very easily be missed. The things we're checking for here should plainly be instrumentation bugs and so unless there's a bug in this validator, I'm not sure it should be a problem that an exception is thrown. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. The validator is installed by default, but I can't think of a case where duplicate stops calls is not considered as a bug in the instrumentation. If somehow this is expected, people should overrride the consumer and log things.

Copy link
Member

Choose a reason for hiding this comment

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

If somehow this is expected, people should overrride the consumer and log things.

The issue with this is that the validator was intentionally made package private so it is all kept as an implementation detail. As things are, there's no option for users to override the consumer. We could make that public API so it is possible, but we'll have to make sure the API is right before going GA.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we have a few options to make this more flexible:

  1. We can make the API public and add an overload to the test registry to inject handlers
  2. We can make only the consumer part public (+ the class that is received by the consumer) and add an overload to the test registry to inject the consumer (I don't think there is a huge difference between this and the previous one)
  3. We can also add an overload to the test registry with a flag to not register the validator

Copy link
Member

Choose a reason for hiding this comment

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

I think my preference would be to switch it to throw an exception and not make anything configurable until we get feedback from a user why the validator's assumptions about correct instrumentation are wrong for their use case. Catching and ignoring the exception thrown in a test is always a workaround on a case-by-case basis. The challenge, as always, is getting enough feedback during the milestone phase before releasing GA, but it's also good for us to understand such use cases since I think we are lacking imagination to come up with them.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍🏼 In order to do that, we need to surface at least an exception so that users can handle it as needed: #5307

@jonatan-ivanov jonatan-ivanov deleted the observation-validator branch July 12, 2024 17:51
shakuzen pushed a commit that referenced this pull request Jul 18, 2024
…egistry (#5307)

Logs can be very easily missed in tests. This switches to throwing an exception which will be much more noticeable.
See gh-5300
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.

Validate expected Observation API call ordering on TestObservationRegistry
3 participants