From 0793a26d96b56ea3110994d763da8c7f0678062a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Tue, 11 Jun 2024 11:08:25 +0200 Subject: [PATCH 1/3] native histograms: only reduce resolution for exponential histograms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently we can only reduce the resolution of exponential native histograms, so checking the schema for that is slightly more precise than checking against max schema. Signed-off-by: György Krajcsovits --- scrape/target.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scrape/target.go b/scrape/target.go index 3afe500a9d..cbc39b38e5 100644 --- a/scrape/target.go +++ b/scrape/target.go @@ -365,7 +365,7 @@ 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 && h.Schema > histogram.ExponentialSchemaMax { + if len(h.PositiveBuckets)+len(h.NegativeBuckets) > app.limit && !histogram.IsExponentialSchema(h.Schema) { return 0, errBucketLimit } for len(h.PositiveBuckets)+len(h.NegativeBuckets) > app.limit { @@ -376,7 +376,7 @@ func (app *bucketLimitAppender) AppendHistogram(ref storage.SeriesRef, lset labe } } if fh != nil { - if len(fh.PositiveBuckets)+len(fh.NegativeBuckets) > app.limit && fh.Schema > histogram.ExponentialSchemaMax { + if len(fh.PositiveBuckets)+len(fh.NegativeBuckets) > app.limit && !histogram.IsExponentialSchema(fh.Schema) { return 0, errBucketLimit } for len(fh.PositiveBuckets)+len(fh.NegativeBuckets) > app.limit { From c309f50ee7a00c102cb5009dc9d8761b1a49b0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Tue, 18 Jun 2024 15:21:17 +0200 Subject: [PATCH 2/3] Add comment to state intent of check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: György Krajcsovits --- scrape/target.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scrape/target.go b/scrape/target.go index cbc39b38e5..ebe86c156b 100644 --- a/scrape/target.go +++ b/scrape/target.go @@ -365,6 +365,8 @@ 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 { + // Return with an early error if the histogram has too many buckets and the + // schema is not exponential, in which case we can't reduce the resolution. if len(h.PositiveBuckets)+len(h.NegativeBuckets) > app.limit && !histogram.IsExponentialSchema(h.Schema) { return 0, errBucketLimit } From 79020b1e8565de3578825ca756c4e0b9aea3c7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Tue, 18 Jun 2024 15:22:03 +0200 Subject: [PATCH 3/3] Comment float histogram as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: György Krajcsovits --- scrape/target.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scrape/target.go b/scrape/target.go index ebe86c156b..9ef4471fbd 100644 --- a/scrape/target.go +++ b/scrape/target.go @@ -378,6 +378,8 @@ func (app *bucketLimitAppender) AppendHistogram(ref storage.SeriesRef, lset labe } } if fh != nil { + // Return with an early error if the histogram has too many buckets and the + // schema is not exponential, in which case we can't reduce the resolution. if len(fh.PositiveBuckets)+len(fh.NegativeBuckets) > app.limit && !histogram.IsExponentialSchema(fh.Schema) { return 0, errBucketLimit }