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

store: add kube_node_role metric #877

Merged
merged 1 commit into from
Sep 5, 2019
Merged

store: add kube_node_role metric #877

merged 1 commit into from
Sep 5, 2019

Conversation

abursavich
Copy link
Contributor

What this PR does / why we need it:
This adds a kube_node_role metric for node roles based on node-role.kubernetes.io/<ROLE> node labels.

This is implemented like kube_node_spec_taint where each taint is a separate metric in the same family, as opposed to kube_node_labels where each label is mapped to the same metric and family.

I've tried to implement this with recording rules on top of kube_node_labels, but an empty node-role.kubernetes.io/<ROLE> label value is valid and, as far as i can tell, there's no way to differentiate between a missing label and an empty value in a query. Further, every possible role must be known in advance to query for the expected labels.

Which issue(s) this PR fixes
N/A

@k8s-ci-robot
Copy link
Contributor

Welcome @abursavich!

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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 30, 2019
@brancz
Copy link
Member

brancz commented Sep 2, 2019

Nominally this is not really aligned with how kube state metrics works, however I’m inclined to accept something like this as node labels are treated with stability guarantees in kubernetes (at least this label) and it is indeed difficult to do what you are trying to accomplish.

@lilic @tariq1890

@abursavich
Copy link
Contributor Author

abursavich commented Sep 2, 2019

@brancz, I'm not sure this would be more palatable, but in the interest of exploration... another option would be to export a kube_node_label metric with stable label dimensions and higher series cardinality. This could be in addition to or in place of the kube_node_labels metric.

# BEFORE
kube_node_labels{label_foo="bar",label_node_role_kubernetes_io_master="",node="127.0.0.1"} 1

# AFTER
kube_node_label{label="foo",value="bar",node="127.0.0.1"} 1
kube_node_label{label="node-role.kubernetes.io/master",value="",node="127.0.0.1"} 1

I have actually wished it was that way for the purposes of other queries in the past, but not just for nodes... for deployments, pods, etc.

As an additional benefit, you would get the real label names without special characters replaced.

@tariq1890
Copy link
Contributor

I am on the fence here on this. While I wish this was made more contractually bound via APIObject, I also don't want it to be a blocker. I'll leave it to @lilic to provide her opinions on this.

@lilic
Copy link
Member

lilic commented Sep 3, 2019

While I wish this was made more contractually bound via APIObject

I agree!

Asking the node team on this, to see if they have plans to change this. If it will stay this way I would say let's add it, unless there is any other place in k8s we think this metric might be better off?

something like this as node labels are treated with stability guarantees in kubernetes

Dear @kubernetes/sig-node-api-reviews can you let us know if you have any plans to change the node-role.kubernetes.io/<ROLE> in the near or far future, thank you!

@k8s-ci-robot k8s-ci-robot added sig/node Categorizes an issue or PR as relevant to SIG Node. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels Sep 3, 2019
@fejta-bot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@lilic lilic removed the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Sep 3, 2019
@abursavich
Copy link
Contributor Author

abursavich commented Sep 3, 2019

I would like to be very explicit that this is a specific case of two generic issues which are the result of mapping dynamic object labels to dynamic metric dimensions, instead of fixing the dimensions and allowing the series cardinality to be dynamic per object.

  1. It is not possible to query for objects with labels that exist but have empty values, as prometheus treats these the same as metrics without the labels.
  2. It is not possible to use prometheus' value matching and parsing functionality on object label keys since they are munged into prometheus label keys.

Reiterating my previous comment, this is an alternative solution to the underlying problems without tying kube-state-metrics to any particular label conventions:

# BEFORE
kube_node_labels{label_foo="bar",label_node_role_kubernetes_io_master="",node="127.0.0.1"} 1

# AFTER
kube_node_label{label="foo",value="bar",node="127.0.0.1"} 1
kube_node_label{label="node-role.kubernetes.io/master",value="",node="127.0.0.1"} 1

One downside would be that queries on multiple labels would become more complicated joins:

# BEFORE
kube_node_labels{label_foo="bar",label_baz="qux"}

# AFTER
kube_node_label{label="foo",value="bar"} and on(node) kube_foo_label{label="baz",value="qux"}

@derekwaynecarr
Copy link
Member

Related discussion about appropriate use of node role labels:
kubernetes/enhancements#1144

@derekwaynecarr
Copy link
Member

The tldr is that the node role label is not going away, but its an implementation detail of the cluster topology and not something that kubernetes components should imply behavior around in favor of more intent based labels (exclude-disruption, etc.). That said, the role of the node should be stable for the life of the node.

@brancz
Copy link
Member

brancz commented Sep 5, 2019

Got it, thanks @derekwaynecarr. I think we're good with moving forward with this. The only thing I would like to do as this is a new metric and in general a new method for kube-state-metrics, mark this as experimental for now. Then this lgtm to merge. Can you mark this metric as experimental in the docs @abursavich ? 🙂

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.

Few comments but we decided we want to proceed with this, thank you so much for the PR!

@brancz
Copy link
Member

brancz commented Sep 5, 2019

/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 5, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abursavich, brancz

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 Sep 5, 2019
@k8s-ci-robot k8s-ci-robot merged commit 087e74f into kubernetes:master Sep 5, 2019
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. sig/node Categorizes an issue or PR as relevant to SIG Node. 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.

7 participants