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(custom resource state metrics): correctly convert status condition Unknown to a valid value #2536

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Haleygo
Copy link

@Haleygo Haleygo commented Oct 29, 2024

What this PR does / why we need it:

According to https://github.com/kubernetes/kube-state-metrics/blob/main/docs/metrics/extend/customresourcestate-metrics.md#gauge

This will work for kubernetes controller CRs which expose status conditions according to the kubernetes api (https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Condition):

ConditionUnknown = "Unknown" should be converted corrctly to a valid value, and more like 0.0 instead of 1.0.

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)

Does not change cardinality.

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 #2439

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 29, 2024
@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 29, 2024
@mrueg
Copy link
Member

mrueg commented Oct 30, 2024

Thanks for the contribution!
I don't think 0.0 is the right way to treat an unknown value as it could be misleading. I think a possible option might be -1.0 for any unknown value. (but I would love to see others chime in on that as well).

@rexagod @dgrisonnet @CatherineF-dev wdyt?

@CatherineF-dev
Copy link
Contributor

Agree on -1 to distinguish this unknown with others.

@richabanker
Copy link
Contributor

/triage accepted
/assign @mrueg

@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 31, 2024
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 4, 2024
@Haleygo
Copy link
Author

Haleygo commented Nov 4, 2024

@mrueg Thanks for reviewing! I have updated the value and doc, please check.

@mrueg mrueg changed the title fix(custom resource state metrics): corrctly convert status condition Unknown to a valid value fix(custom resource state metrics): correctly convert status condition Unknown to a valid value Nov 5, 2024
Copy link

@itaiatu itaiatu left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot
Copy link
Contributor

@itaiatu: changing LGTM is restricted to collaborators

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-sigs/prow repository.

@itaiatu
Copy link

itaiatu commented Nov 6, 2024

We also encountered this issue and this small fix will solve it.

@CatherineF-dev
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 6, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: CatherineF-dev, Haleygo, itaiatu
Once this PR has been reviewed and has the lgtm label, please ask for approval from mrueg. For more information see the Kubernetes Code Review Process.

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

@CatherineF-dev
Copy link
Contributor

Hi @mrueg, could you help add this into v2.14.0 milestone? https://github.com/kubernetes/kube-state-metrics/milestone/7

Thx

@mrueg mrueg added this to the v2.14.0 milestone Nov 6, 2024
@mrueg
Copy link
Member

mrueg commented Nov 6, 2024

@dgrisonnet made me aware of

kube_node_status_condition{condition="CustomizedType",node="127.0.0.1",status="false"} 0
kube_node_status_condition{condition="CustomizedType",node="127.0.0.1",status="true"} 1
kube_node_status_condition{condition="CustomizedType",node="127.0.0.1",status="unknown"} 0
in which we expose the status Unknown as 0 as well. Could you change it back to 0 instead of -1 for consistency?
Thanks and apologies for the extra work!

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. 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. 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.

Metric with type Gauge throwing errors with no reason.
6 participants