Skip to content

feat: deduplicate validation errors and increment metric #132613

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 1 commit into
base: master
Choose a base branch
from

Conversation

gavinkflam
Copy link
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Several resources currently emit duplicate validation errors during update operations. This results in bloated and confusing API responses and redundant processing. I've submitted a few PRs to address specific cases, but there are likely many more instances still present in the codebase.

Detecting these duplicates is challenging because kubectl deduplicates error messages before displaying them to the user and hiding the issue.

This PR introduces server-side deduplication of validation errors before the response is returned. This helps produce cleaner, more concise responses and reduces unnecessary payload size. Additionally, a new metric is introduced to track the number of duplicate errors detected, providing visibility into remaining problem areas and helping to identify opportunities for further cleanup.

Which issue(s) this PR is related to:

Fixes #130656

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Updated resource update API to deduplicate validation errors and increment a metric.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 30, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines 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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 30, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @gavinkflam. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added area/apiserver area/stable-metrics Issues or PRs involving stable metrics sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 30, 2025
@k8s-triage-robot
Copy link

This PR may require stable metrics review.

Stable metrics are guaranteed to not change. Please review the documentation for the requirements and lifecycle of stable metrics and ensure that your metrics meet these guidelines.

@gavinkflam gavinkflam force-pushed the 130656-duplicate-validation-errors-metric branch from 1fced79 to fd84973 Compare July 1, 2025 02:41
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gavinkflam
Once this PR has been reviewed and has the lgtm label, please assign deads2k for approval. 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

@k8s-ci-robot k8s-ci-robot removed sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. area/stable-metrics Issues or PRs involving stable metrics labels Jul 1, 2025
@gavinkflam
Copy link
Contributor Author

Changed the metric to alpha according to KEP-1209.

@gavinkflam
Copy link
Contributor Author

cc @thockin @jpbetz @deads2k @seans3

// and increment duplicate validation error metric when duplicates are found.
func DeduplicateValidationErrorsAndUpdateMetric(qualifiedKind schema.GroupKind, operation string, errs field.ErrorList) field.ErrorList {
uniqueErrs := field.ErrorList{}
errsSet := sets.New[string]()
Copy link
Member

Choose a reason for hiding this comment

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

given how few errors there are, we should just make([]string, 0, len(errs)), do slices.Contains() for lookup, and append to the list if it is not found.

@@ -52,6 +53,15 @@ var validationMetricsInstance = &validationMetrics{
StabilityLevel: metrics.BETA,
},
),
DuplicateValidationErrorCounter: metrics.NewCounterVec(
Copy link
Member

Choose a reason for hiding this comment

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

@jpbetz -- does this need a KEP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kubectl dedups API errors and hides bugs
4 participants