diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_advisor_handler.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_advisor_handler.go index 58fac27d3..3270c1cd9 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_advisor_handler.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_advisor_handler.go @@ -293,9 +293,7 @@ func (p *DynamicPolicy) createGetAdviceRequest() (*advisorapi.GetAdviceRequest, func (p *DynamicPolicy) getAdviceFromAdvisor(ctx context.Context) (isImplemented bool, err error) { startTime := time.Now() general.Infof("called") - p.Lock() defer func() { - p.Unlock() general.InfoS("finished", "duration", time.Since(startTime)) }() @@ -383,9 +381,7 @@ func (p *DynamicPolicy) lwCPUAdvisorServer(stopCh <-chan struct{}) error { err, status.Code(err)) } - p.Lock() err = p.allocateByCPUAdvisor(resp) - p.Unlock() if err != nil { general.Errorf("allocate by ListAndWatch response of CPUAdvisorServer failed with error: %v", err) } @@ -407,7 +403,9 @@ func (p *DynamicPolicy) allocateByCPUAdvisor(resp *advisorapi.ListAndWatchRespon startTime := time.Now() general.Infof("allocateByCPUAdvisor is called") _ = p.emitter.StoreInt64(util.MetricNameHandleAdvisorRespCalled, 1, metrics.MetricTypeNameRaw) + p.Lock() defer func() { + p.Unlock() if err != nil { _ = p.emitter.StoreInt64(util.MetricNameHandleAdvisorRespFailed, 1, metrics.MetricTypeNameRaw) } diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go index 20a650c23..f1f1771d9 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go @@ -128,9 +128,7 @@ func (p *DynamicPolicy) createGetAdviceRequest() (*advisorsvc.GetAdviceRequest, func (p *DynamicPolicy) getAdviceFromAdvisor(ctx context.Context) (isImplemented bool, err error) { startTime := time.Now() general.Infof("called") - p.Lock() defer func() { - p.Unlock() general.InfoS("finished", "duration", time.Since(startTime)) }() @@ -217,9 +215,7 @@ func (p *DynamicPolicy) lwMemoryAdvisorServer(stopCh <-chan struct{}) error { err, status.Code(err)) } - p.Lock() err = p.handleAdvisorResp(resp) - p.Unlock() if err != nil { general.Errorf("handle ListAndWatch response of MemoryAdvisorServer failed with error: %v", err) } @@ -239,7 +235,9 @@ func (p *DynamicPolicy) handleAdvisorResp(advisorResp *advisorsvc.ListAndWatchRe startTime := time.Now() general.Infof("called") _ = p.emitter.StoreInt64(util.MetricNameHandleAdvisorRespCalled, 1, metrics.MetricTypeNameRaw) + p.Lock() defer func() { + p.Unlock() if retErr != nil { _ = p.emitter.StoreInt64(util.MetricNameHandleAdvisorRespFailed, 1, metrics.MetricTypeNameRaw) }