Skip to content

feat(googlepolicy): add LogTransformPolicy (LogAdd) compiler and evaluator - #703

Draft
rafaelwestphal wants to merge 1 commit into
masterfrom
westphalrafael/log-transform-policy
Draft

rafaelwestphal wants to merge 1 commit into
masterfrom
westphalrafael/log-transform-policy

Conversation

@rafaelwestphal

Copy link
Copy Markdown
Contributor

Summary

Implements LogTransformPolicy (LogAdd operation) end-to-end across protobuf definitions, pkg/googlepolicy, googlepolicyprocessor, googlecontrolplaneprovider, and the policy integration test suite:

  • Protobuf (proto/policy/v1alpha1/log_transform_policy.proto): Defines LogTransformPolicy (id, repeated LogMatcher matches, repeated LogAdd add) and LogAdd (LogFieldSelector target, Value value, bool upsert) with generated Go bindings and wire/protojson round-trip tests.
  • Shared Log Matcher & Attribute Setter Engine (pkg/googlepolicy/internal/matcher):
    • Extracts CompiledLogMatcher, CompileLogMatcher, and CompileLogExtractor into internal/matcher/log.go so logfilter and logtransform share log matching logic as peers without sibling imports.
    • Adds CompilePathSetter (supporting nested AttributePath map creation without leaving partial maps when upsert: false rejects an existing leaf or non-map ancestor) and CompileValueSetter.
  • Compiler & Evaluator (pkg/googlepolicy/logtransform):
    • Implements googlepolicy.LogTransformPolicyEvaluator (TransformLog(ctx LogContext) TransformResult returning TransformNoMatch | TransformModified) for PolicyType = "log_transform".
    • Supports all valid LogFieldSelector targets (log_attribute, resource_attribute, scope_attribute, record_field [BODY, SEVERITY_TEXT, SEVERITY_NUMBER, TRACE_ID, SPAN_ID], and scope_field [NAME, VERSION; SCHEMA_URL is rejected at compile time]).
    • Includes unit tests (policy_test.go, 98.9% coverage) and fuzz tests (fuzz_test.go, FuzzLogTransformPolicy).
  • Two-Stage Processor Pipeline (googlepolicyprocessor):
    • Evaluates Stage 1 (log_filter) before Stage 2 (log_transform) in deterministic PolicyName() order; dropped log records never enter Stage 2.
    • Records result="transformed" on processor_googlepolicy_records and processor_googlepolicy_policy_records (while preserving result="kept" on processor_googlepolicy_policy_records when a record is exempted by an ACTION_KEEP filter policy and subsequently transformed).
  • Integration Tests (integration_test/policy_test):
    • Adds golden test testdata/log_transform_and_filter_ordering and TestLogFilterKeepAndTransformSelfMetrics.

@rafaelwestphal
rafaelwestphal force-pushed the westphalrafael/log-transform-policy branch 3 times, most recently from 7785eb8 to dc3716d Compare October 13, 2026 18:16
@rafaelwestphal
rafaelwestphal force-pushed the westphalrafael/log-transform-policy branch 5 times, most recently from 8e71da9 to b7aef05 Compare October 16, 2026 18:32
@rafaelwestphal
rafaelwestphal force-pushed the westphalrafael/log-transform-policy branch from b7aef05 to d04e30c Compare October 17, 2026 00:00
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