mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Merge pull request #120434 from pohly/scheduler-backoff-metric-test
scheduler: fix TestIncomingPodsMetrics unit test
This commit is contained in:
commit
3cfdf3c33d
@ -2255,7 +2255,7 @@ func TestPriorityQueue_initPodMaxInUnschedulablePodsDuration(t *testing.T) {
|
|||||||
var podInfoList []*framework.QueuedPodInfo
|
var podInfoList []*framework.QueuedPodInfo
|
||||||
|
|
||||||
for i, op := range test.operations {
|
for i, op := range test.operations {
|
||||||
op(logger, queue, test.operands[i])
|
op(t, logger, queue, test.operands[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedLen := len(test.expected)
|
expectedLen := len(test.expected)
|
||||||
@ -2278,31 +2278,58 @@ func TestPriorityQueue_initPodMaxInUnschedulablePodsDuration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type operation func(logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo)
|
type operation func(t *testing.T, logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
add = func(logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
add = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
||||||
queue.Add(logger, pInfo.Pod)
|
if err := queue.Add(logger, pInfo.Pod); err != nil {
|
||||||
|
t.Fatalf("Unexpected error during Add: %v", err)
|
||||||
}
|
}
|
||||||
addUnschedulablePodBackToUnschedulablePods = func(logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
}
|
||||||
|
popAndRequeueAsUnschedulable = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
||||||
// To simulate the pod is failed in scheduling in the real world, Pop() the pod from activeQ before AddUnschedulableIfNotPresent() below.
|
// To simulate the pod is failed in scheduling in the real world, Pop() the pod from activeQ before AddUnschedulableIfNotPresent() below.
|
||||||
queue.activeQ.Add(queue.newQueuedPodInfo(pInfo.Pod))
|
// UnschedulablePlugins will get cleared by Pop, so make a copy first.
|
||||||
if p, err := queue.Pop(); err != nil || p.Pod != pInfo.Pod {
|
unschedulablePlugins := pInfo.UnschedulablePlugins.Clone()
|
||||||
panic(fmt.Sprintf("Expected: %v after Pop, but got: %v", pInfo.Pod.Name, p.Pod.Name))
|
if err := queue.activeQ.Add(queue.newQueuedPodInfo(pInfo.Pod)); err != nil {
|
||||||
|
t.Fatalf("Unexpected error during Add: %v", err)
|
||||||
}
|
}
|
||||||
|
p, err := queue.Pop()
|
||||||
queue.AddUnschedulableIfNotPresent(logger, pInfo, 1)
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error during Pop: %v", err)
|
||||||
}
|
}
|
||||||
addUnschedulablePodBackToBackoffQ = func(logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
if p.Pod != pInfo.Pod {
|
||||||
queue.AddUnschedulableIfNotPresent(logger, pInfo, 1)
|
t.Fatalf("Expected: %v after Pop, but got: %v", pInfo.Pod.Name, p.Pod.Name)
|
||||||
}
|
}
|
||||||
addPodActiveQ = func(logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
// Simulate plugins that are waiting for some events.
|
||||||
|
p.UnschedulablePlugins = unschedulablePlugins
|
||||||
|
if err := queue.AddUnschedulableIfNotPresent(logger, p, 1); err != nil {
|
||||||
|
t.Fatalf("Unexpected error during AddUnschedulableIfNotPresent: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
popAndRequeueAsBackoff = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
||||||
|
// To simulate the pod is failed in scheduling in the real world, Pop() the pod from activeQ before AddUnschedulableIfNotPresent() below.
|
||||||
|
if err := queue.activeQ.Add(queue.newQueuedPodInfo(pInfo.Pod)); err != nil {
|
||||||
|
t.Fatalf("Unexpected error during Add: %v", err)
|
||||||
|
}
|
||||||
|
p, err := queue.Pop()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error during Pop: %v", err)
|
||||||
|
}
|
||||||
|
if p.Pod != pInfo.Pod {
|
||||||
|
t.Fatalf("Expected: %v after Pop, but got: %v", pInfo.Pod.Name, p.Pod.Name)
|
||||||
|
}
|
||||||
|
// When there is no known unschedulable plugin, pods always go to the backoff queue.
|
||||||
|
if err := queue.AddUnschedulableIfNotPresent(logger, p, 1); err != nil {
|
||||||
|
t.Fatalf("Unexpected error during AddUnschedulableIfNotPresent: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addPodActiveQ = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
||||||
queue.activeQ.Add(pInfo)
|
queue.activeQ.Add(pInfo)
|
||||||
}
|
}
|
||||||
updatePodActiveQ = func(logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
updatePodActiveQ = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
||||||
queue.activeQ.Update(pInfo)
|
queue.activeQ.Update(pInfo)
|
||||||
}
|
}
|
||||||
addPodUnschedulablePods = func(logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
addPodUnschedulablePods = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
||||||
if !pInfo.Gated {
|
if !pInfo.Gated {
|
||||||
// Update pod condition to unschedulable.
|
// Update pod condition to unschedulable.
|
||||||
podutil.UpdatePodCondition(&pInfo.Pod.Status, &v1.PodCondition{
|
podutil.UpdatePodCondition(&pInfo.Pod.Status, &v1.PodCondition{
|
||||||
@ -2314,28 +2341,28 @@ var (
|
|||||||
}
|
}
|
||||||
queue.unschedulablePods.addOrUpdate(pInfo)
|
queue.unschedulablePods.addOrUpdate(pInfo)
|
||||||
}
|
}
|
||||||
deletePod = func(_ klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
deletePod = func(t *testing.T, _ klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
||||||
queue.Delete(pInfo.Pod)
|
queue.Delete(pInfo.Pod)
|
||||||
}
|
}
|
||||||
updatePodQueueable = func(logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
updatePodQueueable = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
||||||
newPod := pInfo.Pod.DeepCopy()
|
newPod := pInfo.Pod.DeepCopy()
|
||||||
newPod.Labels = map[string]string{"queueable": ""}
|
newPod.Labels = map[string]string{"queueable": ""}
|
||||||
queue.Update(logger, pInfo.Pod, newPod)
|
queue.Update(logger, pInfo.Pod, newPod)
|
||||||
}
|
}
|
||||||
addPodBackoffQ = func(logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
addPodBackoffQ = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, pInfo *framework.QueuedPodInfo) {
|
||||||
queue.podBackoffQ.Add(pInfo)
|
queue.podBackoffQ.Add(pInfo)
|
||||||
}
|
}
|
||||||
moveAllToActiveOrBackoffQ = func(logger klog.Logger, queue *PriorityQueue, _ *framework.QueuedPodInfo) {
|
moveAllToActiveOrBackoffQ = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, _ *framework.QueuedPodInfo) {
|
||||||
queue.MoveAllToActiveOrBackoffQueue(logger, UnschedulableTimeout, nil, nil, nil)
|
queue.MoveAllToActiveOrBackoffQueue(logger, UnschedulableTimeout, nil, nil, nil)
|
||||||
}
|
}
|
||||||
flushBackoffQ = func(logger klog.Logger, queue *PriorityQueue, _ *framework.QueuedPodInfo) {
|
flushBackoffQ = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, _ *framework.QueuedPodInfo) {
|
||||||
queue.clock.(*testingclock.FakeClock).Step(2 * time.Second)
|
queue.clock.(*testingclock.FakeClock).Step(2 * time.Second)
|
||||||
queue.flushBackoffQCompleted(logger)
|
queue.flushBackoffQCompleted(logger)
|
||||||
}
|
}
|
||||||
moveClockForward = func(logger klog.Logger, queue *PriorityQueue, _ *framework.QueuedPodInfo) {
|
moveClockForward = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, _ *framework.QueuedPodInfo) {
|
||||||
queue.clock.(*testingclock.FakeClock).Step(2 * time.Second)
|
queue.clock.(*testingclock.FakeClock).Step(2 * time.Second)
|
||||||
}
|
}
|
||||||
flushUnschedulerQ = func(logger klog.Logger, queue *PriorityQueue, _ *framework.QueuedPodInfo) {
|
flushUnschedulerQ = func(t *testing.T, logger klog.Logger, queue *PriorityQueue, _ *framework.QueuedPodInfo) {
|
||||||
queue.clock.(*testingclock.FakeClock).Step(queue.podMaxInUnschedulablePodsDuration)
|
queue.clock.(*testingclock.FakeClock).Step(queue.podMaxInUnschedulablePodsDuration)
|
||||||
queue.flushUnschedulablePodsLeftover(logger)
|
queue.flushUnschedulablePodsLeftover(logger)
|
||||||
}
|
}
|
||||||
@ -2413,7 +2440,7 @@ func TestPodTimestamp(t *testing.T) {
|
|||||||
var podInfoList []*framework.QueuedPodInfo
|
var podInfoList []*framework.QueuedPodInfo
|
||||||
|
|
||||||
for i, op := range test.operations {
|
for i, op := range test.operations {
|
||||||
op(logger, queue, test.operands[i])
|
op(t, logger, queue, test.operands[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedLen := len(test.expected)
|
expectedLen := len(test.expected)
|
||||||
@ -2698,7 +2725,7 @@ scheduler_plugin_execution_duration_seconds_count{extension_point="PreEnqueue",p
|
|||||||
queue := NewTestQueue(ctx, newDefaultQueueSort(), WithClock(testingclock.NewFakeClock(timestamp)), WithPreEnqueuePluginMap(m), WithPluginMetricsSamplePercent(test.pluginMetricsSamplePercent), WithMetricsRecorder(*recorder))
|
queue := NewTestQueue(ctx, newDefaultQueueSort(), WithClock(testingclock.NewFakeClock(timestamp)), WithPreEnqueuePluginMap(m), WithPluginMetricsSamplePercent(test.pluginMetricsSamplePercent), WithMetricsRecorder(*recorder))
|
||||||
for i, op := range test.operations {
|
for i, op := range test.operations {
|
||||||
for _, pInfo := range test.operands[i] {
|
for _, pInfo := range test.operands[i] {
|
||||||
op(logger, queue, pInfo)
|
op(t, logger, queue, pInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2856,7 +2883,7 @@ func TestIncomingPodsMetrics(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "add pods to unschedulablePods",
|
name: "add pods to unschedulablePods",
|
||||||
operations: []operation{
|
operations: []operation{
|
||||||
addUnschedulablePodBackToUnschedulablePods,
|
popAndRequeueAsUnschedulable,
|
||||||
},
|
},
|
||||||
want: `
|
want: `
|
||||||
scheduler_queue_incoming_pods_total{event="ScheduleAttemptFailure",queue="unschedulable"} 3
|
scheduler_queue_incoming_pods_total{event="ScheduleAttemptFailure",queue="unschedulable"} 3
|
||||||
@ -2865,7 +2892,7 @@ func TestIncomingPodsMetrics(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "add pods to unschedulablePods and then move all to backoffQ",
|
name: "add pods to unschedulablePods and then move all to backoffQ",
|
||||||
operations: []operation{
|
operations: []operation{
|
||||||
addUnschedulablePodBackToUnschedulablePods,
|
popAndRequeueAsUnschedulable,
|
||||||
moveAllToActiveOrBackoffQ,
|
moveAllToActiveOrBackoffQ,
|
||||||
},
|
},
|
||||||
want: ` scheduler_queue_incoming_pods_total{event="ScheduleAttemptFailure",queue="unschedulable"} 3
|
want: ` scheduler_queue_incoming_pods_total{event="ScheduleAttemptFailure",queue="unschedulable"} 3
|
||||||
@ -2875,7 +2902,7 @@ func TestIncomingPodsMetrics(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "add pods to unschedulablePods and then move all to activeQ",
|
name: "add pods to unschedulablePods and then move all to activeQ",
|
||||||
operations: []operation{
|
operations: []operation{
|
||||||
addUnschedulablePodBackToUnschedulablePods,
|
popAndRequeueAsUnschedulable,
|
||||||
moveClockForward,
|
moveClockForward,
|
||||||
moveAllToActiveOrBackoffQ,
|
moveAllToActiveOrBackoffQ,
|
||||||
},
|
},
|
||||||
@ -2886,7 +2913,7 @@ func TestIncomingPodsMetrics(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "make some pods subject to backoff and add them to backoffQ, then flush backoffQ",
|
name: "make some pods subject to backoff and add them to backoffQ, then flush backoffQ",
|
||||||
operations: []operation{
|
operations: []operation{
|
||||||
addUnschedulablePodBackToBackoffQ,
|
popAndRequeueAsBackoff,
|
||||||
moveClockForward,
|
moveClockForward,
|
||||||
flushBackoffQ,
|
flushBackoffQ,
|
||||||
},
|
},
|
||||||
@ -2905,7 +2932,7 @@ func TestIncomingPodsMetrics(t *testing.T) {
|
|||||||
queue := NewTestQueue(ctx, newDefaultQueueSort(), WithClock(testingclock.NewFakeClock(timestamp)))
|
queue := NewTestQueue(ctx, newDefaultQueueSort(), WithClock(testingclock.NewFakeClock(timestamp)))
|
||||||
for _, op := range test.operations {
|
for _, op := range test.operations {
|
||||||
for _, pInfo := range pInfos {
|
for _, pInfo := range pInfos {
|
||||||
op(logger, queue, pInfo)
|
op(t, logger, queue, pInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
metricName := metrics.SchedulerSubsystem + "_" + metrics.SchedulerQueueIncomingPods.Name
|
metricName := metrics.SchedulerSubsystem + "_" + metrics.SchedulerQueueIncomingPods.Name
|
||||||
|
Loading…
Reference in New Issue
Block a user