Add bounds check to headBlockAppender

Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
Goutham Veeramachaneni 2017-05-05 19:52:11 +05:30
parent c1939b7136
commit 8096d11e4e
No known key found for this signature in database
GPG key ID: F1C217E8E9023CAD
2 changed files with 15 additions and 3 deletions

View file

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

View file

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