-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
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.
Thanks for the PR! I added a small comment inline.
I will defer to Loïc and Bruno to check the feature.
return metricsCapability | ||
.filter(cap -> buildTimeConfig.metricsEnabled && cap.metricsSupported(MetricsFactory.MICROMETER)) | ||
.map(supported -> new AdditionalIndexedClassesBuildItem( | ||
MongoClientRecorder.getMicrometerCommandListenerClassName())) | ||
.orElseGet(AdditionalIndexedClassesBuildItem::new); |
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.
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 :).
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.
@gsmet pushforced the change
e3d1e69
to
304406f
Compare
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.
It looks ok to me but could you please add a test entry here:
quarkus/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/MongoMetricsTest.java
Line 24 in ebee0a4
public class MongoMetricsTest extends MongoTestBase { |
@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. |
@brunobat The deployment module pom has |
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. |
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.
As other already said, a test would be great
public static String getMicrometerCommandListenerClassName() { | ||
return MicrometerCommandListener.class.getName(); | ||
} | ||
|
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.
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.
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.
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
@brunobat @loicmathieu |
4659ab5
to
dc0689b
Compare
This comment has been minimized.
This comment has been minimized.
🎊 PR Preview 0396c33 has been successfully built and deployed to https://quarkus-pr-main-44999-preview.surge.sh/version/main/guides/
|
This comment has been minimized.
This comment has been minimized.
dc0689b
to
e24f716
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Looks good to me.
Thanks @vkn !
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.
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(); |
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.
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).
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.
@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
f29ef89
to
be1fa40
Compare
Status for workflow
|
Status for workflow
|
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