Fix mongodb_connections metric for mongos instances
The getDiagnosticData command returns empty data for mongos, causing connection metrics to be missing. This adds a fallback to serverStatus when getDiagnosticData returns empty data for mongos instances.
This ensures that mongodb_connections (and mongodb_ss_connections) metrics are properly exposed for mongos routers, maintaining compatibility with monitoring dashboards and alerting rules.
May fix https://github.com/percona/mongodb_exporter/issues/916
Codecov Report
:x: Patch coverage is 53.84615% with 6 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 68.72%. Comparing base (dc46ed5) to head (697ffeb).
:warning: Report is 167 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| exporter/diagnostic_data_collector.go | 53.84% | 2 Missing and 4 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #1151 +/- ##
==========================================
- Coverage 70.88% 68.72% -2.16%
==========================================
Files 28 29 +1
Lines 3569 2440 -1129
==========================================
- Hits 2530 1677 -853
+ Misses 904 589 -315
- Partials 135 174 +39
| Flag | Coverage Δ | |
|---|---|---|
| agent | 68.72% <53.84%> (-2.16%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Thanks a lot for your contribution @vtomasr5 .
If you're still up, can we add some tests for mongos instances? Maybe something similar to TestAllDiagnosticDataCollectorMetrics but connected to the mongos instance instead - only checking for mongodb_ss_connections_* is fine.
Additionally, you can sync this branch with current main and it should fix the duplicate metrics errors in CI.
Hi @vtomasr5, could you address the three lints mentioned there https://github.com/percona/mongodb_exporter/pull/1151/files#diff-442864aca9e35e7752c01f444b178deb5f245bb3af68683dbacfdf3f86a618a8?