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

Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
Callum Styan 2021-09-02 11:08:05 -07:00 committed by GitHub
parent 2a5dde2f87
commit 93886d8417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

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

View File

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