Commit ddcb6051 authored by Piotr Szczesniak's avatar Piotr Szczesniak

Fixed panic in GCM data source implementation in Initial Resources

The panic occured when there was no historical data to make prediction
parent 1a641027
...@@ -122,6 +122,9 @@ func (s *gcmSource) GetUsagePercentile(kind api.ResourceName, perc int64, image, ...@@ -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]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment