Skip to content

compact/downsample: support native histogram custom buckets downsampling#8706

Open
Br1an67 wants to merge 3 commits intothanos-io:mainfrom
Br1an67:fix/issue-8698-custom-buckets-downsample
Open

compact/downsample: support native histogram custom buckets downsampling#8706
Br1an67 wants to merge 3 commits intothanos-io:mainfrom
Br1an67:fix/issue-8698-custom-buckets-downsample

Conversation

@Br1an67
Copy link
Copy Markdown

@Br1an67 Br1an67 commented Mar 8, 2026

Fixes #8698

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

  • Modified minSchema function to skip custom bucket schemas (schema < 0) when finding the minimum schema for downsampling. Custom bucket histograms cannot be reduced in resolution using CopyToSchema.
  • Updated histogramAggregator.add method to skip the schema reduction step for custom bucket histograms (schema < 0), allowing them to be used as-is during downsampling.

Verification

The fix addresses the panic cannot reduce resolution to custom buckets schema that occurred when the compactor tried to downsample native histograms with custom buckets. The changes ensure that:

  1. Custom bucket schemas (negative schema values) are excluded from the minimum schema calculation
  2. When processing custom bucket histograms during downsampling, the CopyToSchema call is skipped since it doesn't support custom bucket schemas
$ git diff --stat HEAD~1
 pkg/compact/downsample/downsample.go | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Custom bucket histograms (schema < 0) cannot be reduced in resolution
using CopyToSchema. Skip schema reduction for custom buckets and use
them as-is during downsampling to prevent panic.

Signed-off-by: root <root@C20251020184286.local>
Signed-off-by: Br1an67 <932039080@qq.com>
@Br1an67 Br1an67 force-pushed the fix/issue-8698-custom-buckets-downsample branch from 866aa3d to 1d42c23 Compare March 8, 2026 10:11
Br1an67 added 2 commits March 8, 2026 10:19
Custom bucket histograms (schema < 0) cannot be subtracted using the
Sub operation. When downsampling custom bucket histograms, treat them
like counter resets and add the full value to the counter instead of
computing a delta. This prevents panics when processing custom bucket
histograms during downsampling.

Fixes panic in histogramAggregator.add() when trying to subtract
custom bucket histograms.

Signed-off-by: Br1an67 <932039080@qq.com>
When downsampling histograms, if the schema type changes between
custom bucket histograms (schema < 0) and exponential bucket histograms
(schema >= 0), the Add operation would fail because these histogram
types cannot be added together.

This fix checks for incompatible schemas before attempting to add
histograms. When incompatible schemas are detected, the aggregation
is reset to the new histogram, similar to how counter resets are handled.

Fixes panic when mixing custom bucket and exponential bucket histograms
during downsampling.

Signed-off-by: Br1an67 <932039080@qq.com>
@pull-request-size pull-request-size Bot added size/M and removed size/S labels Mar 8, 2026
Copy link
Copy Markdown
Member

@GiedriusS GiedriusS left a comment

Choose a reason for hiding this comment

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

What's the difference between https://github.com/thanos-io/thanos/pull/8699/changes and this? Maybe you could collaborate? Could you add a test case?

@Br1an67 Br1an67 force-pushed the fix/issue-8698-custom-buckets-downsample branch from 1fe5228 to 35a41c4 Compare March 18, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compact: implement native histogram custom buckets downsampling

2 participants