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 restartPolicy to kube_pod_init_container_info metric #2240

Merged

Conversation

changhyuni
Copy link
Contributor

@changhyuni changhyuni commented Nov 18, 2023

What this PR does / why we need it:

This PR adds a label to kube_pod_init_container_info to track the restartPolicy set in the init_container
With sidecar support starting with kubernetes 1.28, init_container can be used restartPolicy
This metric tells you which pods are using the sidecar feature

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)
adds a label that is never updated for a given init container

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 18, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If kube-state-metrics contributors determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 18, 2023
@changhyuni changhyuni changed the title Add label init cotainter metric feat: add restartPolicy to kube_pod_init_container_info metric Nov 18, 2023
@changhyuni changhyuni force-pushed the add_label_init_cotainter_metric branch 2 times, most recently from 1c66a95 to 6ed3c50 Compare November 19, 2023 07:21
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 19, 2023
@changhyuni changhyuni force-pushed the add_label_init_cotainter_metric branch 2 times, most recently from bed3463 to 863e023 Compare November 19, 2023 07:23
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 19, 2023
@changhyuni changhyuni closed this Nov 19, 2023
@mrueg
Copy link
Member

mrueg commented Dec 12, 2023

@changhyuni any plans to revive this one? This could be an interesting label

@changhyuni changhyuni reopened this Dec 13, 2023
@changhyuni
Copy link
Contributor Author

changhyuni commented Dec 13, 2023

@mrueg I've reopened it. I'll fix the tests that are failing.

@changhyuni changhyuni force-pushed the add_label_init_cotainter_metric branch from 863e023 to 4769203 Compare December 14, 2023 13:49
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 14, 2023
@changhyuni changhyuni force-pushed the add_label_init_cotainter_metric branch from 4769203 to ed1a7f9 Compare December 14, 2023 13:51
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 14, 2023
@@ -677,16 +677,21 @@ func createPodInitContainerInfoFamilyGenerator() generator.FamilyGenerator {
"",
wrapPodFunc(func(p *v1.Pod) *metric.Family {
ms := []*metric.Metric{}
labelKeys := []string{"container", "image_spec", "image", "image_id", "container_id"}
labelKeys := []string{"container", "image_spec", "image", "image_id", "container_id", "type"}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
labelKeys := []string{"container", "image_spec", "image", "image_id", "container_id", "type"}
labelKeys := []string{"container", "image_spec", "image", "image_id", "container_id", "restart_policy"}

let's use the kubernetes specific labels

Copy link
Contributor Author

@changhyuni changhyuni Dec 15, 2023

Choose a reason for hiding this comment

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

@mrueg nice i fixed
but, container restart policy and pod restart policy label names are different
https://github.com/kubernetes/kube-state-metrics/blob/main/internal/store/pod.go#L1191C11-L1191C11

Copy link
Member

Choose a reason for hiding this comment

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

yes, that one is in a separate metric, I think if this is in an Info metric it's too generic to call it type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mrueg
I understand. From that perspective, restart_policy would be better.

modify label key
@changhyuni changhyuni force-pushed the add_label_init_cotainter_metric branch from 16e83bb to b948807 Compare December 15, 2023 00:18
@@ -36,7 +36,7 @@
| kube_pod_created | Gauge | Unix creation timestamp | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
| kube_pod_deletion_timestamp | Gauge | Unix deletion timestamp | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
| kube_pod_restart_policy | Gauge | Describes the restart policy in use by this pod | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `type`=&lt;Always\|Never\|OnFailure&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
| kube_pod_init_container_info | Gauge | Information about an init container in a pod | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `image`=&lt;image-name&gt; <br> `image_id`=&lt;image-id&gt; <br> `image_spec`=&lt;image-spec&gt; <br> `container_id`=&lt;containerid&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
| kube_pod_init_container_info | Gauge | Information about an init container in a pod | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `image`=&lt;image-name&gt; <br> `image_id`=&lt;image-id&gt; <br> `image_spec`=&lt;image-spec&gt; <br> `container_id`=&lt;containerid&gt; <br> `uid`=&lt;pod-uid&gt; <br> `type`=&lt;Always&gt; | STABLE | - |
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
| kube_pod_init_container_info | Gauge | Information about an init container in a pod | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `image`=&lt;image-name&gt; <br> `image_id`=&lt;image-id&gt; <br> `image_spec`=&lt;image-spec&gt; <br> `container_id`=&lt;containerid&gt; <br> `uid`=&lt;pod-uid&gt; <br> `type`=&lt;Always&gt; | STABLE | - |
| kube_pod_init_container_info | Gauge | Information about an init container in a pod | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `image`=&lt;image-name&gt; <br> `image_id`=&lt;image-id&gt; <br> `image_spec`=&lt;image-spec&gt; <br> `container_id`=&lt;containerid&gt; <br> `uid`=&lt;pod-uid&gt; <br> `type`=&lt;restart-policy&gt; | STABLE | - |

One last change.

Copy link
Contributor Author

@changhyuni changhyuni Dec 18, 2023

Choose a reason for hiding this comment

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

@mrueg
<br> `restart_policy`=&lt;Always&gt;
right? i fixed

Copy link
Member

Choose a reason for hiding this comment

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

The Always should be replaced by a placeholder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mrueg
i fixed

docs/pod-metrics.md Outdated Show resolved Hide resolved
@mrueg
Copy link
Member

mrueg commented Dec 19, 2023

/lgtm

Thanks for your contribution!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 19, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: changhyuni, mrueg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 19, 2023
@k8s-ci-robot k8s-ci-robot merged commit fde27ec into kubernetes:main Dec 19, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants