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

add annotation metrics and ability to exclude. #1041

Closed
wants to merge 1 commit into from

Conversation

jw-s
Copy link
Contributor

@jw-s jw-s commented Jan 31, 2020

What this PR does / why we need it:

  • Provides a metric which exposes annotations for that particular API kind.
  • Whitelist on all annotation related metrics, users will have to specify the annotation labels they would like to expose.
    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 annotation metrics, what is the future direction? #941

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

Welcome @jw-s!

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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jan 31, 2020
Copy link
Member

@lilic lilic left a comment

Choose a reason for hiding this comment

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

Thanks fro your PR, it's a large PR so might take a bit to review.

Do you mind fixing the docs tests, they need regeneration, that's why the tests are failing. Thanks!

pkg/options/options.go Outdated Show resolved Hide resolved
@jw-s jw-s force-pushed the annotation-metrics-whitelisting branch from 75b3eea to e803725 Compare February 3, 2020 20:11
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 13, 2020
@jw-s jw-s force-pushed the annotation-metrics-whitelisting branch from e803725 to eed98f5 Compare February 18, 2020 16:36
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 18, 2020
@jw-s jw-s force-pushed the annotation-metrics-whitelisting branch from eed98f5 to e37390d Compare February 19, 2020 15:30
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 19, 2020
@jw-s jw-s force-pushed the annotation-metrics-whitelisting branch 2 times, most recently from 3aaefe6 to e6e5749 Compare February 19, 2020 15:55
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 19, 2020
@jw-s jw-s force-pushed the annotation-metrics-whitelisting branch from e6e5749 to 26697b5 Compare February 19, 2020 16:08
@@ -6,3 +6,4 @@
| kube_certificatesigningrequest_condition | Gauge | `certificatesigningrequest`=&lt;certificatesigningrequest-name&gt; <br> `condition`=&lt;approved\|denied&gt; | STABLE |
| kube_certificatesigningrequest_labels | Gauge | `certificatesigningrequest`=&lt;certificatesigningrequest-name&gt;| STABLE |
| kube_certificatesigningrequest_cert_length | Gauge | `certificatesigningrequest`=&lt;certificatesigningrequest-name&gt;| STABLE |
| kube_certificatesigningrequest_annotations | Gauge | `certificatesigningrequest`=&lt;certificatesigningrequest-name&gt;| EXPERIMENTAL |
Copy link
Member

Choose a reason for hiding this comment

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

Why don't you document the labels for all new metrics?
E.g. for ConfigMaps, you documented label annotation_CONFIGMAP_ANNOTATION=<CONFIGMAP_ANNOTATION>, but for CertificateSigningRequest, you don't document all labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, this should be consistent.

@@ -8,7 +8,7 @@
| kube_persistentvolumeclaim_resource_requests_storage_bytes | Gauge | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; | STABLE |
| kube_persistentvolumeclaim_status_condition | Gauge | `namespace` =&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `type`=&lt;persistentvolumeclaim-condition-type&gt; <br> `status`=&lt;true\|false\|unknown&gt; | EXPERIMENTAL |
| kube_persistentvolumeclaim_status_phase | Gauge | `namespace`=&lt;persistentvolumeclaim-namespace&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `phase`=&lt;Pending\|Bound\|Lost&gt; | STABLE |

| kube_persistentvolumeclaim_annotations | Gauge | `annotation_PERSISTENTVOLUMECLAIM_ANNOTATION`=&lt;PERSISTENTVOLUMECLAIM_ANNOTATION&gt; <br> `persistentvolumeclaim`=&lt;persistentvolumeclaim-name&gt; <br> `namespace`=&lt;persistentvolumeclaim-namespace&gt; | EXPERIMENTAL |
Note:
Copy link
Member

Choose a reason for hiding this comment

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

Missing an empty line between the table and the line Note.

Copy link
Member

@olivierlemasle olivierlemasle left a comment

Choose a reason for hiding this comment

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

Two other remarks:

  • the --annotation-allowlist is not intuitive to use because filtering is done on annotations already transformed to Prometheus labels.
    For example, to see the annotation volumes.kubernetes.io/controller-managed-attach-detach, you need to pass --annotation-allowlist="volumes_kubernetes_io_controller_managed_attach_detach". That's neither the real K8s annotation, nor the effective prometheus label (which is annotation_volumes_kubernetes_io_controller_managed_attach_detach).

  • When annotations are filtered out, we have this kind of results:

     # HELP kube_namespace_annotations Kubernetes annotations converted to Prometheus labels.
     # TYPE kube_namespace_annotations gauge
     kube_namespace_annotations 1
     kube_namespace_annotations 1
     kube_namespace_annotations 1
     kube_namespace_annotations 1
     kube_namespace_annotations 1
     kube_namespace_annotations 1
    

    I guess we should have either the other labels (namespace in that case) or no metric at all...

@jw-s
Copy link
Contributor Author

jw-s commented Feb 20, 2020

Two other remarks:

  • the --annotation-allowlist is not intuitive to use because filtering is done on annotations already transformed to Prometheus labels.
    For example, to see the annotation volumes.kubernetes.io/controller-managed-attach-detach, you need to pass --annotation-allowlist="volumes_kubernetes_io_controller_managed_attach_detach". That's neither the real K8s annotation, nor the effective prometheus label (which is annotation_volumes_kubernetes_io_controller_managed_attach_detach).

  • When annotations are filtered out, we have this kind of results:

     # HELP kube_namespace_annotations Kubernetes annotations converted to Prometheus labels.
     # TYPE kube_namespace_annotations gauge
     kube_namespace_annotations 1
     kube_namespace_annotations 1
     kube_namespace_annotations 1
     kube_namespace_annotations 1
     kube_namespace_annotations 1
     kube_namespace_annotations 1
    

    I guess we should have either the other labels (namespace in that case) or no metric at all...

Completely agree, wanted to discuss this with everyone before doing the implementation. I feel we should allow (whitelist) default annotations i.e namespace or should we allow all metrics default labels?

@lilic
Copy link
Member

lilic commented Feb 27, 2020

Completely agree, wanted to discuss this with everyone before doing the implementation. I feel we should allow (whitelist) default annotations i.e namespace or should we allow all metrics default labels?

Having namespace by default included in the metric makes sense, users who don't want this can exclude this metric entirely, but not having the namespace label by default doesn't make the metric useful.

cc @brancz @tariq1890 any objections?

@jw-s
Copy link
Contributor Author

jw-s commented Mar 2, 2020

Completely agree, wanted to discuss this with everyone before doing the implementation. I feel we should allow (whitelist) default annotations i.e namespace or should we allow all metrics default labels?

Having namespace by default included in the metric makes sense, users who don't want this can exclude this metric entirely, but not having the namespace label by default doesn't make the metric useful.

cc @brancz @tariq1890 any objections?

Only problem with this approach is it will only work for namespace scoped objects , my feeling was we include all metrics default labels.

@jw-s jw-s force-pushed the annotation-metrics-whitelisting branch from 4d6c590 to 6a2e62d Compare March 2, 2020 15:56
@jw-s
Copy link
Contributor Author

jw-s commented Mar 2, 2020

Just pushed the changes to allow each resource's Labels by default. What do you guys think? Will also make the cli argument name more intuitive.

@lilic
Copy link
Member

lilic commented Mar 10, 2020

@tariq1890 @brancz please also have a look

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 10, 2020
@@ -0,0 +1,40 @@
package store
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a license header

@@ -0,0 +1,40 @@
package store
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change the name to default_labels.go?

@@ -27,6 +27,7 @@ $ kube-state-metrics -h
Usage of ./kube-state-metrics:
--add_dir_header If true, adds the file directory to the header
--alsologtostderr log to standard error as well as files
--annotation-allowlist string Comma-separated list of annotation labels to be exposed. This list comprises of exact annotation label names and/or regex patterns.
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer leaving out allowlist as a part of the param name since there is allow/deny dichotomy here.

Perhaps something along the lines of --annotation-filter?

Thoughts @brancz @lilic ?

@@ -51,6 +53,10 @@ func TestEndpointStore(t *testing.T) {
Labels: map[string]string{
"app": "foobar",
},
Annotations: map[string]string{
"whitelisted": "true",
Copy link
Contributor

Choose a reason for hiding this comment

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

The usage of whitelist and blacklist has some rather problematic undertones. As we are trying to be rid of them for the next major release, we should stick to allowed/denied.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed!

@tariq1890
Copy link
Contributor

tariq1890 commented Mar 12, 2020

@jw-s Thank you so much for your hard work with this PR. It is really appreciated :). I've provided my first round of comments. Looks like you will need to rebase the PR as well.

Sorry for the delay.

@lilic
Copy link
Member

lilic commented Oct 7, 2020

Yes if its possible to reuse them then yes! To make it clear we want to end up with the following by default:

fooresource_labels{fooresource=“fooresourcename”, namespace=“fooresourcenamespace”}

Hope that makes more sense now?

@jw-s jw-s force-pushed the annotation-metrics-whitelisting branch from f784dc7 to 2700ea5 Compare October 8, 2020 21:33
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 8, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jw-s
To complete the pull request process, please assign brancz after the PR has been reviewed.
You can assign the PR to them by writing /assign @brancz in a comment when ready.

The full list of commands accepted by this bot can be found 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

@jw-s jw-s force-pushed the annotation-metrics-whitelisting branch 5 times, most recently from 65f257f to 901150c Compare October 13, 2020 07:33
@lilic
Copy link
Member

lilic commented Oct 13, 2020

@jw-s is this ready for another review?

@jw-s
Copy link
Contributor Author

jw-s commented Oct 13, 2020

@lilic Yeah, though e2e tests are failing and no useful output in the logs, need to check why...

@jw-s jw-s force-pushed the annotation-metrics-whitelisting branch from 901150c to ad1105a Compare October 14, 2020 08:24
@jw-s
Copy link
Contributor Author

jw-s commented Oct 27, 2020

@lilic Sorry i didn't have time to check this. Would be nice to get this in before the cut. Any way i can test the e2e locally?

@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 27, 2020
@k8s-ci-robot
Copy link
Contributor

@jw-s: PR needs rebase.

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.

@lilic
Copy link
Member

lilic commented Oct 27, 2020

Yes you should be able to run them with make e2e and running docker https://github.com/kubernetes/kube-state-metrics/tree/master/tests

@lilic
Copy link
Member

lilic commented Oct 27, 2020

@jw-s could you possibly split the adding default labels into a separate PR and we can merge as bugfix in 2.0, as those should land in 2.0 release and annotation label metrics can land in a future release. Sounds good?

@jw-s
Copy link
Contributor Author

jw-s commented Oct 27, 2020

@lilic Yeah I'll work on a PR tomorrow morning and hopefully get it done before the afternoon so it can be taken in the 2.0 cut.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 25, 2021
@Mepemotrarial
Copy link

@jw-s Any progress on this?

@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 7, 2021
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

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.

@sepich sepich mentioned this pull request Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

annotation metrics, what is the future direction?
9 participants