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

Enable more MongoDB Micrometer metrics #44999

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

vkn
Copy link
Contributor

@vkn vkn commented Dec 9, 2024

Currently only connection pool micrometer metrics are supported. This PR enables all available metrics based on io.micrometer.core.instrument.binder.mongodb.MongoMetricsCommandListener

All unit tests in mongodb-client extension are based on microprofile metrics, so it was not possible to add tests for micrometer, without modifying dependencies and existing tests. However I've added an assertion in MongodbPanacheResourceTest.java in integration-tests/mongodb-panache module

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I added a small comment inline.

I will defer to Loïc and Bruno to check the feature.

Comment on lines 131 to 135
return metricsCapability
.filter(cap -> buildTimeConfig.metricsEnabled && cap.metricsSupported(MetricsFactory.MICROMETER))
.map(supported -> new AdditionalIndexedClassesBuildItem(
MongoClientRecorder.getMicrometerCommandListenerClassName()))
.orElseGet(AdditionalIndexedClassesBuildItem::new);
Copy link
Member

Choose a reason for hiding this comment

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

Any chance you could implement this with simple ifs (with early returns for edge cases)?

Because this is a bit hard to follow and I'm worried we will regret it when fixing a bug one early morning without coffee :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gsmet pushforced the change

@vkn vkn force-pushed the mongodb-micrometer-metrics branch from e3d1e69 to 304406f Compare December 10, 2024 13:32
Copy link
Contributor

@brunobat brunobat left a comment

Choose a reason for hiding this comment

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

It looks ok to me but could you please add a test entry here:

@vkn
Copy link
Contributor Author

vkn commented Dec 10, 2024

It looks ok to me but could you please add a test entry here:

@brunobat the test is based on microprofile metrics. to add test for the micrometer metrics, we would have to refactor tests and create separate tests for micrometer and microprofile metrics. or do you see an easier way

@brunobat
Copy link
Contributor

It looks ok to me but could you please add a test entry here:

@brunobat the test is based on microprofile metrics. to add test for the micrometer metrics, we would have to refactor tests and create separate tests for micrometer and microprofile metrics. or do you see an easier way

yeah, sorry, didn't look at the imports... Then It's worse than I thought.
Can you please add a test class for Micrometer under the deployment module?

@vkn
Copy link
Contributor Author

vkn commented Dec 10, 2024

It looks ok to me but could you please add a test entry here:

@brunobat the test is based on microprofile metrics. to add test for the micrometer metrics, we would have to refactor tests and create separate tests for micrometer and microprofile metrics. or do you see an easier way

yeah, sorry, didn't look at the imports... Then It's worse than I thought. Can you please add a test class for Micrometer under the deployment module?

@brunobat The deployment module pom has quarkus-smallrye-metrics-deployment dependency. so microprofile metrics are on the class path and there is no way to add micrometer metrics, unless you agree to remove it from the pom xml and add the dependency in QuarkusUnitTest programmatically. The existing test have to be then adjusted and not import microprofile metrics, as far as I can tell

@loicmathieu
Copy link
Contributor

The deployment module pom has quarkus-smallrye-metrics-deployment dependency. so microprofile metrics are on the class path and there is no way to add micrometer metrics,

Mongodb metrics support preclude our switch to Micrometer by default that's why the test is based on Microprofile metrics, I'm OK to switch to test to Micrometer.

@vkn thanks a lot for your contribution. MongoDB could emit a lot of commands, I wonder if this listener should be added always of if we could be able to disable it for performance reason.

Copy link
Contributor

@loicmathieu loicmathieu left a comment

Choose a reason for hiding this comment

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

As other already said, a test would be great

Comment on lines 103 to 106
public static String getMicrometerCommandListenerClassName() {
return MicrometerCommandListener.class.getName();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

As this is used in a single place you can directly add the class name at the use site.
This would also avoid loading the class at runtime if not used wich would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As this is used in a single place you can directly add the class name at the use site. This would also avoid loading the class at runtime if not used wich would be better.

micrometer wasn't on class path in deployment module, that's why I've put it there. I'll add optional dependency and move the code to the deployment

@vkn
Copy link
Contributor Author

vkn commented Dec 10, 2024

@brunobat @loicmathieu
I've changed the tests to be based on micrometer. MongoMetricsTest verifies the new mongodb.driver.commands metrics are available. Please have a look

@vkn vkn requested review from loicmathieu and brunobat December 10, 2024 15:48
@vkn vkn force-pushed the mongodb-micrometer-metrics branch from 4659ab5 to dc0689b Compare December 11, 2024 12:38

This comment has been minimized.

Copy link

github-actions bot commented Dec 11, 2024

🎊 PR Preview 0396c33 has been successfully built and deployed to https://quarkus-pr-main-44999-preview.surge.sh/version/main/guides/

  • Images of blog posts older than 3 months are not available.
  • Newsletters older than 3 months are not available.

This comment has been minimized.

@vkn vkn force-pushed the mongodb-micrometer-metrics branch from dc0689b to e24f716 Compare December 11, 2024 13:42

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

@brunobat brunobat 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 to me.
Thanks @vkn !

@gsmet gsmet changed the title Enable more mongodb micrometer metrics Enable more MongoDB Micrometer metrics Dec 17, 2024
Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

Thanks for the adjustment. I requested a small change as we shouldn't produce an empty AdditionalIndexedClassesBuildItem when we don't want to produce anything.

Once this is fixed, it's all good to go.

I can do it if you prefer but I thought you might be interested in doing it yourself. Let me know!

MongoClientBuildTimeConfig buildTimeConfig,
Optional<MetricsCapabilityBuildItem> metricsCapability) {
if (!buildTimeConfig.metricsEnabled) {
return new AdditionalIndexedClassesBuildItem();
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I wouldn't do that. Even if it doesn't complain right now, that's certainly something that could break later.

What you need to do is change the method to return void and inject a BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexedClasses and call the produce() method when it makes sense (and return; if you want to exit early).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gsmet I've adjusted the code as you requested. Thanks!

Even if it doesn't complain right now,
that's certainly something that could break later
@vkn vkn force-pushed the mongodb-micrometer-metrics branch from f29ef89 to be1fa40 Compare December 17, 2024 10:52
@vkn vkn requested a review from gsmet December 17, 2024 11:28
Copy link

quarkus-bot bot commented Dec 17, 2024

Status for workflow Quarkus Documentation CI

This is the status report for running Quarkus Documentation CI on commit be1fa40.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

Warning

There are other workflow runs running, you probably need to wait for their status before merging.

Copy link

quarkus-bot bot commented Dec 17, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit be1fa40.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@brunobat brunobat merged commit 849ec70 into quarkusio:main Dec 17, 2024
24 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.18 - main milestone Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants