Fix div by 0 panic is resize function. (#9286)
Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
parent
2a5dde2f87
commit
93886d8417
|
@ -279,7 +279,7 @@ func (ce *CircularExemplarStorage) Resize(l int64) int {
|
||||||
|
|
||||||
migrated := 0
|
migrated := 0
|
||||||
|
|
||||||
if l > 0 {
|
if l > 0 && len(oldBuffer) > 0 {
|
||||||
// Rewind previous next index by count with wrap-around.
|
// Rewind previous next index by count with wrap-around.
|
||||||
// This math is essentially looking at nextIndex, where we would write the next exemplar to,
|
// 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.
|
// 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,
|
expectedMigrated: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Zero",
|
name: "ShrinkToZero",
|
||||||
startSize: 100,
|
startSize: 100,
|
||||||
newCount: 0,
|
newCount: 0,
|
||||||
expectedSeries: []int{},
|
expectedSeries: []int{},
|
||||||
|
@ -436,6 +436,14 @@ func TestResize(t *testing.T) {
|
||||||
notExpectedSeries: []int{},
|
notExpectedSeries: []int{},
|
||||||
expectedMigrated: 0,
|
expectedMigrated: 0,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "GrowFromZero",
|
||||||
|
startSize: 0,
|
||||||
|
newCount: 10,
|
||||||
|
expectedSeries: []int{},
|
||||||
|
notExpectedSeries: []int{},
|
||||||
|
expectedMigrated: 0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
Loading…
Reference in New Issue