The current mechanism to enable Micrometer metrics for Mongo is to add the MongoMetricsCommandListener to the MongoClientSettings.Builder. This code proposal simply auto-configures in this command listener when appropriate.
:information_source: There is also a MongoMetricsConnectionPoolListener that would add more Mongo (connection pool) metrics. However, I left it out because it has a dependency on legacy com.mongodb.MongoClient
as well as some Mongo event classes that were removed in Mongo 4 Java driver. I am planning on submitting a fix to Micrometer to bring it up to speed w/ Mongo 4 driver. Once that is available, I will circle back here and auto-configure it in.
Comment From: onobc
Thanks very much for the PR, @bono007. On first review, this looks excellent. I've left a few minor comments for your consideration when you have a moment.
Thanks @wilkinsona . I am just now getting back to this and will update w/ suggestions shortly.
Unfortunately, it's too late to add enhancements in 2.4, but we should hopefully be able to merge this for 2.5.
No worries.
Comment From: jonatan-ivanov
@bono007 Would you be up to merging this and #25758 together so that both mongo metrics listeners and tag providers will be auto-configured?
Comment From: onobc
Perfect timing @jonatan-ivanov. My plan was to add the connection pool metrics listener auto-config this weekend. I will instead happily merge your proposal into this one in the next 12-36hrs.
@wilkinsona are you ok w/ me combining #25758 into here?
Comment From: wilkinsona
The code in #25758 in its current form needs to be reworked as the additions have been made in spring-boot-autoconfigure
rather than spring-boot-actuator-autoconfigure
. I haven't looked at things in detail, but I suspect it may be quicker to redo the tag listener part on top of what's already proposed here rather than trying to merge things together.
Comment From: onobc
Yep I saw that as well. Sorry for the lack of clarification @wilkinsona - I did not mean literally "merge" - but rather bring the code into this MR.
Sounds good. I will do this in the 24-36hrs.
Comment From: onobc
Thanks again, @bono007. I've left a few comments for you consideration.
I've also opened micrometer-metrics/micrometer#2541 which may have an effect on this changes. This is just FYI at the moment. If the Micrometer team adopt my suggestion, we can make any updates in Boot at that time.
Oh man, that was me. I created these and while I did see the other tags provider I failed to snap to the naming not containing "Metrics". Uggh, naming. :) I will submit a proposal for these changes in Micrometer.
Comment From: onobc
I made the suggested naming changes and yanked the link to the Mongo docs @wilkinsona . I like it much better. Please take a scan when you can. Thanks.
Comment From: jonatan-ivanov
fyi: the tags providers were renamed, they are available in the snapshot: https://github.com/micrometer-metrics/micrometer/pull/2548/files
Comment From: wilkinsona
Thanks again for the PR, @bono007. I've merged the proposed changes along with a small polishing commit.