Browse Source

Fix ClusterCosts query templating of offset variable

Niko Kovacevic 6 years ago
parent
commit
c40db8d825
1 changed files with 6 additions and 2 deletions
  1. 6 2
      costmodel/cluster.go

+ 6 - 2
costmodel/cluster.go

@@ -117,7 +117,7 @@ func resultToTotal(qr interface{}) ([][]string, error) {
 	return totals, nil
 }
 
-// ClusterCostsOverTime gives the current full cluster costs averaged over a window of time.
+// ClusterCosts gives the current full cluster costs averaged over a window of time.
 func ClusterCosts(cli prometheusClient.Client, cloud costAnalyzerCloud.Provider, windowString, offset string) (*Totals, error) {
 
 	localStorageQuery, err := cloud.GetLocalStorageQuery()
@@ -128,6 +128,11 @@ func ClusterCosts(cli prometheusClient.Client, cloud costAnalyzerCloud.Provider,
 		localStorageQuery = fmt.Sprintf("+ %s", localStorageQuery)
 	}
 
+	// turn offsets of the format "[0-9+]h" into the format "offset [0-9+]h" for use in query templatess
+	if offset != "" {
+		offset = fmt.Sprintf("offset %s", offset)
+	}
+
 	qCores := fmt.Sprintf(queryClusterCores, offset, offset, offset)
 	qRAM := fmt.Sprintf(queryClusterRAM, offset, offset)
 	qStorage := fmt.Sprintf(queryStorage, windowString, offset, windowString, offset, localStorageQuery)
@@ -178,7 +183,6 @@ func ClusterCosts(cli prometheusClient.Client, cloud costAnalyzerCloud.Provider,
 		MemCost:     ramTotal,
 		StorageCost: storageTotal,
 	}, nil
-
 }
 
 // ClusterCostsOverTime gives the full cluster costs over time