automatically reduce resolution rather than fail scrape

Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
This commit is contained in:
Ziqi Zhao 2023-11-11 22:24:47 +08:00
parent e250f09b5d
commit b94f32f6fa
2 changed files with 17 additions and 4 deletions

View file

@ -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)

View file

@ -517,6 +517,11 @@ func TestBucketLimitAppender(t *testing.T) {
limit: 3,
expectError: true,
},
{
h: example,
limit: 4,
expectError: false,
},
{
h: example,
limit: 10,