Merge pull request #2979 from prometheus/beorn7/storage2

Fix iterator issue in varbit chunk
This commit is contained in:
Björn Rabenstein 2017-07-21 19:38:23 +02:00 committed by GitHub
commit a5ddcf5fb2
2 changed files with 23 additions and 1 deletions

View file

@ -1040,7 +1040,7 @@ func (it *varbitChunkIterator) FindAtOrBefore(t model.Time) bool {
prevT = model.Earliest
prevV model.SampleValue
)
for it.Scan() && t.After(it.t) {
for it.Scan() && !t.Before(it.t) {
prevT = it.t
prevV = it.v
// TODO(beorn7): If we are in a repeat, we could iterate forward

View file

@ -980,6 +980,28 @@ func testValueAtOrBeforeTime(t *testing.T, encoding chunk.Encoding) {
if expected.Value != actual.Value {
t.Errorf("3.2. Got %v; want %v", actual.Value, expected.Value)
}
// #4 Query alternatingly exactly on and just between timestamps.
// Exposes issue #2965.
for i, expected := range samples {
i *= 2
actual := it.ValueAtOrBeforeTime(expected.Timestamp)
if expected.Timestamp != actual.Timestamp {
t.Errorf("4.%d. Got %v; want %v", i, actual.Timestamp, expected.Timestamp)
}
if expected.Value != actual.Value {
t.Errorf("4.%d. Got %v; want %v", i, actual.Value, expected.Value)
}
i++
actual = it.ValueAtOrBeforeTime(expected.Timestamp + 1)
if expected.Timestamp != actual.Timestamp {
t.Errorf("4.%d. Got %v; want %v", i, actual.Timestamp, expected.Timestamp)
}
if expected.Value != actual.Value {
t.Errorf("4.%d. Got %v; want %v", i, actual.Value, expected.Value)
}
}
}
func TestValueAtTimeChunkType0(t *testing.T) {