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

Don't crash on non-existent path values #1998

Merged
merged 2 commits into from
Feb 17, 2023
Merged

Conversation

rexagod
Copy link
Member

@rexagod rexagod commented Feb 16, 2023

What this PR does / why we need it: Don't crash on non-existent path values in CRS.

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

Which issue(s) this PR fixes: Fixes #1992

Don't crash on non-existent path values in CRS.

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 16, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If kube-state-metrics contributors determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 16, 2023
@rexagod
Copy link
Member Author

rexagod commented Feb 16, 2023

/cc @mrueg

@@ -430,6 +430,10 @@ func (c compiledGauge) value(it interface{}) (*eachValue, error) {
Value: 0,
}, nil
}
// no it means no iterables were passed down, meaning that the path resolution never happened
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 moved to the beginning of the function so we can return the error early?

Copy link
Member Author

@rexagod rexagod Feb 17, 2023

Choose a reason for hiding this comment

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

That'll fail cases that expect a zero in case of nil.

// If `valueFrom` was not resolved, respect `NilIsZero` and return.
if got == nil {
if c.NilIsZero {
return &eachValue{
Labels: labels,
Value: 0,
}, nil
}
// no it means no iterables were passed down, meaning that the path resolution never happened
if it == nil {
return nil, fmt.Errorf("got nil while resolving path")
}
// Don't error if there was not a type-casting issue (`toFloat64`), but rather a failed lookup.
return nil, nil
}

// no it means no iterables were passed down, meaning that the path resolution never happened
if it == nil {
return nil, fmt.Errorf("got nil while resolving path")
}
// Don't error if there was not a type-casting issue (`toFloat64`), but rather a failed lookup.
Copy link
Member

Choose a reason for hiding this comment

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

The failed lookup is handled now, can you update this comment?

@mrueg
Copy link
Member

mrueg commented Feb 17, 2023

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 17, 2023
@k8s-ci-robot k8s-ci-robot merged commit d498cab into kubernetes:main Feb 17, 2023
@mrueg mrueg mentioned this pull request Feb 22, 2023
@rexagod rexagod mentioned this pull request May 23, 2023
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. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on nonexistent metric paths in custom resources
3 participants