瀏覽代碼

Return error on zero-length time window

Niko Kovacevic 6 年之前
父節點
當前提交
e696f0a815
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      costmodel/cluster.go

+ 6 - 0
costmodel/cluster.go

@@ -118,10 +118,16 @@ func NewClusterCostsFromMonthly(cpuMonthly, gpuMonthly, ramMonthly, storageMonth
 		return nil, err
 		return nil, err
 	}
 	}
 
 
+	// If the number of hours is not given (i.e. is zero) compute one from the window and offset
 	if dataHours == 0 {
 	if dataHours == 0 {
 		dataHours = end.Sub(*start).Hours()
 		dataHours = end.Sub(*start).Hours()
 	}
 	}
 
 
+	// Do not allow zero-length windows to prevent divide-by-zero issues
+	if dataHours == 0 {
+		return nil, fmt.Errorf("illegal time range: window %s, offset %s", window, offset)
+	}
+
 	cc := &ClusterCosts{
 	cc := &ClusterCosts{
 		Start:             start,
 		Start:             start,
 		End:               end,
 		End:               end,