Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
54218a79
Unverified
Commit
54218a79
authored
Mar 19, 2019
by
Wei Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scheduler: add unit test for pending pods metrics
parent
0806ef2c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
151 additions
and
6 deletions
+151
-6
scheduling_queue_test.go
pkg/scheduler/internal/queue/scheduling_queue_test.go
+151
-6
No files found.
pkg/scheduler/internal/queue/scheduling_queue_test.go
View file @
54218a79
...
@@ -23,11 +23,13 @@ import (
...
@@ -23,11 +23,13 @@ import (
"testing"
"testing"
"time"
"time"
dto
"github.com/prometheus/client_model/go"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/clock"
podutil
"k8s.io/kubernetes/pkg/api/v1/pod"
podutil
"k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/pkg/scheduler/metrics"
"k8s.io/kubernetes/pkg/scheduler/util"
"k8s.io/kubernetes/pkg/scheduler/util"
)
)
...
@@ -1066,7 +1068,7 @@ func TestPodTimestamp(t *testing.T) {
...
@@ -1066,7 +1068,7 @@ func TestPodTimestamp(t *testing.T) {
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
operations
[]
operation
operations
[]
operation
operan
t
s
[]
*
podInfo
operan
d
s
[]
*
podInfo
expected
[]
*
podInfo
expected
[]
*
podInfo
}{
}{
{
{
...
@@ -1075,7 +1077,7 @@ func TestPodTimestamp(t *testing.T) {
...
@@ -1075,7 +1077,7 @@ func TestPodTimestamp(t *testing.T) {
addPodActiveQ
,
addPodActiveQ
,
addPodActiveQ
,
addPodActiveQ
,
},
},
operan
t
s
:
[]
*
podInfo
{
pInfo2
,
pInfo1
},
operan
d
s
:
[]
*
podInfo
{
pInfo2
,
pInfo1
},
expected
:
[]
*
podInfo
{
pInfo1
,
pInfo2
},
expected
:
[]
*
podInfo
{
pInfo1
,
pInfo2
},
},
},
{
{
...
@@ -1084,7 +1086,7 @@ func TestPodTimestamp(t *testing.T) {
...
@@ -1084,7 +1086,7 @@ func TestPodTimestamp(t *testing.T) {
updatePodActiveQ
,
updatePodActiveQ
,
updatePodActiveQ
,
updatePodActiveQ
,
},
},
operan
t
s
:
[]
*
podInfo
{
pInfo2
,
pInfo1
},
operan
d
s
:
[]
*
podInfo
{
pInfo2
,
pInfo1
},
expected
:
[]
*
podInfo
{
pInfo1
,
pInfo2
},
expected
:
[]
*
podInfo
{
pInfo1
,
pInfo2
},
},
},
{
{
...
@@ -1094,7 +1096,7 @@ func TestPodTimestamp(t *testing.T) {
...
@@ -1094,7 +1096,7 @@ func TestPodTimestamp(t *testing.T) {
addPodUnschedulableQ
,
addPodUnschedulableQ
,
moveAllToActiveQ
,
moveAllToActiveQ
,
},
},
operan
t
s
:
[]
*
podInfo
{
pInfo2
,
pInfo1
,
nil
},
operan
d
s
:
[]
*
podInfo
{
pInfo2
,
pInfo1
,
nil
},
expected
:
[]
*
podInfo
{
pInfo1
,
pInfo2
},
expected
:
[]
*
podInfo
{
pInfo1
,
pInfo2
},
},
},
{
{
...
@@ -1106,7 +1108,7 @@ func TestPodTimestamp(t *testing.T) {
...
@@ -1106,7 +1108,7 @@ func TestPodTimestamp(t *testing.T) {
flushBackoffQ
,
flushBackoffQ
,
moveAllToActiveQ
,
moveAllToActiveQ
,
},
},
operan
t
s
:
[]
*
podInfo
{
pInfo2
,
pInfo1
,
pInfo1
,
nil
,
nil
},
operan
d
s
:
[]
*
podInfo
{
pInfo2
,
pInfo1
,
pInfo1
,
nil
,
nil
},
expected
:
[]
*
podInfo
{
pInfo1
,
pInfo2
},
expected
:
[]
*
podInfo
{
pInfo1
,
pInfo2
},
},
},
}
}
...
@@ -1117,7 +1119,7 @@ func TestPodTimestamp(t *testing.T) {
...
@@ -1117,7 +1119,7 @@ func TestPodTimestamp(t *testing.T) {
var
podInfoList
[]
*
podInfo
var
podInfoList
[]
*
podInfo
for
i
,
op
:=
range
test
.
operations
{
for
i
,
op
:=
range
test
.
operations
{
op
(
queue
,
test
.
operan
t
s
[
i
])
op
(
queue
,
test
.
operan
d
s
[
i
])
}
}
for
i
:=
0
;
i
<
len
(
test
.
expected
);
i
++
{
for
i
:=
0
;
i
<
len
(
test
.
expected
);
i
++
{
...
@@ -1135,3 +1137,146 @@ func TestPodTimestamp(t *testing.T) {
...
@@ -1135,3 +1137,146 @@ func TestPodTimestamp(t *testing.T) {
})
})
}
}
}
}
// TestPendingPodsMetric tests Prometheus metrics related with pending pods
func
TestPendingPodsMetric
(
t
*
testing
.
T
)
{
total
:=
50
timestamp
:=
time
.
Now
()
var
pInfos
=
make
([]
*
podInfo
,
0
,
total
)
for
i
:=
1
;
i
<=
total
;
i
++
{
p
:=
&
podInfo
{
pod
:
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
fmt
.
Sprintf
(
"test-pod-%d"
,
i
),
Namespace
:
fmt
.
Sprintf
(
"ns%d"
,
i
),
UID
:
types
.
UID
(
fmt
.
Sprintf
(
"tp-%d"
,
i
)),
},
},
timestamp
:
timestamp
,
}
pInfos
=
append
(
pInfos
,
p
)
}
tests
:=
[]
struct
{
name
string
operations
[]
operation
operands
[][]
*
podInfo
expected
[]
int64
}{
{
name
:
"add pods to activeQ and unschedulableQ"
,
operations
:
[]
operation
{
addPodActiveQ
,
addPodUnschedulableQ
,
},
operands
:
[][]
*
podInfo
{
pInfos
[
:
30
],
pInfos
[
30
:
],
},
expected
:
[]
int64
{
30
,
0
,
20
},
},
{
name
:
"add pods to all kinds of queues"
,
operations
:
[]
operation
{
addPodActiveQ
,
backoffPod
,
addPodBackoffQ
,
addPodUnschedulableQ
,
},
operands
:
[][]
*
podInfo
{
pInfos
[
:
15
],
pInfos
[
15
:
40
],
pInfos
[
15
:
40
],
pInfos
[
40
:
],
},
expected
:
[]
int64
{
15
,
25
,
10
},
},
{
name
:
"add pods to unschedulableQ and then move all to activeQ"
,
operations
:
[]
operation
{
addPodUnschedulableQ
,
moveAllToActiveQ
,
},
operands
:
[][]
*
podInfo
{
pInfos
[
:
total
],
{
nil
},
},
expected
:
[]
int64
{
int64
(
total
),
0
,
0
},
},
{
name
:
"make some pods subject to backoff, add pods to unschedulableQ, and then move all to activeQ"
,
operations
:
[]
operation
{
backoffPod
,
addPodUnschedulableQ
,
moveAllToActiveQ
,
},
operands
:
[][]
*
podInfo
{
pInfos
[
:
20
],
pInfos
[
:
total
],
{
nil
},
},
expected
:
[]
int64
{
int64
(
total
-
20
),
20
,
0
},
},
{
name
:
"make some pods subject to backoff, add pods to unschedulableQ/activeQ, move all to activeQ, and finally flush backoffQ"
,
operations
:
[]
operation
{
backoffPod
,
addPodUnschedulableQ
,
addPodActiveQ
,
moveAllToActiveQ
,
flushBackoffQ
,
},
operands
:
[][]
*
podInfo
{
pInfos
[
:
20
],
pInfos
[
:
40
],
pInfos
[
40
:
],
{
nil
},
{
nil
},
},
expected
:
[]
int64
{
int64
(
total
),
0
,
0
},
},
}
resetMetrics
:=
func
()
{
metrics
.
ActivePods
.
Set
(
0
)
metrics
.
BackoffPods
.
Set
(
0
)
metrics
.
UnschedulablePods
.
Set
(
0
)
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
resetMetrics
()
queue
:=
NewPriorityQueueWithClock
(
nil
,
clock
.
NewFakeClock
(
timestamp
))
for
i
,
op
:=
range
test
.
operations
{
for
_
,
pInfo
:=
range
test
.
operands
[
i
]
{
op
(
queue
,
pInfo
)
}
}
var
activeNum
,
backoffNum
,
unschedulableNum
float64
metricProto
:=
&
dto
.
Metric
{}
if
err
:=
metrics
.
ActivePods
.
Write
(
metricProto
);
err
!=
nil
{
t
.
Errorf
(
"error writing ActivePods metric: %v"
,
err
)
}
activeNum
=
metricProto
.
Gauge
.
GetValue
()
if
int64
(
activeNum
)
!=
test
.
expected
[
0
]
{
t
.
Errorf
(
"ActivePods: Expected %v, got %v"
,
test
.
expected
[
0
],
activeNum
)
}
if
err
:=
metrics
.
BackoffPods
.
Write
(
metricProto
);
err
!=
nil
{
t
.
Errorf
(
"error writing BackoffPods metric: %v"
,
err
)
}
backoffNum
=
metricProto
.
Gauge
.
GetValue
()
if
int64
(
backoffNum
)
!=
test
.
expected
[
1
]
{
t
.
Errorf
(
"BackoffPods: Expected %v, got %v"
,
test
.
expected
[
1
],
backoffNum
)
}
if
err
:=
metrics
.
UnschedulablePods
.
Write
(
metricProto
);
err
!=
nil
{
t
.
Errorf
(
"error writing UnschedulablePods metric: %v"
,
err
)
}
unschedulableNum
=
metricProto
.
Gauge
.
GetValue
()
if
int64
(
unschedulableNum
)
!=
test
.
expected
[
2
]
{
t
.
Errorf
(
"UnschedulablePods: Expected %v, got %v"
,
test
.
expected
[
2
],
unschedulableNum
)
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment