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

Allow Lease metrics to be exported across all namespaces #1845

Merged
merged 4 commits into from
Oct 14, 2022

Conversation

lantingchiang
Copy link
Contributor

What this PR does / why we need it: This PR modifies the Lease store's createLeaseListWatch() method so that the metrics for the Lease custom resource to be exported across all namespaces, as opposed to only the kube-node-lease namespace. This allows us to get metrics on Lease resources used by pods as well.

How does this change affect the cardinality of KSM: increases cardinality by the number of namespaces

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 #

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 27, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: lantingchiang / name: Lanting Chiang (8f883f0)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Sep 27, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @lantingchiang!

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 size/S Denotes a PR that changes 10-29 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 Sep 27, 2022
@fpetkovski
Copy link
Contributor

Thanks for this PR. The change makes sense to me, but I am just curious why KSM was exporting lease metrics from that single namespace only.

/lgtm
/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 28, 2022
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 28, 2022
@fpetkovski
Copy link
Contributor

Looking at the tests, we don't expose the namespace yet: https://github.com/kubernetes/kube-state-metrics/blob/master/internal/store/lease_test.go#L57-L58

We should update the lease store to export the fields that you added to the docs, and update tests accordingly.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 28, 2022
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 28, 2022
@lantingchiang
Copy link
Contributor Author

Thanks for this PR. The change makes sense to me, but I am just curious why KSM was exporting lease metrics from that single namespace only.

I think it's because that namespace contains all node leases, so it was sufficient if pod leases weren't of interest.

Copy link
Contributor

@fpetkovski fpetkovski left a comment

Choose a reason for hiding this comment

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

Thanks

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 29, 2022
@lantingchiang
Copy link
Contributor Author

Hi @dgrisonnet, could I get a review please? Thanks!

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 11, 2022
@lantingchiang
Copy link
Contributor Author

Exported Lease.Spec.HolderIdentity field because some pod leases don't have a metadata.ownerReferences field.


owners := l.GetOwnerReferences()
if len(owners) == 0 {
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: []string{"<none>", "<none>"},
LabelValues: []string{"<none>", "<none>", l.Namespace, *l.Spec.HolderIdentity},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can *l.Spec.HolderIdentity be nil in some cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes HolderIdentity is optional. Thanks for catching this!

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 12, 2022
Comment on lines 45 to 49
var holder string
if l.Spec.HolderIdentity == nil {
holder = "<none>"
} else {
holder = *l.Spec.HolderIdentity
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var holder string
if l.Spec.HolderIdentity == nil {
holder = "<none>"
} else {
holder = *l.Spec.HolderIdentity
}
var holder string
if l.Spec.HolderIdentity != nil {
holder = *l.Spec.HolderIdentity
}

Copy link
Contributor

@fpetkovski fpetkovski left a comment

Choose a reason for hiding this comment

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

Just one small nit, otherwise looks good

labelKeys := []string{"owner_kind", "owner_name"}
labelKeys := []string{"owner_kind", "owner_name", "namespace", "lease_holder"}

holder = "<none>"
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if I was not very specific here, but I don't think we use this placeholder anywhere else, so we should not introduce it. It's fine to leave the holder label empty when there is no holder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! I was trying to match the owner_name and owner_kind values when they're empty, but thanks for the clarification!

@fpetkovski
Copy link
Contributor

Thank you for the contribution!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 13, 2022
Copy link
Member

@dgrisonnet dgrisonnet left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve
/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 14, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dgrisonnet, fpetkovski, lantingchiang

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:
  • OWNERS [dgrisonnet,fpetkovski]

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 merged commit cb5f88b into kubernetes:master Oct 14, 2022
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants