Sfoglia il codice sorgente

Return error on zero-length time window

Niko Kovacevic 6 anni fa
parent
commit
e696f0a815
1 ha cambiato i file con 6 aggiunte e 0 eliminazioni
  1. 6 0
      costmodel/cluster.go

+ 6 - 0
costmodel/cluster.go

@@ -118,10 +118,16 @@ func NewClusterCostsFromMonthly(cpuMonthly, gpuMonthly, ramMonthly, storageMonth
 		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 {
 		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{
 		Start:             start,
 		End:               end,