Skip to content

storage: remove compaction_ratio metric from probe#29994

Merged
WillemKauf merged 1 commit intoredpanda-data:devfrom
WillemKauf:compaction_ratio_metric_agg
Apr 7, 2026
Merged

storage: remove compaction_ratio metric from probe#29994
WillemKauf merged 1 commit intoredpanda-data:devfrom
WillemKauf:compaction_ratio_metric_agg

Conversation

@WillemKauf
Copy link
Copy Markdown
Contributor

@WillemKauf WillemKauf commented Mar 30, 2026

The cardinality of this metric is much too high, and its usefulness doesnot justify the cost. Aggregating it would also reduce its usefulness.

We have plenty of log lines from which one could infer the "compactibility" of a segment/log/topic.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v26.1.x
  • v25.3.x
  • v25.2.x

Release Notes

  • none

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Reduces /metrics cardinality for storage compaction ratio by making the metric eligible for label aggregation across partitions (topic-level rollup) rather than emitting a distinct time series per partition.

Changes:

  • Removed the non-aggregated compaction_ratio metric registration.
  • Added a new aggregated metric compaction_ratio_total with updated help text describing topic-level aggregation.

Comment thread src/v/storage/probe.cc Outdated
Comment thread src/v/storage/probe.cc Outdated
Comment thread src/v/storage/probe.cc
@WillemKauf WillemKauf force-pushed the compaction_ratio_metric_agg branch from 0d04d47 to cf61deb Compare March 30, 2026 19:42
Copy link
Copy Markdown
Member

@StephanDollberg StephanDollberg left a comment

Choose a reason for hiding this comment

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

Does it make more sense to calculate a ratio more directly at the topic level instead of doing the average of averages approach (weighted by bytes or something)?

@WillemKauf
Copy link
Copy Markdown
Contributor Author

Does it make more sense to calculate a ratio more directly at the topic level instead of doing the average of averages approach (weighted by bytes or something)?

to be honest this metric is already fairly approximate given its sliding window nature and the fact it has a sample size of 5 segments/operations. i don't believe it is a good indicator of "compactibility" and doing the low effort thing here probably isn't a huge deal.

wdyt @dotnwat ?

@vbotbuildovich
Copy link
Copy Markdown
Collaborator

CI test results

test results on build#82498
test_class test_method test_arguments test_kind job_url test_status passed reason test_history
RedpandaNodeOperationsSmokeTest test_node_ops_smoke_test {"cloud_storage_type": 1, "mixed_versions": false} integration https://buildkite.com/redpanda/redpanda/builds/82498#019d4052-e5f7-4866-aa5e-e66447800099 FLAKY 10/11 Test PASSES after retries.No significant increase in flaky rate(baseline=0.0000, p0=1.0000, reject_threshold=0.0100. adj_baseline=0.1000, p1=0.3487, trust_threshold=0.5000) https://redpanda.metabaseapp.com/dashboard/87-tests?tab=142-dt-individual-test-history&test_class=RedpandaNodeOperationsSmokeTest&test_method=test_node_ops_smoke_test
WriteCachingFailureInjectionE2ETest test_crash_all {"use_transactions": false} integration https://buildkite.com/redpanda/redpanda/builds/82498#019d4052-d9f8-49ca-9df6-fef61d0aabd6 FLAKY 18/21 Test PASSES after retries.No significant increase in flaky rate(baseline=0.0825, p0=0.5002, reject_threshold=0.0100. adj_baseline=0.2278, p1=0.1333, trust_threshold=0.5000) https://redpanda.metabaseapp.com/dashboard/87-tests?tab=142-dt-individual-test-history&test_class=WriteCachingFailureInjectionE2ETest&test_method=test_crash_all

@WillemKauf WillemKauf requested a review from andrwng April 1, 2026 18:30
Comment thread src/v/storage/probe.cc Outdated
Comment on lines +261 to +265
sm::description(
"Sum of compaction ratios across segments in this partition. "
"When aggregate_metrics is enabled, this is summed across all "
"partitions in a topic; divide by the partition count to get "
"the average compaction ratio."),
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.

I'm fine with this change, but just looking at how it's used (moving average of ratio computed with every segment rewrite), I'm wondering how useful it is in practice as is today (even without this aggregation).

If we're already going to need callers to do some math with this division, maybe we should instead expose some bytes_rewritten_in and bytes_rewritten_out and aggregate that, so that the collective compaction ratio is always bytes out / bytes in, whether aggregated or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm wondering how useful it is in practice as is today

I don't think its all that useful. I was leaning towards fully removing it.

If we're already going to need callers to do some math with this division, maybe we should instead expose some bytes_rewritten_in and bytes_rewritten_out and aggregate that, so that the collective compaction ratio is always bytes out / bytes in, whether aggregated or not.

I'd prefer this change as well but it would require some additional state/book-keeping in disk_log_impl, and I wasn't sure that juice was worth the squeeze.

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.

+1 to removing it

additional state/book-keeping

FWIW the compaction_result (where we compute the compaction ratio today) seems to already have size_before and size_after. Presumably if we could just add these to a counter, or am I missing something?

Copy link
Copy Markdown
Contributor

@andrwng andrwng Apr 1, 2026

Choose a reason for hiding this comment

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

Ah i guess the issue is that we'd kind of want a rolling average of both of the counters in order to make sense of them over longer spans of time, though maybe for monitoring, even if we didn't have the rolling average we could do something like rate(size_before) / rate(size_after)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently the compaction_ratio is represented as a moving_average with 5 samples in the disk_log_impl, so the book-keeping isn't just two size_ts or something like that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(race)

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.

Right, edited my message with another thought (using rates). If we do that, I don't think a moving average is necessary. Though I'm also not confident enough in my grafana fu to know that what i'm suggesting gets us something useful

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm leaning towards outright removing the metric and the moving average itself from disk_log_impl now. @dotnwat do you have any objections to this?

Copy link
Copy Markdown
Member

@dotnwat dotnwat Apr 2, 2026

Choose a reason for hiding this comment

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

I'll defer to your best judgement on if you think it's useful or not. Compaction ratio seems useful on the surface in that it tells us something about the data, but I think we lose that usefulness if we aggregate. So if the choice is between aggregate or drop it, dropping it is probably the right move.

However, if we kind of like knowing that it is there, we could expose it through the admin interface (for later inclusion in debug bundle), or we could log a summary of compation work (including ratio) after a compaction run at debug or trace level?

Although, maybe debug/trace also isn't useful in practice depending on when you'd want to know the compaction ratio 🤷

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

or we could log a summary of compation work (including ratio) after a compaction run at debug or trace level?

we log some interesting compaction info at INFO level which (per segment) notes the number of batches processed, number of records discarded, etc. It's not a complete summary of the entire compaction run (which would likely be missed for long running compactions if logged at TRACE or DEBUG anyways) but it is pretty good information from which the compaction ratio can be extrapolated.

The cardinality of this metric is much too high, and its usefulness does
not justify the cost. Aggregating it would also reduce its usefulness.

We have plenty of log lines from which one could infer the "compactibility"
of a `segment`/`log`/`topic`.
@WillemKauf WillemKauf force-pushed the compaction_ratio_metric_agg branch from cf61deb to 88fa106 Compare April 3, 2026 02:54
@WillemKauf WillemKauf changed the title storage: aggregate compaction_ratio metric across partitions storage: remove compaction_ratio metric from probe Apr 3, 2026
@WillemKauf
Copy link
Copy Markdown
Contributor Author

Force push to:

  • Outright remove the metric from the storage::probe.

@WillemKauf WillemKauf requested a review from andrwng April 3, 2026 02:55
@WillemKauf WillemKauf merged commit 6af2630 into redpanda-data:dev Apr 7, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants