mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 22:37:27 -08:00
Add bounds check to headBlockAppender
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
parent
c1939b7136
commit
8096d11e4e
4
head.go
4
head.go
|
@ -296,6 +296,10 @@ type refdSample struct {
|
|||
}
|
||||
|
||||
func (a *headAppender) Add(lset labels.Labels, t int64, v float64) (uint64, error) {
|
||||
if !a.inBounds(t) {
|
||||
return 0, ErrOutOfBounds
|
||||
}
|
||||
|
||||
hash := lset.Hash()
|
||||
|
||||
if ms := a.get(hash, lset); ms != nil {
|
||||
|
|
14
head_test.go
14
head_test.go
|
@ -168,6 +168,8 @@ func TestHeadBlock_e2e(t *testing.T) {
|
|||
numDatapoints := 1000
|
||||
numRanges := 1000
|
||||
timeInterval := int64(3)
|
||||
maxTime := int64(2 * 1000)
|
||||
minTime := int64(200)
|
||||
// Create 8 series with 1000 data-points of different ranges and run queries.
|
||||
lbls := [][]labels.Label{
|
||||
{
|
||||
|
@ -220,7 +222,7 @@ func TestHeadBlock_e2e(t *testing.T) {
|
|||
tmpdir, _ := ioutil.TempDir("", "test")
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
hb, err := createHeadBlock(tmpdir+"/hb", 0, nil, 0, 1000)
|
||||
hb, err := createHeadBlock(tmpdir+"/hb", 0, nil, minTime, maxTime)
|
||||
require.NoError(t, err)
|
||||
app := hb.Appender()
|
||||
|
||||
|
@ -231,10 +233,16 @@ func TestHeadBlock_e2e(t *testing.T) {
|
|||
ts := rand.Int63n(300)
|
||||
for i := 0; i < numDatapoints; i++ {
|
||||
v := rand.Float64()
|
||||
series = append(series, sample{ts, v})
|
||||
if ts >= minTime && ts <= maxTime {
|
||||
series = append(series, sample{ts, v})
|
||||
}
|
||||
|
||||
_, err := app.Add(ls, ts, v)
|
||||
require.NoError(t, err)
|
||||
if ts >= minTime && ts <= maxTime {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.Error(t, ErrOutOfBounds, err)
|
||||
}
|
||||
|
||||
ts += rand.Int63n(timeInterval) + 1
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue