|
|
@@ -217,9 +217,14 @@ const (
|
|
|
, "container_name","$1","container","(.+)"), "pod_name","$1","pod","(.+)")`
|
|
|
// queryPVCAllocationFmt yields the total byte-hour CPU allocation over the given window.
|
|
|
// sum(all VCPU measurements within given window) = [byte*min] by metric
|
|
|
- // (") / 60 = [byte*hour] by metric
|
|
|
+ // (") / 60 = [byte*hour] by metric, assuming no missed scrapes
|
|
|
+ // (") * (normalization factor) = [byte*hour] by metric, normalized for missed scrapes
|
|
|
// sum(") by unique pvc = [VCPU*hour] by (cluster, namespace, pod, pv, pvc)
|
|
|
- queryPVCAllocationFmt = `sum(sum_over_time(pod_pvc_allocation[%s:1m])) by (cluster_id, namespace, pod, persistentvolume, persistentvolumeclaim) / 60`
|
|
|
+ // Note: normalization factor is 1.0 if no scrapes are missed and has an upper bound determined by minExpectedScrapeRate
|
|
|
+ // so that coarse resolutions don't push normalization factors too high; e.g. 24h resolution with 1h of data would make
|
|
|
+ // for a normalization factor of 24. With a minimumExpectedScrapeRate of 0.95, that caps the norm factor at
|
|
|
+ queryPVCAllocationFmt = `sum(sum_over_time(pod_pvc_allocation[%s:1m])) by (cluster_id, namespace, pod, persistentvolume, persistentvolumeclaim) / 60
|
|
|
+ * 60 / clamp_min(count_over_time(sum(pod_pvc_allocation) by (cluster_id, namespace, pod, persistentvolume, persistentvolumeclaim)[%s:1m])/%f, 60 * %f)`
|
|
|
queryPVHourlyCostFmt = `avg_over_time(pv_hourly_cost[%s])`
|
|
|
queryNSLabels = `avg_over_time(kube_namespace_labels[%s])`
|
|
|
queryPodLabels = `avg_over_time(kube_pod_labels[%s])`
|
|
|
@@ -1698,7 +1703,7 @@ func (cm *CostModel) costDataRange(cli prometheusClient.Client, clientset kubern
|
|
|
queryCPUUsage := fmt.Sprintf(queryCPUUsageStr, windowString, "")
|
|
|
queryGPURequests := fmt.Sprintf(queryGPURequestsStr, windowString, "", windowString, "", resolutionHours, windowString, "")
|
|
|
queryPVRequests := fmt.Sprintf(queryPVRequestsStr)
|
|
|
- queryPVCAllocation := fmt.Sprintf(queryPVCAllocationFmt, windowString)
|
|
|
+ queryPVCAllocation := fmt.Sprintf(queryPVCAllocationFmt, windowString, windowString, resolutionHours, minimumExpectedScrapeRate)
|
|
|
queryPVHourlyCost := fmt.Sprintf(queryPVHourlyCostFmt, windowString)
|
|
|
queryNetZoneRequests := fmt.Sprintf(queryZoneNetworkUsage, windowString, "")
|
|
|
queryNetRegionRequests := fmt.Sprintf(queryRegionNetworkUsage, windowString, "")
|