Skip to content

feat(mongodb): alert when compaction is needed#2433

Open
delthas wants to merge 2 commits into
development/2.15from
improvement/ZENKO-5293/mongodb-compaction-needed-alert
Open

feat(mongodb): alert when compaction is needed#2433
delthas wants to merge 2 commits into
development/2.15from
improvement/ZENKO-5293/mongodb-compaction-needed-alert

Conversation

@delthas

@delthas delthas commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Follow-up to ZENKO-5285 (PR #2431), which bundled two alerts in its description and only shipped the first (createIndexes-failed). This adds the second — a fragmentation / compaction-needed signal — that @DarkIsDude explicitly asked be filed as a follow-up.

Two commits, deliberately split

  1. mongodb: enable dbstatsfreestorage collector in exporter — one-line values.yaml change adding --collector.dbstatsfreestorage to metrics.extraArgs. The chart's exporter no longer uses --collect-all (dropped in 8414833 for ZENKO-5281), so each sub-collector is opted into individually in extraArgs (already lists dbstats, diagnosticdata, replicasetstatus, topmetrics). Without dbstatsfreestorage, freeStorageSize / totalFreeStorageSize only appear as part of the clunky per-host mongodb_dbstats_raw_<host>_* expansion instead of as top-level mongodb_dbstats_* series.

  2. mongodb: alert when compaction is needed — the alert proper.

The alert

mongodb_dbstats_totalFreeStorageSize > 0.3 * mongodb_dbstats_fsTotalSize
for: 1h

Per-(pod, database) granularity. Severity warning. Threshold exposed as the compactionFreeStorageRatioThreshold x-input (default 0.3).

Expressing the threshold as a fraction of filesystem capacity (not of the DB's own storage) lets it scale across cluster sizes:

  • 100 GB FS → fires around 30 GB reclaimable
  • 1 TB FS → fires around 300 GB reclaimable
  • 10 TB FS → fires around 3 TB reclaimable

Heuristic notes

A previous draft combined three legs (FS-pressure + fragmentation ratio + absolute floor). @francoisferrand's review pointed out that the fragmentation-ratio leg added noise without much signal and the FS-pressure leg could mask real waste on under-used disks. The single fs-scaled threshold above folds both concerns into one condition.

Per-DB granularity means the alert tells you pod={{ "{{ $labels.pod }}" }} and database={{ "{{ $labels.database }}" }} but does not identify the specific collection. To find that, an operator runs collStats on the alerting DB. The exporter has a --collector.collstats flag that could expose per-collection visibility, but at Artesca-scale cardinality (thousands of buckets per DB) that's expensive — deferred.

Safety against missing / zero values

  • Missing metric for a (pod, database) tuple → PromQL produces empty → no alert.
  • totalFreeStorageSize = 0 (no fragmentation) → 0 > 0.3 * fsTotalSize is always false.
  • fsTotalSize = 0 would degenerate (0.3 * 0 = 0, then any positive freeStorage would fire), but it's physically impossible for an attached PVC.

Follow-up (not in this PR)

Matching compactionFreeStorageRatioThreshold config option in ZKOP, to expose the knob to ops. Not filed as a ticket yet; will track when this lands.

Related

Issue: ZENKO-5293

@bert-e

bert-e commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Hello delthas,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval
/bypass_build_status Bypass the build and test status
/bypass_commit_size Bypass the check on the size of the changeset TBA
/bypass_incompatible_branch Bypass the check on the source branch prefix
/bypass_jira_check Bypass the Jira issue check
/bypass_peer_approval Bypass the pull request peers' approval
/bypass_leader_approval Bypass the pull request leaders' approval
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request TBA
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

@bert-e

bert-e commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

@delthas delthas force-pushed the improvement/ZENKO-5293/mongodb-compaction-needed-alert branch 3 times, most recently from 807646c to 146b0b5 Compare June 8, 2026 13:40
@delthas delthas marked this pull request as ready for review June 8, 2026 13:45
@delthas delthas requested review from a team, benzekrimaha and francoisferrand June 8, 2026 13:45
@delthas

delthas commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@francoisferrand Heuristics are up for discussion -- I chose a mix of:

  • Disk is being significantly used (to avoid saving 10GB on a disk that has 10TB free space)
  • There is a signficiant number of GBs to save (to avoid alarms on tiny collections)
  • There is a significant ratio of data to save (to avoid running compact just to save 10GB on a 10TB DB)

@francoisferrand francoisferrand left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • not sure about thresholds/computation: are these relevant default?
  • not sure we should merge in 2.15, or target 2.16 and get time to "preview" this and avoid shipping alerts which would lead to support calls...

Comment thread monitoring/mongodb/alerts.yaml Outdated
Comment thread monitoring/mongodb/alerts.yaml Outdated
Add --collector.dbstatsfreestorage to mongodb_exporter's extraArgs so
the dbstats response's freeStorageSize / indexFreeStorageSize /
totalFreeStorageSize fields are surfaced as top-level Prometheus series
(mongodb_dbstats_freeStorageSize{database, rs_nm, ...} etc.).

These sub-collectors are not bundled into the catch-all options the
exporter exposes (--collect-all and similar shortcuts); they have to be
opted into explicitly. Since the chart no longer uses --collect-all
anyway (dropped in 8414833 for ZENKO-5281), each individual collector
we want has to be named in extraArgs — which is already how dbstats,
diagnosticdata, replicasetstatus, and topmetrics are wired up. This
just adds dbstatsfreestorage to that list.

Verified on a live Artesca cluster (exporter 0.40.0): without this flag
the freeStorageSize fields only appear as part of the per-host
mongodb_dbstats_raw_<host>_freeStorageSize series — clunky for alerting
queries. With the flag they appear cleanly as top-level series with
{database, rs_nm, ...} labels.

This unblocks the MongoDbCompactionNeeded alert added in the following
commit, which needs totalFreeStorageSize at top level to express the
compaction-pressure heuristic.

Issue: ZENKO-5293
@delthas delthas force-pushed the improvement/ZENKO-5293/mongodb-compaction-needed-alert branch from 146b0b5 to 2790943 Compare June 16, 2026 09:12
@delthas

delthas commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Keeping on 2.15 for now as 2.16 doesnt exist.

@scality scality deleted a comment from bert-e Jun 16, 2026
@bert-e

bert-e commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

The following reviewers are expecting changes from the author, or must review again:

@scality scality deleted a comment from bert-e Jun 16, 2026
@delthas delthas force-pushed the improvement/ZENKO-5293/mongodb-compaction-needed-alert branch from 2790943 to b8e0eda Compare June 16, 2026 09:33
@delthas delthas requested a review from francoisferrand June 16, 2026 09:34
@delthas

delthas commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Intentionally set 30% by default (conservative), up for discussion

@bert-e

bert-e commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

Comment thread monitoring/mongodb/alerts.yaml Outdated
Add MongoDbCompactionNeeded Prometheus rule that fires when a MongoDB
database has accumulated reclaimable storage exceeding 30% of the
underlying filesystem capacity:

  totalFreeStorageSize > 0.3 * fsTotalSize    for: 1h

Per-(pod, database) granularity, severity warning. The threshold is
exposed as the compactionFreeStorageRatioThreshold x-input. Expressing
it as a fraction of fsTotalSize lets it scale across cluster sizes: a
100 GB filesystem fires around 30 GB reclaimable; a 10 TB filesystem
fires around 3 TB.

Companion fixture covers a needs-compaction DB and a healthy DB sharing
the same filesystem (the first crosses the threshold, the second
doesn't).

Issue: ZENKO-5293
@delthas delthas force-pushed the improvement/ZENKO-5293/mongodb-compaction-needed-alert branch from b8e0eda to fe5f995 Compare June 17, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants