Skip to content

Commit 7b8ea90

Browse files
authored
Merge pull request #2222 from adinhodovic/add-scheduler-name-metric
feat: Add new metric kube_pod_scheduler
2 parents a5e439a + e9c7e66 commit 7b8ea90

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

docs/pod-metrics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
| kube_pod_status_unschedulable | Gauge | Describes the unschedulable status for the pod | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
5555
| kube_pod_tolerations | Gauge | Information about the pod tolerations | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; <br> `key`=&lt;toleration-key&gt; <br> `operator`=&lt;toleration-operator&gt; <br> `value`=&lt;toleration-value&gt; <br> `effect`=&lt;toleration-effect&gt; `toleration_seconds`=&lt;toleration-seconds&gt; | EXPERIMENTAL | - |
5656
| kube_pod_service_account | Gauge | The service account for a pod | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; <br> `service_account`=&lt;service_account&gt; | EXPERIMENTAL | - |
57+
| kube_pod_scheduler | Gauge | The scheduler for a pod | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; <br> `name`=&lt;scheduler-name&gt; | EXPERIMENTAL | - |
5758

5859
## Useful metrics queries
5960

internal/store/pod.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func podMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
9494
createPodTolerationsFamilyGenerator(),
9595
createPodNodeSelectorsFamilyGenerator(),
9696
createPodServiceAccountFamilyGenerator(),
97+
createPodSchedulerNameFamilyGenerator(),
9798
}
9899
}
99100

@@ -1708,6 +1709,27 @@ func createPodServiceAccountFamilyGenerator() generator.FamilyGenerator {
17081709
)
17091710
}
17101711

1712+
func createPodSchedulerNameFamilyGenerator() generator.FamilyGenerator {
1713+
return *generator.NewFamilyGeneratorWithStability(
1714+
"kube_pod_scheduler",
1715+
"The scheduler for a pod.",
1716+
metric.Gauge,
1717+
basemetrics.ALPHA,
1718+
"",
1719+
wrapPodFunc(func(p *v1.Pod) *metric.Family {
1720+
m := metric.Metric{
1721+
LabelKeys: []string{"name"},
1722+
LabelValues: []string{p.Spec.SchedulerName},
1723+
Value: 1,
1724+
}
1725+
1726+
return &metric.Family{
1727+
Metrics: []*metric.Metric{&m},
1728+
}
1729+
}),
1730+
)
1731+
}
1732+
17111733
func wrapPodFunc(f func(*v1.Pod) *metric.Family) func(interface{}) *metric.Family {
17121734
return func(obj interface{}) *metric.Family {
17131735
pod := obj.(*v1.Pod)

internal/store/pod_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,26 @@ func TestPodStore(t *testing.T) {
21362136
"kube_pod_service_account",
21372137
},
21382138
},
2139+
{
2140+
Obj: &v1.Pod{
2141+
ObjectMeta: metav1.ObjectMeta{
2142+
Name: "pod1",
2143+
Namespace: "ns1",
2144+
UID: "uid1",
2145+
},
2146+
Spec: v1.PodSpec{
2147+
SchedulerName: "scheduler1",
2148+
},
2149+
},
2150+
Want: `
2151+
# HELP kube_pod_scheduler The scheduler for a pod.
2152+
# TYPE kube_pod_scheduler gauge
2153+
kube_pod_scheduler{namespace="ns1",pod="pod1",name="scheduler1",uid="uid1"} 1
2154+
`,
2155+
MetricNames: []string{
2156+
"kube_pod_scheduler",
2157+
},
2158+
},
21392159
}
21402160

21412161
for i, c := range cases {
@@ -2231,7 +2251,7 @@ func BenchmarkPodStore(b *testing.B) {
22312251
},
22322252
}
22332253

2234-
expectedFamilies := 52
2254+
expectedFamilies := 53
22352255
for n := 0; n < b.N; n++ {
22362256
families := f(pod)
22372257
if len(families) != expectedFamilies {

pkg/app/server_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func TestFullScrapeCycle(t *testing.T) {
235235
# HELP kube_pod_overhead_cpu_cores The pod overhead in regards to cpu cores associated with running a pod.
236236
# HELP kube_pod_overhead_memory_bytes The pod overhead in regards to memory associated with running a pod.
237237
# HELP kube_pod_runtimeclass_name_info The runtimeclass associated with the pod.
238+
# HELP kube_pod_scheduler The scheduler for a pod.
238239
# HELP kube_pod_service_account The service account for a pod.
239240
# HELP kube_pod_owner [STABLE] Information about the Pod's owner.
240241
# HELP kube_pod_restart_policy [STABLE] Describes the restart policy in use by this pod.
@@ -286,6 +287,7 @@ func TestFullScrapeCycle(t *testing.T) {
286287
# TYPE kube_pod_overhead_cpu_cores gauge
287288
# TYPE kube_pod_overhead_memory_bytes gauge
288289
# TYPE kube_pod_runtimeclass_name_info gauge
290+
# TYPE kube_pod_scheduler gauge
289291
# TYPE kube_pod_service_account gauge
290292
# TYPE kube_pod_owner gauge
291293
# TYPE kube_pod_restart_policy gauge
@@ -336,6 +338,7 @@ kube_pod_created{namespace="default",pod="pod0",uid="abc-0"} 1.5e+09
336338
kube_pod_info{namespace="default",pod="pod0",uid="abc-0",host_ip="1.1.1.1",pod_ip="1.2.3.4",node="node1",created_by_kind="",created_by_name="",priority_class="",host_network="false"} 1
337339
kube_pod_owner{namespace="default",pod="pod0",uid="abc-0",owner_kind="",owner_name="",owner_is_controller=""} 1
338340
kube_pod_restart_policy{namespace="default",pod="pod0",uid="abc-0",type="Always"} 1
341+
kube_pod_scheduler{namespace="default",pod="pod0",uid="abc-0",name="scheduler1"} 1
339342
kube_pod_service_account{namespace="default",pod="pod0",uid="abc-0",service_account=""} 1
340343
kube_pod_status_phase{namespace="default",pod="pod0",uid="abc-0",phase="Failed"} 0
341344
kube_pod_status_phase{namespace="default",pod="pod0",uid="abc-0",phase="Pending"} 0
@@ -774,6 +777,7 @@ func pod(client *fake.Clientset, index int) error {
774777
UID: types.UID("abc-" + i),
775778
},
776779
Spec: v1.PodSpec{
780+
SchedulerName: "scheduler1",
777781
RestartPolicy: v1.RestartPolicyAlways,
778782
NodeName: "node1",
779783
Containers: []v1.Container{

0 commit comments

Comments
 (0)