From 44e0c79406649fa0018420129a4f9f51e83aa3a5 Mon Sep 17 00:00:00 2001 From: utam0k Date: Thu, 8 Jan 2026 21:02:17 +0900 Subject: [PATCH] Align the meaning of victim metrics between async preemption and sync preemption Signed-off-by: utam0k --- pkg/scheduler/framework/preemption/preemption.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/scheduler/framework/preemption/preemption.go b/pkg/scheduler/framework/preemption/preemption.go index 08819574be0..5df7e80d3de 100644 --- a/pkg/scheduler/framework/preemption/preemption.go +++ b/pkg/scheduler/framework/preemption/preemption.go @@ -462,6 +462,8 @@ func (ev *Evaluator) SelectCandidate(ctx context.Context, candidates []Candidate // - Reject the victim pods if they are in waitingPod map // - Clear the low-priority pods' nominatedNodeName status if needed func (ev *Evaluator) prepareCandidate(ctx context.Context, c Candidate, pod *v1.Pod, pluginName string) *fwk.Status { + metrics.PreemptionVictims.Observe(float64(len(c.Victims().Pods))) + fh := ev.Handler cs := ev.Handler.ClientSet() @@ -484,8 +486,6 @@ func (ev *Evaluator) prepareCandidate(ctx context.Context, c Candidate, pod *v1. return fwk.AsStatus(err) } - metrics.PreemptionVictims.Observe(float64(len(c.Victims().Pods))) - // Lower priority pods nominated to run on this node, may no longer fit on // this node. So, we should remove their nomination. Removing their // nomination updates these pods and moves them to the active queue. It @@ -532,8 +532,6 @@ func clearNominatedNodeName(ctx context.Context, cs clientset.Interface, apiCach // // See http://kep.k8s.io/4832 for how the async preemption works. func (ev *Evaluator) prepareCandidateAsync(c Candidate, pod *v1.Pod, pluginName string) { - metrics.PreemptionVictims.Observe(float64(len(c.Victims().Pods))) - // Intentionally create a new context, not using a ctx from the scheduling cycle, to create ctx, // because this process could continue even after this scheduling cycle finishes. ctx, cancel := context.WithCancel(context.Background()) @@ -553,6 +551,8 @@ func (ev *Evaluator) prepareCandidateAsync(c Candidate, pod *v1.Pod, pluginName return } + metrics.PreemptionVictims.Observe(float64(len(c.Victims().Pods))) + errCh := parallelize.NewErrorChannel() preemptPod := func(index int) { victim := victimPods[index]