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

fix: Support scraping pods metrics that is still in scheduling status and has no assigned node #2217

Merged

Conversation

mickeyzzc
Copy link
Contributor

@mickeyzzc mickeyzzc commented Oct 11, 2023

What this PR does / why we need it:

When daemonset is used to scrape the metrics of pods, it can only scrape the metrics of pods assigned to nodes, but in scheduling, for example, pods in pending state cannot be scraped.
This results in pending pods with no indicators to observe and alert.
This pr adds a configuration parameter that, when enabled, captures pending pods from apiservice.

Signed-off-by: mickeyzzc <mickey_zzc@163.com>
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 11, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Oct 11, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @mickeyzzc!

It looks like this is your first PR to kubernetes/kube-state-metrics 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kube-state-metrics has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Oct 11, 2023
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 11, 2023
Signed-off-by: mickeyzzc <mickey_zzc@163.com>
@mickeyzzc mickeyzzc changed the title Support scraping pods metrics that is still in scheduling status and has no assigned node fix: Support scraping pods metrics that is still in scheduling status and has no assigned node Oct 11, 2023
@CatherineF-dev
Copy link
Contributor

CatherineF-dev commented Oct 11, 2023

Cool! Thanks for it!
We also found Daemonset sharding loses pod metrics who don't have assigned node. Just found it can be fixed by this PR.

@CatherineF-dev
Copy link
Contributor

/assign @CatherineF-dev

Signed-off-by: mickeyzzc <mickey_zzc@163.com>
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 12, 2023
@mickeyzzc mickeyzzc requested a review from mrueg October 12, 2023 15:02
return EmptyFieldSelector()
pattern := "[^a-zA-Z0-9_,-]+"
re := regexp.MustCompile(pattern)
result := re.ReplaceAllString(n.String(), "")
Copy link
Contributor

@CatherineF-dev CatherineF-dev Oct 12, 2023

Choose a reason for hiding this comment

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

QQ: why we need re.ReplaceAllString(n.String(), "")

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove re.ReplaceAllString(n.String(), ""). If node name isn't correct, keep it as before. Then users can know node name isn't correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

QQ: why we need re.ReplaceAllString(n.String(), "")

There are two considerations for regularization here:

  1. Handle the difference between "" and nil
  2. Correction of node name

Copy link
Contributor

Choose a reason for hiding this comment

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

QQ: could you give two examples for these two cases?

We shouldn't change node name, which users are not aware of.

Copy link
Contributor

@CatherineF-dev CatherineF-dev Nov 21, 2023

Choose a reason for hiding this comment

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

Ping~

Keep node name as same from input, or return errors during validation. We should not hide errors.

Copy link
Member

Choose a reason for hiding this comment

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

@mickeyzzc can you address this comment?

Signed-off-by: 蓝宝石的傻话 <mickey_zzc@163.com>
@mickeyzzc mickeyzzc force-pushed the pods-shards-support-no-node-scraping branch from dff7885 to d33929e Compare October 12, 2023 15:21
@CatherineF-dev
Copy link
Contributor

Cool! Seems we can make it without an extra flag.

Signed-off-by: 蓝宝石的傻话 <mickey_zzc@163.com>
Signed-off-by: 蓝宝石的傻话 <mickey_zzc@163.com>
@dashpole
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 19, 2023
Signed-off-by: 蓝宝石的傻话 <mickey_zzc@163.com>
@mickeyzzc
Copy link
Contributor Author

/triage accepted

@dashpole Do I need your approval to merge again?

@dashpole
Copy link
Contributor

@mickeyzzc I just did triage, to ensure the PR has an appropriate assignee. You will need approval from the reviewers and assignees on the PR to merge.

@k8s-ci-robot
Copy link
Contributor

@mickeyzzc: you cannot LGTM your own PR.

In response to this:

/lgtm

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.

@mickeyzzc
Copy link
Contributor Author

@mickeyzzc I just did triage, to ensure the PR has an appropriate assignee. You will need approval from the reviewers and assignees on the PR to merge.

@mrueg Can you help with the merger?

@mrueg
Copy link
Member

mrueg commented Nov 22, 2023

To my understanding, when someone runs the daemonset for pod metrics, you suggest to have an additional deployment with --node="" to track unassigned pods?

Isn't it simpler to include pod metrics with --node="" in the regular ksm deployment that is already there additionally to the DS or does it make sense to have an additional deployment? (I'm not sure how users use this in terms of their metric storage system. @CatherineF-dev might be able to provide insights)

And before we can merge, can you update the README so users know how to apply this?
https://github.com/kubernetes/kube-state-metrics#daemonset-sharding-for-pod-metrics

@CatherineF-dev
Copy link
Contributor

CatherineF-dev commented Nov 22, 2023

Isn't it simpler to include pod metrics with --node="" in the regular ksm deployment that is already there additionally to the DS or does it make sense to have an additional deployment?

Yes, this PR wants to fix --node="" to not select any nodes. Without this CL, --node="" collects all nodes.

@CatherineF-dev
Copy link
Contributor

CatherineF-dev commented Nov 22, 2023

I left one comment here https://github.com/kubernetes/kube-state-metrics/pull/2217/files#r1399988722 that keeping node name as same from input, or return errors during validation.

Signed-off-by: mickeyzzc <mickey_zzc@163.com>
@mickeyzzc
Copy link
Contributor Author

And before we can merge, can you update the README so users know how to apply this?
https://github.com/kubernetes/kube-state-metrics#daemonset-sharding-for-pod-metrics

@mrueg completed

@@ -276,6 +276,21 @@ spec:
fieldPath: spec.nodeName
```

To track metrics for unassigned pods, you need to add an additional deployment and set `--node=""`, as shown in the following example:
```
Copy link
Member

Choose a reason for hiding this comment

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

@mickeyzzc can you add an empty line before the codeblock to fix the lint? Thanks!

README.md Show resolved Hide resolved
@mrueg
Copy link
Member

mrueg commented Dec 19, 2023

/lgtm

Thank you 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: mickeyzzc, 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 7324ae5 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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants