Skip to content

Commit

Permalink
koordlet: fix misleading query helper (#1893)
Browse files Browse the repository at this point in the history
Signed-off-by: saintube <saintube@foxmail.com>
  • Loading branch information
saintube committed Feb 5, 2024
1 parent 93f2bc2 commit bdaf284
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/koordlet/qosmanager/helpers/metrics_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ func CollectContainerThrottledMetric(metricCache metriccache.MetricCache, contai
return aggregateResult, nil
}

func GenerateQueryParamsAvg(windowSeconds int64) *metriccache.QueryParam {
func GenerateQueryParamsAvg(windowDuration time.Duration) *metriccache.QueryParam {
end := time.Now()
start := end.Add(-time.Duration(windowSeconds) * time.Second)
start := end.Add(-windowDuration)
queryParam := &metriccache.QueryParam{
Aggregate: metriccache.AggregationTypeAVG,
Start: &start,
Expand Down
2 changes: 1 addition & 1 deletion pkg/koordlet/qosmanager/plugins/cpuburst/cpu_burst.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (b *cpuBurst) start() {
// return isOverload, share pool usage ratio and message detail
func (b *cpuBurst) getNodeStateForBurst(sharePoolThresholdPercent int64,
podsMeta []*statesinformer.PodMeta) nodeStateForBurst {
overloadMetricDuration := util.MinInt64(int64(b.reconcileInterval*5), int64(10*time.Second))
overloadMetricDuration := time.Duration(util.MinInt64(int64(b.reconcileInterval*5), int64(10*time.Second)))
queryParam := helpers.GenerateQueryParamsAvg(overloadMetricDuration)

queryMeta, err := metriccache.NodeCPUUsageMetric.BuildQueryMeta(nil)
Expand Down
20 changes: 10 additions & 10 deletions pkg/koordlet/qosmanager/plugins/cpuevict/cpu_evict.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ func (c *cpuEvictor) cpuEvict() {

func (c *cpuEvictor) calculateMilliRelease(thresholdConfig *slov1alpha1.ResourceThresholdStrategy, windowSeconds int64) int64 {
// Step1: Calculate release resource by BECPUResourceMetric in window
queryparam := helpers.GenerateQueryParamsAvg(windowSeconds)
querier, err := c.metricCache.Querier(*queryparam.Start, *queryparam.End)
queryParam := helpers.GenerateQueryParamsAvg(time.Duration(windowSeconds) * time.Second)
querier, err := c.metricCache.Querier(*queryParam.Start, *queryParam.End)
if err != nil {
klog.Warningf("get query failed, error %v", err)
return 0
}
// BECPUUsage
avgBECPUMilliUsage, count01 := getBECPUMetric(metriccache.BEResourceAllocationUsage, querier, queryparam.Aggregate)
avgBECPUMilliUsage, count01 := getBECPUMetric(metriccache.BEResourceAllocationUsage, querier, queryParam.Aggregate)
// BECPURequest
avgBECPUMilliRequest, count02 := getBECPUMetric(metriccache.BEResourceAllocationRequest, querier, queryparam.Aggregate)
avgBECPUMilliRequest, count02 := getBECPUMetric(metriccache.BEResourceAllocationRequest, querier, queryParam.Aggregate)
// BECPULimit
avgBECPUMilliRealLimit, count03 := getBECPUMetric(metriccache.BEResourceAllocationRealLimit, querier, queryparam.Aggregate)
avgBECPUMilliRealLimit, count03 := getBECPUMetric(metriccache.BEResourceAllocationRealLimit, querier, queryParam.Aggregate)

// CPU Satisfaction considers the allocatable when policy=evictByAllocatable.
avgBECPUMilliLimit := avgBECPUMilliRealLimit
Expand Down Expand Up @@ -172,18 +172,18 @@ func (c *cpuEvictor) calculateMilliRelease(thresholdConfig *slov1alpha1.Resource
}

// Step2: Calculate release resource current
queryparam = helpers.GenerateQueryParamsLast(c.metricCollectInterval * 2)
querier, err = c.metricCache.Querier(*queryparam.Start, *queryparam.End)
queryParam = helpers.GenerateQueryParamsLast(c.metricCollectInterval * 2)
querier, err = c.metricCache.Querier(*queryParam.Start, *queryParam.End)
if err != nil {
klog.Warningf("get query failed, error %v", err)
return 0
}
// BECPUUsage
currentBECPUMilliUsage, _ := getBECPUMetric(metriccache.BEResourceAllocationUsage, querier, queryparam.Aggregate)
currentBECPUMilliUsage, _ := getBECPUMetric(metriccache.BEResourceAllocationUsage, querier, queryParam.Aggregate)
// BECPURequest
currentBECPUMilliRequest, _ := getBECPUMetric(metriccache.BEResourceAllocationRequest, querier, queryparam.Aggregate)
currentBECPUMilliRequest, _ := getBECPUMetric(metriccache.BEResourceAllocationRequest, querier, queryParam.Aggregate)
// BECPULimit
currentBECPUMilliRealLimit, _ := getBECPUMetric(metriccache.BEResourceAllocationRealLimit, querier, queryparam.Aggregate)
currentBECPUMilliRealLimit, _ := getBECPUMetric(metriccache.BEResourceAllocationRealLimit, querier, queryParam.Aggregate)

// CPU Satisfaction considers the allocatable when policy=evictByAllocatable.
currentBECPUMilliLimit := currentBECPUMilliRealLimit
Expand Down

0 comments on commit bdaf284

Please sign in to comment.