[receiver/mongodbreceiver] Check if mongodb.flushes.rate metric is enabled before trying to collect
Description
This PR fixes the issue stated below, where mongodb receiver tries to collect WiredTiger checkpoint data for disabled metric mongodb.flushes.rate. I think we should add if clause to all metrics that can be disabled, let's discuss.
Link to tracking issue
Fixes https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/41465
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: odorT / name: Kamran Karimov (5ad9c24221e848054208070e3725777531951a32)
@justinianvoss22 should I add if clause to all metrics that can be disabled?
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/ef72f9e9904f887122072f787391c7a09573dd3f/receiver/mongodbreceiver/scraper.go#L254-L269
please run make chlog-new and add the changelog file to your PR.
[like] Kamran Karimov reacted to your message:
From: Antoine Toulme @.> Sent: Monday, July 28, 2025 11:16:07 PM To: open-telemetry/opentelemetry-collector-contrib @.> Cc: Kamran Karimov @.>; Mention @.> Subject: Re: [open-telemetry/opentelemetry-collector-contrib] [receiver/mongodbreceiver] Check if mongodb.flushes.rate metric is enabled before trying to collect (PR #41604)
[https://avatars.githubusercontent.com/u/16758?s=20&v=4]atoulme left a comment (open-telemetry/opentelemetry-collector-contrib#41604)https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/41604#issuecomment-3130103537
please run make chlog-new and add the changelog file to your PR.
— Reply to this email directly, view it on GitHubhttps://github.com/open-telemetry/opentelemetry-collector-contrib/pull/41604#issuecomment-3130103537, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN6E2NBCTVZC3PZJSXSR3UL3K2VLPAVCNFSM6AAAAACCO67V2OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCMZQGEYDGNJTG4. You are receiving this because you were mentioned.Message ID: @.***>
This PR was marked stale due to lack of activity. It will be closed in 14 days.
@justinianvoss22 can you please review as the codeowner for MongoDB receiver?
@justinianvoss22 please review as codeowner
@justinianvoss22 should I add if clause to all metrics that can be disabled?
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/ef72f9e9904f887122072f787391c7a09573dd3f/receiver/mongodbreceiver/scraper.go#L254-L269
@odorT Sorry for the delay in response.
It makes sense to add condition checks to all metrics that can be disabled. Looks like many metrics in recordAdminStats and some in recordNormalServerStats can be checked.
Thanks for response @justinianvoss22 , sure, will send commit this week
@justinianvoss22 Could you please elaborate on why we shouldn't check them all? I'm concerned I may have missed a key point there
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/ef72f9e9904f887122072f787391c7a09573dd3f/receiver/mongodbreceiver/scraper.go#L243-L251
@justinianvoss22 Could you please elaborate on why we shouldn't check them all? I'm concerned I may have missed a key point there
https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/ef72f9e9904f887122072f787391c7a09573dd3f/receiver/mongodbreceiver/scraper.go#L243-L251
Sorry if I wasn't clear, I am agreeing with you, we should check them all. I was giving a few examples when looking around.
This PR was marked stale due to lack of activity. It will be closed in 14 days.
Hi, @odorT! Been waiting for a response from you, but to follow up again, the changes you are making are reasonable, and it would make sense to do these checks for recordDBStats and recordNormalServerStats as well. For example, the starting at the top of recordNormalServerStats:
if s.config.Metrics.MongodbCollectionCount.Enabled {
s.recordCollections(now, doc, dbName, errs)
}
if s.config.Metrics.MongodbDataSize.Enabled {
s.recordDataSize(now, doc, dbName, errs)
}
...
Sorry, this slipped my mind. I’ll make the changes and send the commit over the weekend.
@justinianvoss22 please have a look when you get a chance
@odor Pinging just to remind to update the unit tests for scraper_test.go, as per my comment above
Hi @justinianvoss22 , I apologize for the slow response. I've been dealing with some work and personal commitments, but I'll have time to address this after(or during) the holidays
Hi @justinianvoss22 , I apologize for the slow response. I've been dealing with some work and personal commitments, but I'll have time to address this after(or during) the holidays
No worries at all! Sounds good 👍