From b94f32f6fa3b619498dd6e1dec9677ab9d30e7de Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Sat, 11 Nov 2023 22:24:47 +0800 Subject: [PATCH] automatically reduce resolution rather than fail scrape Signed-off-by: Ziqi Zhao --- scrape/target.go | 16 ++++++++++++---- scrape/target_test.go | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scrape/target.go b/scrape/target.go index 8cc8597a4..ed4c598b7 100644 --- a/scrape/target.go +++ b/scrape/target.go @@ -366,13 +366,21 @@ type bucketLimitAppender struct { func (app *bucketLimitAppender) AppendHistogram(ref storage.SeriesRef, lset labels.Labels, t int64, h *histogram.Histogram, fh *histogram.FloatHistogram) (storage.SeriesRef, error) { if h != nil { - if len(h.PositiveBuckets)+len(h.NegativeBuckets) > app.limit { - return 0, errBucketLimit + for len(h.PositiveBuckets)+len(h.NegativeBuckets) > app.limit { + lastSum := len(h.PositiveBuckets) + len(h.NegativeBuckets) + h = h.ReduceResolution(h.Schema - 1) + if len(h.PositiveBuckets)+len(h.NegativeBuckets) == lastSum { + return 0, errBucketLimit + } } } if fh != nil { - if len(fh.PositiveBuckets)+len(fh.NegativeBuckets) > app.limit { - return 0, errBucketLimit + for len(fh.PositiveBuckets)+len(fh.NegativeBuckets) > app.limit { + lastSum := len(fh.PositiveBuckets) + len(fh.NegativeBuckets) + fh = fh.ReduceResolution(fh.Schema - 1) + if len(fh.PositiveBuckets)+len(fh.NegativeBuckets) == lastSum { + return 0, errBucketLimit + } } } ref, err := app.Appender.AppendHistogram(ref, lset, t, h, fh) diff --git a/scrape/target_test.go b/scrape/target_test.go index 4f0c840cd..f676b85c0 100644 --- a/scrape/target_test.go +++ b/scrape/target_test.go @@ -517,6 +517,11 @@ func TestBucketLimitAppender(t *testing.T) { limit: 3, expectError: true, }, + { + h: example, + limit: 4, + expectError: false, + }, { h: example, limit: 10,