Skip to content

[log] Add debug logging to guard policy JSON unmarshaling#3733

Merged
lpcox merged 1 commit intomainfrom
log/add-debug-logging-guard-policy-6d082e3f0467f0f8
Apr 14, 2026
Merged

[log] Add debug logging to guard policy JSON unmarshaling#3733
lpcox merged 1 commit intomainfrom
log/add-debug-logging-guard-policy-6d082e3f0467f0f8

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

Adds 5 targeted logGuardPolicy debug log calls to internal/config/guard_policy.go — previously unlogged but important functions in the DIFC guard policy parsing pipeline.

Changes

File: internal/config/guard_policy.go

Three functions now have debug logging:

GuardPolicy.UnmarshalJSON

  • Logs parsed key count after initial JSON decode (helps diagnose unexpected policy structures)
  • Logs resolved policy type (allow-only vs write-sink) before returning

AllowOnlyPolicy.UnmarshalJSON

  • Logs field count on entry (visibility into how many fields are being parsed)
  • Logs parsed repos type and minIntegrity value on successful parse

normalizeAndValidateScopeArray

  • Logs scope entry count before validation loop begins

Quality

  • ✅ Exactly 1 file modified (focused PR)
  • ✅ No test files modified
  • ✅ Reuses existing logGuardPolicy = logger.New("config:guard_policy") logger — no new declaration added
  • ✅ Logger naming follows pkg:filename convention (already established in the file)
  • ✅ No side effects in logger arguments — only pre-computed values (len(raw), p.MinIntegrity, etc.)
  • ✅ Messages are meaningful and helpful for troubleshooting policy parse failures
  • ✅ No duplication with existing log calls

Context

guard_policy.go is 800 lines with complex DIFC guard policy parsing/validation logic. The UnmarshalJSON functions are called during gateway startup and whenever policy JSON is parsed. These are the first places where malformed configs would fail, making entry/exit logging particularly useful for diagnosing configuration issues.

Generated by Go Logger Enhancement · ● 9M ·

Add 5 targeted logGuardPolicy calls to previously unlogged functions:
- GuardPolicy.UnmarshalJSON: log parsed key count and resolved policy type
- AllowOnlyPolicy.UnmarshalJSON: log field count on entry and parsed fields on success
- normalizeAndValidateScopeArray: log scope entry count before validation

All logging uses the existing logGuardPolicy logger and pre-computed
values only — no side effects in logger arguments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions bot added automation enhancement New feature or request labels Apr 14, 2026
@lpcox lpcox marked this pull request as ready for review April 14, 2026 14:45
Copilot AI review requested due to automatic review settings April 14, 2026 14:45
@lpcox lpcox merged commit f72afef into main Apr 14, 2026
3 checks passed
@lpcox lpcox deleted the log/add-debug-logging-guard-policy-6d082e3f0467f0f8 branch April 14, 2026 14:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds additional debug logging to the guard policy JSON unmarshaling and scope validation path to improve troubleshooting of malformed or unexpected DIFC guard policy configurations during config load.

Changes:

  • Log decoded top-level key count and resolved policy type during GuardPolicy.UnmarshalJSON.
  • Log decoded field count and parsed values during AllowOnlyPolicy.UnmarshalJSON.
  • Log scope entry count at the start of normalizeAndValidateScopeArray.
Show a summary per file
File Description
internal/config/guard_policy.go Adds targeted debug logs around guard policy JSON decoding and scope validation to improve observability during config parsing.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

return fmt.Errorf("allow-only must include min-integrity")
}

logGuardPolicy.Printf("UnmarshalJSON: allow-only policy parsed, repos=%T, minIntegrity=%s", p.Repos, p.MinIntegrity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants