Merge pull request #135955 from utam0k/async-metrics

scheduler: align the meaning of victim metrics between async preemption and sync preemption
This commit is contained in:
Kubernetes Prow Robot 2026-01-08 20:39:41 +05:30 committed by GitHub
commit b54554b72d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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]