Skip to content

fix(normalizers): include resource context in failed normalization log#27769

Open
rafaelmfried wants to merge 1 commit intoargoproj:masterfrom
rafaelmfried:fix/normalization-log-resource-context
Open

fix(normalizers): include resource context in failed normalization log#27769
rafaelmfried wants to merge 1 commit intoargoproj:masterfrom
rafaelmfried:fix/normalization-log-resource-context

Conversation

@rafaelmfried
Copy link
Copy Markdown

Closes #14148.

What

Adds the resource's group, kind, name, and namespace as structured fields on the Failed to apply normalization debug log in util/argo/normalizers/diff_normalizer.go.

Why

The original message gave operators no way to identify which resource the failing patch was targeting. With cluster-wide ignoreDifferences rules this can fire dozens of times per reconcile loop, producing noise that's hard to act on.

Reporter's exact pain in the issue:

I have no idea what it's doing, since apparently it's trying to remove /status from something but it doesn't tell me what the something it's operating on — generally speaking that's an important detail.

Diff

// before
log.Debugf("Failed to apply normalization: %v", err)

// after
gvk := un.GroupVersionKind()
log.WithFields(log.Fields{
    "group":     gvk.Group,
    "kind":      gvk.Kind,
    "name":      un.GetName(),
    "namespace": un.GetNamespace(),
}).Debugf("Failed to apply normalization patch: %v", err)

Scope decisions (open to changing in review)

Choice Why
shouldLogError filter Left intact Already silences the two most common false-positive paths (Unable to remove nonexistent key, remove operation does not apply: doc is missing path) that triggered the original report.
Patch path exposure Not added to the log Would require extending the normalizerPatch interface (line 27) — disproportionate to the bug. Resource context alone already answers the reporter's "some portion of docData" ask. Happy to follow up in a separate PR if the team wants the path too.
Wording Failed to apply normalization patch (kept "Failed", added "patch" for precision) The reporter suggested it shouldn't say "Failed" if purely informational — but after shouldLogError filtering, what reaches this branch is a real failure to apply the patch. Open to Skipped normalization patch if you prefer a less alarming tone.

Test

TestNormalizeFailureLogIncludesResourceContext in diff_normalizer_test.go — reuses the existing helpful-error trigger pattern from TestJQPathExpressionReturnsHelpfulError and asserts via test.CaptureLogEntries that kind=ConfigMap and name=my-configmap appear in the captured output along with the new message.

=== RUN   TestNormalizeFailureLogIncludesResourceContext
--- PASS: TestNormalizeFailureLogIncludesResourceContext (0.00s)
PASS
ok      github.com/argoproj/argo-cd/v3/util/argo/normalizers    0.888s

Full package suite (go test ./util/argo/normalizers/...) is green locally — 15/15.

Notes

  • This is my first PR to argo-cd. Signed-off-by is included; CLA on file via the GitHub workflow.
  • Linked discussion in the issue thread (Change Failed to apply normalization warning #14148) before opening — @colecschmidt had previously expressed interest but no PR landed in 11 days, so I picked it up after pinging the issue.

@rafaelmfried rafaelmfried requested a review from a team as a code owner May 9, 2026 23:37
@bunnyshell
Copy link
Copy Markdown

bunnyshell Bot commented May 9, 2026

✅ Preview Environment deployed on Bunnyshell

Component Endpoints
argocd https://argocd-qfzutu.bunnyenv.com/
argocd-ttyd https://argocd-web-cli-qfzutu.bunnyenv.com/

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔴 /bns:stop to stop the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

The "Failed to apply normalization" debug message previously logged only
the underlying error, leaving operators with no way to identify which
resource the patch was targeting. With cluster-wide ignoreDifferences
rules, this can fire dozens of times per reconcile loop with no signal
about the offending resource.

Add the resource's group, kind, name, and namespace as structured fields
on the existing Debugf call so the log entry is actionable. The
shouldLogError filter is left intact — it already silences the most
common "nonexistent key" / "doc is missing path" cases that triggered
the original report.

The normalizerPatch interface is intentionally not extended to expose
the JSON-patch path itself; the resource context already addresses the
reporter's "some portion of docData" ask without expanding scope.

Closes argoproj#14148

Signed-off-by: Rafael Moura Friederick <rafael.mf.documents@gmail.com>
@rafaelmfried rafaelmfried force-pushed the fix/normalization-log-resource-context branch from 9c85370 to 410e2b6 Compare May 9, 2026 23:42
@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.97%. Comparing base (5ec0603) to head (410e2b6).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #27769   +/-   ##
=======================================
  Coverage   63.96%   63.97%           
=======================================
  Files         421      421           
  Lines       57774    57780    +6     
=======================================
+ Hits        36954    36963    +9     
+ Misses      17339    17337    -2     
+ Partials     3481     3480    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jsoref
Copy link
Copy Markdown
Member

jsoref commented May 10, 2026

Seems reasonable to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change Failed to apply normalization warning

2 participants