Skip to content

Commit

Permalink
fix: avoid fetching empty metrics (kubewharf#98)
Browse files Browse the repository at this point in the history
As metricsFetcher.GetContainerMetric and cpuResourceAdvisor.update are called in separate goroutines,
the latter may be executed before the former, resulting in obtaining empty metrics and
falling back to using pod requests as estimated resources, which leads to a sharp decrease in headroom.

Signed-off-by: linzhecheng <linzhecheng@bytedance.com>
  • Loading branch information
cheney-lin authored and luomingmeng committed Oct 11, 2024
1 parent 5e0587f commit 0e3726e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ func (cra *cpuResourceAdvisor) update() {
cra.mutex.Lock()
defer cra.mutex.Unlock()

// skip updating during startup
if time.Now().Before(cra.startTime.Add(types.StartUpPeriod)) {
klog.Infof("[qosaware-cpu] skip updating: starting up")
return
}

// sanity check: if reserve pool exists
reservePoolInfo, ok := cra.metaCache.GetPoolInfo(state.PoolNameReserve)
if !ok || reservePoolInfo == nil {
Expand Down Expand Up @@ -192,12 +198,6 @@ func (cra *cpuResourceAdvisor) update() {

klog.Infof("[qosaware-cpu] region map: %v", general.ToString(cra.regionMap))

// skip notifying cpu server during startup
if time.Now().Before(cra.startTime.Add(types.StartUpPeriod)) {
klog.Infof("[qosaware-cpu] skip notifying cpu server: starting up")
return
}

// assemble provision result from each region and notify cpu server
calculationResult, err := cra.assembleProvision()
if err != nil {
Expand Down

0 comments on commit 0e3726e

Please sign in to comment.