Skip to content

feat: include reason label to kube_deployment_status_condition #2719

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

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

Conversation

Rishab87
Copy link
Contributor

@Rishab87 Rishab87 commented Aug 4, 2025

What this PR does / why we need it:
Building upon the work of #2146, I've addressed the reviews and created this.

This PR adds reason label to kube_deployment_status_condition metrics.

It's necessary to distinguish between Progressing Deployment and Complete Deployment .

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)
no changes in 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 #1991

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 4, 2025
@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 4, 2025
metric.LabelValues = append([]string{string(c.Type)}, metric.LabelValues...)
reason := c.Reason
if _, ok := allowedDeploymentReasons[reason]; !ok {
reason = ""
Copy link
Member

Choose a reason for hiding this comment

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

should this be empty? or should this be "unknown"

CC: @rexagod

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with an empty string for cleaner queries, but I'm open to changing it if you want.

Copy link
Member

Choose a reason for hiding this comment

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

it depends, is the reason ever empty? then we could use unknown to differ between an empty reason and something we don't recognize.

if the reason field is never empty, this approach is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah right, seems like reason field can be empty, I've changed it to unknown, thanks for pointing out!

@dgrisonnet
Copy link
Member

/assign @mrueg
/triage accepted

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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Rishab87
Once this PR has been reviewed and has the lgtm label, please ask for approval from mrueg. For more information see the 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

@Rishab87
Copy link
Contributor Author

@mrueg I've made the changes, can you have a look again?

metric.LabelKeys = []string{"condition", "status"}
metric.LabelValues = append([]string{string(c.Type)}, metric.LabelValues...)
reason := c.Reason
if _, ok := allowedDeploymentReasons[reason]; !ok {
Copy link
Member

@mrueg mrueg Aug 11, 2025

Choose a reason for hiding this comment

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

if it's empty, will it still be unknown?
Can you create a test with the reason field being empty as well as with one test with a non allowed deployment reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that was the case earlier, fixed it if its empty then it will remain empty and will show unknown if reason is not in the allowed list, also added the tests for both cases.

@Rishab87
Copy link
Contributor Author

@mrueg made changes, can you have another look?

@@ -183,8 +183,10 @@ func deploymentMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
metric := m

reason := c.Reason
if _, ok := allowedDeploymentReasons[reason]; !ok {
reason = "unknown"
if reason != "" {
Copy link
Member

@mrueg mrueg Aug 11, 2025

Choose a reason for hiding this comment

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

Can we add "" to the allowedDeploymentReasons instead?

Copy link
Contributor Author

@Rishab87 Rishab87 Aug 11, 2025

Choose a reason for hiding this comment

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

yeah, added it

@Rishab87
Copy link
Contributor Author

@mrueg I've addressed the reviews, can you look again?

Comment on lines +44 to +46
var (
allowedDeploymentReasons = map[string]struct{}{
"MinimumReplicasAvailable": {},
Copy link
Member

Choose a reason for hiding this comment

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

Looking at these strings again
https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/deployment/util/deployment_util.go#L67

Can we refer to these here instead and create a complete list based on what's available in deployment_util.go?

Suggested change
var (
allowedDeploymentReasons = map[string]struct{}{
"MinimumReplicasAvailable": {},
import deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
var (
allowedDeploymentReasons = map[string]struct{}{
deploymentutil.MinimumReplicasAvailable: {},

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. size/M Denotes a PR that changes 30-99 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.

Include reason label to the kube_deployment_status_condition metric
4 participants