Repository navigation
metricbeat/module/mongodb/collstats: add $collStats aggregation support with fallback - #48638
Conversation
…back and sharded merge
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
This comment has been minimized.
This comment has been minimized.
Use NotEmpty for empty-string checks and InDelta for float assertions so the collstats test suite passes the current lint configuration.
…ate-collstats-mongo
…move incorrect breaking-change notes - Fix mongoVersion caching bug: failures are no longer cached as "unknown"; the next Fetch retries version detection, so transient errors (MongoDB not yet ready) and live server upgrades are handled automatically. - Fix isVersionAtLeast for major-only version strings (e.g. "6"): missing minor/patch parts are now treated as 0 instead of causing an early loop exit that incorrectly returned true. - Guard against empty version string returned by versionGetter with no error. - Extract cacheMongoVersion as a testable method; inject versionGetter via Metricset field for unit testing without a real MongoDB connection. - Add unit tests: retry-on-error, empty-string-not-cached, permanent-failure-uses-legacy-path, major-only and major.minor version boundary cases for isVersionAtLeast. - Extend standalone integration tests to cover MongoDB 4.4, 6.0, and 8.0 in addition to 5.0 and 7.0, straddling the 6.2.0 aggregation boundary. - Fix standalone docker-compose healthcheck to support MongoDB 4.4 which ships only the old mongo shell (mongosh || mongo fallback). - Remove incorrect "In versions before 9.2.0" backward-compat notes from fields.yml and exported-fields-mongodb.md: git history confirms the field paths (mongodb.collstats.stats.*) were never changed by this PR; the stats.stats.* double-nesting never existed in production. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Analysis: How the incorrect
|
TL;DR
Remediation
Investigation detailsRoot CauseThis is a configuration/generated-artifacts drift failure: CI ran the update/check pipeline and detected uncommitted generated changes. The failing step explicitly reports generated drift in:
That confirms at least one failing file is generated output and must be refreshed/committed with source changes. Evidence
Verification
Follow-upIf the files were already committed in a newer push, retrying the Buildkite pipeline should pass this step. Note 🔒 Integrity filter blocked 2 itemsThe following items were blocked because they don't meet the GitHub integrity level.
To allow these resources, lower tools:
github:
min-integrity: approved # merged | approved | unapproved | noneWhat is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
…sset - Fix goimports struct-field comment alignment in collstats.go - Replace assert.Equal(t, "", ...) with assert.Empty(t, ...) per testifylint - Regenerate metricbeat/module/mongodb/fields.go after fields.yml cleanup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rious shardCount on standalone
Two bugs surfaced while exercising the metricset against live MongoDB
across the 6.2 deprecation boundary (standalone 4.4-8.0 and sharded
5.0/7.0):
1. scale broke the legacy collStats command path (MongoDB < 6.2).
fetchCollStatsCommand built the command as an unordered bson.M and,
when scale != 1, added a second key. The MongoDB driver requires the
command name to be the first BSON field and rejects multi-key
unordered maps ("multi-key map passed in for ordered parameter cmd"),
so every collection errored and zero events were emitted. Switch to
an ordered bson.D. The aggregation path (6.2+) was unaffected because
it already builds an ordered pipeline.
2. Standalone deployments on 6.2+ emitted a spurious stats.shardCount=1.
hasShardMetadata treated the top-level "host" field as a sharding
signal, but $collStats always emits "host" (the serving node), even
on standalone/replica set. This routed every standalone aggregation
result through the sharded-merge path. Key off "shard" only, so
standalone matches the legacy path while genuine sharded collections
still report their shard count.
Both gaps escaped CI because no test set a non-default scale and no
assertion checked shardCount on standalone. Add regression coverage:
a scaled fetch in TestFetchStandaloneVersions across the full version
matrix, a standalone "must not report shardCount" assertion, and an
updated TestHasShardMetadata case for the host-only result.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@jmikell821 could you please review and approve; thank you! |
|
@Mergifyio backport 9.4 9.3 8.19 |
✅ Backports have been createdDetails
Cherry-pick of e45acca has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
…lStats aggregation support with fallback (#51470)
Proposed commit message
Replaces the deprecated
collstatscommand with the recommendedaggregatepipeline using the$collStatsstage. Thecollstatscommand was deprecated in MongoDB 6.2, and this change ensures compatibility with current and future MongoDB versions while providing enhanced collection statistics. Now it transparently uses either the deprecatedcollStatsdatabase command (legacy) or the$collStatsaggregation stage (MongoDB 6.2+) depending on server version and feature availability to collect collection-level operational and storage statistics from MongoDB.The new approach provides additional metrics that were not available in the old command. A few of them have been enabled, while the rest are currently disabled, pending further development to add them when a need arises.
Implementation wise, these are the following things added:
buildInfocommand$collStatsaggregation with fallback to legacy commandcollStatscommand$collStatspipeline withstorageStatsandcountoptionsstorageStatsto maintain compatibility with existing event mappingReferences
Checklist
CHANGELOG.next.asciidocorCHANGELOG-developer.next.asciidoc.Testing
Comprehensive testing performed across the MongoDB 6.2 deprecation boundary:
✅ MongoDB 5.0 (Pre-deprecation)
✅ MongoDB 7.0 (Post-deprecation)
numOrphanDocscorrectly captured✅ Cross-version Validation
numOrphanDocsonly in 6.0+)Even scripts for future testing added — standalone, replica set and sharded setups. The same standalone setup is being used by the newly written integration tests that has tests against both 5.0 and 7.0.
Related issues