Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new metric kube_pod_scheduler #2222

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/pod-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
| 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 | - |
| 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 | - |
| 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 | - |
| kube_pod_scheduler_name | Gauge | The scheduler name for a pod | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; <br> `scheduler_name`=&lt;scheduler_name&gt; | EXPERIMENTAL | - |

## Useful metrics queries

Expand Down
22 changes: 22 additions & 0 deletions internal/store/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func podMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
createPodTolerationsFamilyGenerator(),
createPodNodeSelectorsFamilyGenerator(),
createPodServiceAccountFamilyGenerator(),
createPodSchedulerNameFamilyGenerator(),
}
}

Expand Down Expand Up @@ -1708,6 +1709,27 @@ func createPodServiceAccountFamilyGenerator() generator.FamilyGenerator {
)
}

func createPodSchedulerNameFamilyGenerator() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_pod_scheduler_name",
"The scheduler name for a pod.",
metric.Gauge,
basemetrics.ALPHA,
"",
wrapPodFunc(func(p *v1.Pod) *metric.Family {
m := metric.Metric{
LabelKeys: []string{"scheduler_name"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if having something like kube_pod_scheduler{name="foo"} could be better to remove the redundancy with the metric name its label.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think that makes sense. Updated.

LabelValues: []string{p.Spec.SchedulerName},
Value: 1,
}

return &metric.Family{
Metrics: []*metric.Metric{&m},
}
}),
)
}

func wrapPodFunc(f func(*v1.Pod) *metric.Family) func(interface{}) *metric.Family {
return func(obj interface{}) *metric.Family {
pod := obj.(*v1.Pod)
Expand Down
22 changes: 21 additions & 1 deletion internal/store/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,26 @@ func TestPodStore(t *testing.T) {
"kube_pod_service_account",
},
},
{
Obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod1",
Namespace: "ns1",
UID: "uid1",
},
Spec: v1.PodSpec{
SchedulerName: "scheduler1",
},
},
Want: `
# HELP kube_pod_scheduler_name The scheduler name for a pod.
# TYPE kube_pod_scheduler_name gauge
kube_pod_scheduler_name{namespace="ns1",pod="pod1",scheduler_name="scheduler1",uid="uid1"} 1
`,
MetricNames: []string{
"kube_pod_scheduler_name",
},
},
}

for i, c := range cases {
Expand Down Expand Up @@ -2231,7 +2251,7 @@ func BenchmarkPodStore(b *testing.B) {
},
}

expectedFamilies := 52
expectedFamilies := 53
for n := 0; n < b.N; n++ {
families := f(pod)
if len(families) != expectedFamilies {
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func TestFullScrapeCycle(t *testing.T) {
# HELP kube_pod_overhead_cpu_cores The pod overhead in regards to cpu cores associated with running a pod.
# HELP kube_pod_overhead_memory_bytes The pod overhead in regards to memory associated with running a pod.
# HELP kube_pod_runtimeclass_name_info The runtimeclass associated with the pod.
# HELP kube_pod_scheduler_name The scheduler name for a pod.
# HELP kube_pod_service_account The service account for a pod.
# HELP kube_pod_owner [STABLE] Information about the Pod's owner.
# HELP kube_pod_restart_policy [STABLE] Describes the restart policy in use by this pod.
Expand Down Expand Up @@ -286,6 +287,7 @@ func TestFullScrapeCycle(t *testing.T) {
# TYPE kube_pod_overhead_cpu_cores gauge
# TYPE kube_pod_overhead_memory_bytes gauge
# TYPE kube_pod_runtimeclass_name_info gauge
# TYPE kube_pod_scheduler_name gauge
# TYPE kube_pod_service_account gauge
# TYPE kube_pod_owner gauge
# TYPE kube_pod_restart_policy gauge
Expand Down Expand Up @@ -336,6 +338,7 @@ kube_pod_created{namespace="default",pod="pod0",uid="abc-0"} 1.5e+09
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
kube_pod_owner{namespace="default",pod="pod0",uid="abc-0",owner_kind="",owner_name="",owner_is_controller=""} 1
kube_pod_restart_policy{namespace="default",pod="pod0",uid="abc-0",type="Always"} 1
kube_pod_scheduler_name{namespace="default",pod="pod0",uid="abc-0",scheduler_name="scheduler1"} 1
kube_pod_service_account{namespace="default",pod="pod0",uid="abc-0",service_account=""} 1
kube_pod_status_phase{namespace="default",pod="pod0",uid="abc-0",phase="Failed"} 0
kube_pod_status_phase{namespace="default",pod="pod0",uid="abc-0",phase="Pending"} 0
Expand Down Expand Up @@ -774,6 +777,7 @@ func pod(client *fake.Clientset, index int) error {
UID: types.UID("abc-" + i),
},
Spec: v1.PodSpec{
SchedulerName: "scheduler1",
RestartPolicy: v1.RestartPolicyAlways,
NodeName: "node1",
Containers: []v1.Container{
Expand Down