|
|
@@ -204,23 +204,14 @@ func (a *Accesses) ComputeIdleCoefficient(costData map[string]*CostData, cli pro
|
|
|
|
|
|
key := fmt.Sprintf("%s:%s", windowString, offset)
|
|
|
if data, valid := a.ClusterCostsCache.Get(key); valid {
|
|
|
-
|
|
|
clusterCosts = data.(map[string]*ClusterCosts)
|
|
|
-
|
|
|
- log.Infof("AggAPI: ComputeIdleCoefficient: ClusterCostsCache is valid")
|
|
|
-
|
|
|
} else {
|
|
|
clusterCosts, err = a.ComputeClusterCosts(cli, cp, windowString, offset, false)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
-
|
|
|
- log.Infof("AggAPI: ComputeIdleCoefficient: ClusterCostsCache is not valid: ComputeClusterCosts")
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- log.Infof("AggAPI: ComputeIdleCoefficient: clusterCosts: %+v", clusterCosts)
|
|
|
-
|
|
|
measureTime(profileStart, profileThreshold, profileName)
|
|
|
|
|
|
for cid, costs := range clusterCosts {
|
|
|
@@ -301,8 +292,6 @@ func AggregateCostData(costData map[string]*CostData, field string, subfields []
|
|
|
rate := opts.Rate
|
|
|
sr := opts.SharedResourceInfo
|
|
|
|
|
|
- log.Infof("AggAPI: AggregateCostData: idleCoefficients: %+v", idleCoefficients)
|
|
|
-
|
|
|
resolutionHours := 1.0
|
|
|
if opts.ResolutionHours > 0.0 {
|
|
|
resolutionHours = opts.ResolutionHours
|
|
|
@@ -1402,22 +1391,38 @@ func (a *Accesses) ComputeAggregateCostModel(promClient prometheusClient.Client,
|
|
|
|
|
|
idleCoefficients := make(map[string]float64)
|
|
|
if allocateIdle {
|
|
|
- duration, offset := window.DurationOffsetStrings()
|
|
|
-
|
|
|
- idleDurationCalcHours := window.Hours()
|
|
|
- if window.Hours() < 1 {
|
|
|
- idleDurationCalcHours = 1
|
|
|
+ dur, off, err := window.DurationOffset()
|
|
|
+ if err != nil {
|
|
|
+ log.Errorf("ComputeAggregateCostModel: error computing idle coefficient: illegal window: %s (%s)", window, err)
|
|
|
+ return nil, "", err
|
|
|
}
|
|
|
- duration = fmt.Sprintf("%dh", int(idleDurationCalcHours))
|
|
|
|
|
|
- if a.ThanosClient != nil {
|
|
|
- offset = thanos.Offset()
|
|
|
- log.Infof("ComputeAggregateCostModel: setting offset to %s", offset)
|
|
|
+ if a.ThanosClient != nil && off < thanos.OffsetDuration() {
|
|
|
+ // Determine difference between the Thanos offset and the requested
|
|
|
+ // offset; e.g. off=1h, thanosOffsetDuration=3h => diff=2h
|
|
|
+ diff := thanos.OffsetDuration() - off
|
|
|
+
|
|
|
+ // Reduce duration by difference and increase offset by difference
|
|
|
+ // e.g. 24h offset 0h => 21h offset 3h
|
|
|
+ dur = dur - diff
|
|
|
+ off = thanos.OffsetDuration()
|
|
|
+
|
|
|
+ log.Infof("ComputeAggregateCostModel: setting duration, offset to %s, %s due to Thanos", dur, off)
|
|
|
+
|
|
|
+ // Idle computation cannot be fulfilled for some windows, specifically
|
|
|
+ // those with sum(duration, offset) < Thanos offset, because there is
|
|
|
+ // no data within that window.
|
|
|
+ if dur <= 0 {
|
|
|
+ return nil, "", fmt.Errorf("requested idle coefficients from Thanos for illegal duration, offset: %s, %s (original window %s)", dur, off, window)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- idleCoefficients, err = a.ComputeIdleCoefficient(costData, promClient, a.CloudProvider, discount, customDiscount, duration, offset)
|
|
|
+ // Convert to Prometheus-compatible strings
|
|
|
+ durStr, offStr := util.DurationOffsetStrings(dur, off)
|
|
|
+
|
|
|
+ idleCoefficients, err = a.ComputeIdleCoefficient(costData, promClient, a.CloudProvider, discount, customDiscount, durStr, offStr)
|
|
|
if err != nil {
|
|
|
- log.Errorf("ComputeAggregateCostModel: error computing idle coefficient: duration=%s, offset=%s, err=%s", duration, offset, err)
|
|
|
+ log.Errorf("ComputeAggregateCostModel: error computing idle coefficient: duration=%s, offset=%s, err=%s", durStr, offStr, err)
|
|
|
return nil, "", err
|
|
|
}
|
|
|
}
|