Fixed panic in GCM data source implementation in Initial Resources

The panic occured when there was no historical data to make prediction
This commit is contained in:
Piotr Szczesniak
2015-10-05 16:07:16 +02:00
parent 1a641027d2
commit ddcb605109

View File

@@ -122,6 +122,9 @@ func (s *gcmSource) GetUsagePercentile(kind api.ResourceName, perc int64, image,
} }
count := len(rawSamples) count := len(rawSamples)
if count == 0 {
return 0, 0, nil
}
sort.Ints(rawSamples) sort.Ints(rawSamples)
usageIndex := int64(math.Ceil(float64(count)*9/10)) - 1 usageIndex := int64(math.Ceil(float64(count)*9/10)) - 1
usage := rawSamples[usageIndex] usage := rawSamples[usageIndex]