|
|
@ -508,9 +508,11 @@ func TestBucketLimitAppender(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cases := []struct { |
|
|
|
cases := []struct { |
|
|
|
h histogram.Histogram |
|
|
|
h histogram.Histogram |
|
|
|
limit int |
|
|
|
limit int |
|
|
|
expectError bool |
|
|
|
expectError bool |
|
|
|
|
|
|
|
expectBucketCount int |
|
|
|
|
|
|
|
expectSchema int32 |
|
|
|
}{ |
|
|
|
}{ |
|
|
|
{ |
|
|
|
{ |
|
|
|
h: example, |
|
|
|
h: example, |
|
|
@ -518,14 +520,18 @@ func TestBucketLimitAppender(t *testing.T) { |
|
|
|
expectError: true, |
|
|
|
expectError: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
h: example, |
|
|
|
h: example, |
|
|
|
limit: 4, |
|
|
|
limit: 4, |
|
|
|
expectError: false, |
|
|
|
expectError: false, |
|
|
|
|
|
|
|
expectBucketCount: 4, |
|
|
|
|
|
|
|
expectSchema: -1, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
h: example, |
|
|
|
h: example, |
|
|
|
limit: 10, |
|
|
|
limit: 10, |
|
|
|
expectError: false, |
|
|
|
expectError: false, |
|
|
|
|
|
|
|
expectBucketCount: 6, |
|
|
|
|
|
|
|
expectSchema: 0, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -536,18 +542,28 @@ func TestBucketLimitAppender(t *testing.T) { |
|
|
|
t.Run(fmt.Sprintf("floatHistogram=%t", floatHisto), func(t *testing.T) { |
|
|
|
t.Run(fmt.Sprintf("floatHistogram=%t", floatHisto), func(t *testing.T) { |
|
|
|
app := &bucketLimitAppender{Appender: resApp, limit: c.limit} |
|
|
|
app := &bucketLimitAppender{Appender: resApp, limit: c.limit} |
|
|
|
ts := int64(10 * time.Minute / time.Millisecond) |
|
|
|
ts := int64(10 * time.Minute / time.Millisecond) |
|
|
|
h := c.h |
|
|
|
|
|
|
|
lbls := labels.FromStrings("__name__", "sparse_histogram_series") |
|
|
|
lbls := labels.FromStrings("__name__", "sparse_histogram_series") |
|
|
|
var err error |
|
|
|
var err error |
|
|
|
if floatHisto { |
|
|
|
if floatHisto { |
|
|
|
_, err = app.AppendHistogram(0, lbls, ts, nil, h.Copy().ToFloat()) |
|
|
|
fh := c.h.Copy().ToFloat() |
|
|
|
} else { |
|
|
|
_, err = app.AppendHistogram(0, lbls, ts, nil, fh) |
|
|
|
_, err = app.AppendHistogram(0, lbls, ts, h.Copy(), nil) |
|
|
|
if c.expectError { |
|
|
|
} |
|
|
|
require.Error(t, err) |
|
|
|
if c.expectError { |
|
|
|
} else { |
|
|
|
require.Error(t, err) |
|
|
|
require.Equal(t, c.expectSchema, fh.Schema) |
|
|
|
|
|
|
|
require.Equal(t, c.expectBucketCount, len(fh.NegativeBuckets)+len(fh.PositiveBuckets)) |
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
require.NoError(t, err) |
|
|
|
h := c.h.Copy() |
|
|
|
|
|
|
|
_, err = app.AppendHistogram(0, lbls, ts, h, nil) |
|
|
|
|
|
|
|
if c.expectError { |
|
|
|
|
|
|
|
require.Error(t, err) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
require.Equal(t, c.expectSchema, h.Schema) |
|
|
|
|
|
|
|
require.Equal(t, c.expectBucketCount, len(h.NegativeBuckets)+len(h.PositiveBuckets)) |
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
require.NoError(t, app.Commit()) |
|
|
|
require.NoError(t, app.Commit()) |
|
|
|
}) |
|
|
|
}) |
|
|
|