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

Support filtering label allowlist by "*" #1823

Merged
merged 1 commit into from
Nov 8, 2022

Conversation

rexagod
Copy link
Member

@rexagod rexagod commented Sep 1, 2022

What this PR does / why we need it: Support filtering label allowlist by "*", which will expand to the enabled resources, while inferring their values based on its value(s).

How does this change affect the cardinality of KSM: No change.

Which issue(s) this PR fixes: Fixes #1815.

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

Welcome @rexagod!

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 size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 1, 2022
@rexagod
Copy link
Member Author

rexagod commented Sep 9, 2022

cc @dgrisonnet @mrueg

.gitignore Outdated
@@ -37,6 +37,7 @@ _testmain.go

*.iml
.idea/
.run/
Copy link
Member

@dgrisonnet dgrisonnet Oct 21, 2022

Choose a reason for hiding this comment

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

since this is not generated by ksm, it shouldn't be added to the gitignore

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.

I think this will be a pretty useful feature, thank you for taking it up @rexagod.

There are a couple of things that would need to be done though before merging this effort:

  • Update the description of the command to explain the new behavior:
    o.flags.Var(&o.LabelsAllowList, "metric-labels-allowlist", "Comma-separated list of additional Kubernetes label keys that will be used in the resource' labels metric. By default the metric contains only name and namespace labels. To include additional labels provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them (Example: '=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)'. A single '*' can be provided per resource instead to allow any labels, but that has severe performance implications (Example: '=pods=[*]').")
  • Add a new test for the all wildcard in
    func TestLabelsAllowListSet(t *testing.T) {
  • Test that the all wildcard really returns label metrics for all the resources. This could be an e2e test like the one we have to test the --resources option in or a unit test in for the builder:
    func TestDefaultCollectorMetricsAvailable(t *testing.T) {

@@ -202,7 +202,16 @@ func (b *Builder) WithAllowAnnotations(annotations map[string][]string) {
// WithAllowLabels configures which labels can be returned for metrics
func (b *Builder) WithAllowLabels(labels map[string][]string) {
if len(labels) > 0 {
b.allowLabelsList = labels
// "all" takes precedence over other specifications
if allowedLabels, ok := labels["all"]; ok {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use * instead of all?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 21, 2022
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 6, 2022
@rexagod rexagod force-pushed the 1815 branch 3 times, most recently from 730713f to 1919a94 Compare November 6, 2022 20:54
@rexagod rexagod changed the title Support filtering label allowlist by "all" Support filtering label allowlist by "*all*" Nov 6, 2022
@rexagod rexagod changed the title Support filtering label allowlist by "*all*" Support filtering label allowlist by "*" Nov 6, 2022
@rexagod
Copy link
Member Author

rexagod commented Nov 6, 2022

Ready for review.

internal/store/builder.go Outdated Show resolved Hide resolved
internal/store/builder.go Outdated Show resolved Hide resolved
Support filtering label allowlist by "*", which will expand to the
enabled resources, while infering their values based on its value(s).

Signed-off-by: Pranshu Srivastava <[email protected]>
Copy link
Member

@mrueg mrueg left a comment

Choose a reason for hiding this comment

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

/lgtm
/hold
Thanks!

@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 Nov 8, 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 Nov 8, 2022
@dgrisonnet
Copy link
Member

Awesome, great stuff @rexagod!

/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 Nov 8, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dgrisonnet, mrueg, rexagod

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

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow all labels/annotations for resources
4 participants