Browse Source

Merge pull request #120 from kubecost/AjayTripathy-handle-range-err

fix panic when no data found
Webb Brown 6 years ago
parent
commit
36808be50d
1 changed files with 3 additions and 0 deletions
  1. 3 0
      costmodel/cluster.go

+ 3 - 0
costmodel/cluster.go

@@ -53,6 +53,9 @@ func resultToTotals(qr interface{}) ([][]string, error) {
 	if !ok {
 	if !ok {
 		return nil, fmt.Errorf("Improperly formatted results from prometheus, result field is not a slice")
 		return nil, fmt.Errorf("Improperly formatted results from prometheus, result field is not a slice")
 	}
 	}
+	if len(results) == 0 {
+		return nil, fmt.Errorf("Not enough data available in the selected time range")
+	}
 	res, ok := results[0].(map[string]interface{})["values"]
 	res, ok := results[0].(map[string]interface{})["values"]
 	totals := [][]string{}
 	totals := [][]string{}
 	for _, val := range res.([]interface{}) {
 	for _, val := range res.([]interface{}) {