Skip to content

feat(telemetry): extend TelemetryPolicy with logging stanza - #2179

Open
andresllh wants to merge 2 commits into
Kuadrant:mainfrom
andresllh:feat/telemetry-logging-fields
Open

feat(telemetry): extend TelemetryPolicy with logging stanza#2179
andresllh wants to merge 2 commits into
Kuadrant:mainfrom
andresllh:feat/telemetry-logging-fields

Conversation

@andresllh

@andresllh andresllh commented Aug 12, 2026

Copy link
Copy Markdown

Summary

  • Extends TelemetryPolicy CRD with a logging stanza (logging.default.fields) for configurable audit field enrichment on auth decision logs
  • Adds KuadrantLoggingBinding helper and KuadrantLoggingPrefix constant in the extension types package
  • Extends the reconciler to iterate logging fields via AddDataTo, routing them through the existing domain-agnostic wasm metadata pipeline as io.kuadrant.logging.fields filter metadata
  • Regenerates deepcopy methods and CRD manifests
  • Adds unit tests for binding functions, buildMetadataContext domain routing with mixed metrics/logging domains, and reconciler behavior (logging-only, mixed, error propagation, empty spec)

Example TelemetryPolicy

apiVersion: extensions.kuadrant.io/v1alpha1
kind: TelemetryPolicy
metadata:
  name: audit-logging
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: Gateway
    name: my-gateway
  logging:
    default:
      fields:
        client_identity: auth.identity.sub
        request_path: request.path

Consumer

The companion Authorino PR (Kuadrant/authorino#671) reads io.kuadrant.logging.fields from CheckRequest filter metadata and appends the resolved fields to auth decision log output.

Test plan

  • KuadrantLoggingBinding / KuadrantMetricBinding unit tests pass
  • buildMetadataContext correctly groups logging.fields bindings under io.kuadrant.logging.fields metadata key
  • buildMetadataContext correctly separates mixed metrics.labels and logging.fields bindings into distinct sorted entries
  • DomainAndFieldName splits logging.fields.client_identity → domain=logging.fields, field=client_identity
  • Reconciler passes logging fields to AddDataTo with correct domain, binding name, and expression
  • Reconciler handles mixed metrics + logging in a single policy
  • Reconciler propagates AddDataTo errors correctly
  • Reconciler handles empty spec (no metrics, no logging) without error
  • make generate and make extensions-manifests produce no diff (generated files are current)
  • go vet clean, go fmt clean
  • Full go test -tags unit ./... — all new tests pass; 4 pre-existing OIDC failures unrelated

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added optional logging configuration to telemetry policies.
    • Supports CEL-based enrichment of authentication decision log records with derived fields.
    • Metrics-only, logging-only, or combined telemetry configurations are now supported.
  • Documentation
    • Updated telemetry policy descriptions and schema documentation to cover logging field enrichment.
  • Tests
    • Added coverage for logging configuration, combined telemetry settings, validation errors, and empty policies.

Add a logging stanza to TelemetryPolicy enabling configurable audit
field enrichment for auth decision logs. The reconciler passes logging
field bindings through the existing domain-agnostic wasm metadata
pipeline, producing io.kuadrant.logging.fields filter metadata that
Authorino consumes to enrich log output.

- Add LoggingSpec/LoggingConfig types with fields map
- Add KuadrantLoggingBinding helper and KuadrantLoggingPrefix constant
- Extend reconcileSpec to iterate logging fields via AddDataTo
- Regenerate deepcopy and CRD manifests
- Add unit tests for binding functions, domain routing, and reconciler

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Andres Llausas <allausas@redhat.com>
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@andresllh, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 4 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: df94c585-7025-4780-9b15-4999b0ec32b8

📥 Commits

Reviewing files that changed from the base of the PR and between 44cf8db and 8da6385.

📒 Files selected for processing (5)
  • cmd/extensions/telemetry-policy/api/v1alpha1/telemetrypolicy_types.go
  • cmd/extensions/telemetry-policy/api/v1alpha1/zz_generated.deepcopy.go
  • cmd/extensions/telemetry-policy/config/crd/bases/extensions.kuadrant.io_telemetrypolicies.yaml
  • cmd/extensions/telemetry-policy/internal/controller/telemetrypolicy_reconciler.go
  • cmd/extensions/telemetry-policy/internal/controller/telemetrypolicy_reconciler_test.go
📝 Walkthrough

Walkthrough

TelemetryPolicy now supports optional CEL-derived logging fields. Reconciliation adds these fields to request data. Binding helpers and WASM metadata tests cover logging and metric domains.

Changes

Telemetry logging support

Layer / File(s) Summary
Logging API and CRD contract
cmd/extensions/telemetry-policy/api/v1alpha1/telemetrypolicy_types.go, cmd/extensions/telemetry-policy/api/v1alpha1/zz_generated.deepcopy.go, cmd/extensions/telemetry-policy/config/crd/bases/...
Adds optional logging configuration and CEL field expressions. Makes metrics optional. Updates the CRD schema and deep-copy methods.
Logging field reconciliation
cmd/extensions/telemetry-policy/internal/controller/telemetrypolicy_reconciler.go, cmd/extensions/telemetry-policy/internal/controller/telemetrypolicy_reconciler_test.go
Adds logging fields through AddDataTo. Tests successful processing, mixed metrics and logging, errors, and empty specifications.
Logging binding and metadata validation
pkg/extension/types/types.go, pkg/extension/types/types_test.go, internal/wasm/action_spec_test.go
Adds logging binding helpers. Tests binding names and WASM metadata grouping, preservation, and ordering.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: adam-cattermole

Poem

A rabbit adds fields by moonlight bright,
CEL expressions hop into sight.
Metrics and logging share the trail,
Bindings carry each detail.
WASM sorts the records right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a logging stanza to TelemetryPolicy.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
cmd/extensions/telemetry-policy/internal/controller/telemetrypolicy_reconciler_test.go (1)

173-179: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the error status contents.

The test only checks that status is non-nil. It also passes if reconcileSpec returns an enforced or otherwise incorrect status together with expectedErr.

Inspect calculateErrorStatus and assert the expected condition status, reason, and observed generation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@cmd/extensions/telemetry-policy/internal/controller/telemetrypolicy_reconciler_test.go`
around lines 173 - 179, Strengthen the test around reconcileSpec by validating
the returned error status contents rather than only checking that status is
non-nil. Use calculateErrorStatus as the expected shape and assert the condition
status, reason, and observed generation match the expected values while
preserving the existing error assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/extensions/telemetry-policy/api/v1alpha1/telemetrypolicy_types.go`:
- Around line 93-97: The TelemetryPolicy Fields map currently allows keys
containing periods that are later misinterpreted as nested logging paths. Update
the API validation for Fields keys to reject periods at admission, preserving
literal field-name behavior; regenerate the extension API DeepCopy output with
make generate, and add a regression test covering a key such as request.user.id.
- Around line 49-54: The optional Metrics and Logging fields in the telemetry
policy type must be pointers so omitempty removes them when unset. Update
reconcileSpec to safely handle nil Metrics and Logging values, then run make
generate and add a serialization test confirming a targetRef-only policy omits
both fields.

---

Nitpick comments:
In
`@cmd/extensions/telemetry-policy/internal/controller/telemetrypolicy_reconciler_test.go`:
- Around line 173-179: Strengthen the test around reconcileSpec by validating
the returned error status contents rather than only checking that status is
non-nil. Use calculateErrorStatus as the expected shape and assert the condition
status, reason, and observed generation match the expected values while
preserving the existing error assertion.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1b95df7c-2a1d-4ef0-a3c0-65742be71906

📥 Commits

Reviewing files that changed from the base of the PR and between b1889a0 and 44cf8db.

📒 Files selected for processing (8)
  • cmd/extensions/telemetry-policy/api/v1alpha1/telemetrypolicy_types.go
  • cmd/extensions/telemetry-policy/api/v1alpha1/zz_generated.deepcopy.go
  • cmd/extensions/telemetry-policy/config/crd/bases/extensions.kuadrant.io_telemetrypolicies.yaml
  • cmd/extensions/telemetry-policy/internal/controller/telemetrypolicy_reconciler.go
  • cmd/extensions/telemetry-policy/internal/controller/telemetrypolicy_reconciler_test.go
  • internal/wasm/action_spec_test.go
  • pkg/extension/types/types.go
  • pkg/extension/types/types_test.go

Comment thread cmd/extensions/telemetry-policy/api/v1alpha1/telemetrypolicy_types.go Outdated
…in field names

Address CodeRabbit review feedback:
- Change Metrics and Logging to pointer types so omitempty correctly
  omits them when unset, preventing CRD validation errors from Go clients
- Add nil guards in reconcileSpec for both optional specs
- Add CEL validation rule on LoggingConfig.Fields to reject period-
  containing keys that would be misrouted by DomainAndFieldName
- Regenerate deepcopy and CRD manifests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Andres Llausas <allausas@redhat.com>
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.

1 participant