Fix div by 0 panic is resize function. (#9286)

Signed-off-by: Callum Styan <callumstyan@gmail.com>
pull/9295/head
Callum Styan 4 years ago committed by GitHub
parent 2a5dde2f87
commit 93886d8417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      tsdb/exemplar.go
  2. 10
      tsdb/exemplar_test.go

@ -279,7 +279,7 @@ func (ce *CircularExemplarStorage) Resize(l int64) int {
migrated := 0
if l > 0 {
if l > 0 && len(oldBuffer) > 0 {
// Rewind previous next index by count with wrap-around.
// This math is essentially looking at nextIndex, where we would write the next exemplar to,
// and find the index in the old exemplar buffer that we should start migrating exemplars from.

@ -413,7 +413,7 @@ func TestResize(t *testing.T) {
expectedMigrated: 50,
},
{
name: "Zero",
name: "ShrinkToZero",
startSize: 100,
newCount: 0,
expectedSeries: []int{},
@ -436,6 +436,14 @@ func TestResize(t *testing.T) {
notExpectedSeries: []int{},
expectedMigrated: 0,
},
{
name: "GrowFromZero",
startSize: 0,
newCount: 10,
expectedSeries: []int{},
notExpectedSeries: []int{},
expectedMigrated: 0,
},
}
for _, tc := range testCases {

Loading…
Cancel
Save