瀏覽代碼

Update modules/prometheus-source/pkg/prom/metricsquerier.go

Co-authored-by: Thomas Nguyen <thomasvn.dev@gmail.com>
Signed-off-by: Matt Bolt <mbolt35@gmail.com>
Matt Bolt 1 年之前
父節點
當前提交
63bed7a6ab
共有 1 個文件被更改,包括 9 次插入2 次删除
  1. 9 2
      modules/prometheus-source/pkg/prom/metricsquerier.go

+ 9 - 2
modules/prometheus-source/pkg/prom/metricsquerier.go

@@ -1371,8 +1371,15 @@ func (pds *PrometheusMetricsQuerier) QueryDataCoverage(limitDays int) (time.Time
 func (pds *PrometheusMetricsQuerier) durationStringFor(start, end time.Time, minsPerResolution int) string {
 	dur := end.Sub(start)
 
-	// if using a version of prometheus where the resolution needs duration offset,
-	// we need to apply that here
+	// If using a version of Prometheus where the resolution needs duration offset,
+	// we need to apply that here.
+	//
+	// E.g. avg(node_total_hourly_cost{}) by (node, provider_id)[60m:5m] with
+	// time=01:00:00 will return, for a node running the entire time, 12
+	// timestamps where the first is 00:05:00 and the last is 01:00:00.
+	// However, OpenCost expects for there to be 13 timestamps where the first
+	// begins at 00:00:00. To achieve this, we must modify our query to 
+	// avg(node_total_hourly_cost{}) by (node, provider_id)[65m:5m]
 	if pds.promConfig.IsOffsetResolution {
 		// increase the query time by the resolution
 		dur = dur + (time.Duration(minsPerResolution) * time.Minute)