Skip to content

add pprof labels for rules#755

Open
YakirOren wants to merge 2 commits intomainfrom
feature/pprof-labels
Open

add pprof labels for rules#755
YakirOren wants to merge 2 commits intomainfrom
feature/pprof-labels

Conversation

@YakirOren
Copy link
Copy Markdown
Contributor

@YakirOren YakirOren commented Mar 25, 2026

Summary by CodeRabbit

  • Chores
    • Added targeted runtime profiling around event processing and rule evaluation to improve observability and performance diagnostics. Instrumentation increases visibility into processing and evaluation latencies while preserving existing behavior and compatibility.

Signed-off-by: Yakir Oren <yakiroren@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f351f148-efaf-495a-b6e3-6cdbbca11db6

📥 Commits

Reviewing files that changed from the base of the PR and between eaf003b and 366c663.

📒 Files selected for processing (1)
  • pkg/rulemanager/rule_manager.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/rulemanager/rule_manager.go

📝 Walkthrough

Walkthrough

Added pprof profiling scopes: wrapped per-handler event dispatch and third-party tracer reporting in pkg/containerwatcher/v2/event_handler_factory.go, and wrapped CEL rule evaluations in pkg/rulemanager/rule_manager.go, adjusting local variable declarations to allow assignment inside the pprof callbacks.

Changes

Cohort / File(s) Summary
Event Handler Profiling
pkg/containerwatcher/v2/event_handler_factory.go
Wrapped the per-handler dispatch loop and reportEventToThirdPartyTracers call in pprof.Do(context.Background(), pprof.Labels("event", ...), ...) for profiling; retained handler type assertions and existing gating logic.
Rule Evaluation Profiling
pkg/rulemanager/rule_manager.go
Wrapped each rm.celEvaluator.EvaluateRule(...) call in pprof.Do(context.Background(), pprof.Labels("rule", rule.ID), ...); refactored shouldAlert/err declarations to allow assignment inside the pprof closure while keeping timing/metrics and error handling unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through code with a profiling tape,
Labels on events and rules took shape,
Quiet scopes now mark each run,
Tracing hops of work well done,
A little rabbit cheers—now go, debug and celebrate! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add pprof labels for rules' accurately describes the main changes: adding pprof instrumentation with labels to rule evaluation logic in the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/pprof-labels

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/rulemanager/rule_manager.go (1)

233-235: Thread the caller's profiling context into these paths instead of starting from context.Background().

The pprof.Do calls at lines 233-235 and 361-363 use context.Background(), which replaces the outer "event" label scope already established by the caller in pkg/containerwatcher/v2/event_handler_factory.go (lines 200-212). Preserve label composition by deriving the rule scope from the caller's profiling context rather than creating a new one from context.Background().

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/rulemanager/rule_manager.go` around lines 233 - 235, Replace the use of
context.Background() in the pprof.Do calls with the profiling context passed
down from the caller so labels are composed rather than replaced; specifically,
where pprof.Do(context.Background(), pprof.Labels("rule", rule.ID), func(_
context.Context) { shouldAlert, err =
rm.celEvaluator.EvaluateRule(enrichedEvent, rule.Expressions.RuleExpression) })
is used, thread the incoming context (the function's ctx/eventCtx) into pprof.Do
instead of context.Background() and propagate that same ctx into the closure so
the outer "event" labels remain composed with the "rule" label.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/rulemanager/rule_manager.go`:
- Around line 230-235: The code is evaluating rule.Expressions.RuleExpression
instead of the already-filtered ruleExpressions, which can run CEL against
unrelated expressions; inside the pprof.Do block where
rm.celEvaluator.EvaluateRule is called (with enrichedEvent), pass the filtered
variable ruleExpressions instead of rule.Expressions.RuleExpression so
EvaluateRule uses the same filtered expressions as EvaluatePolicyRulesForEvent.

---

Nitpick comments:
In `@pkg/rulemanager/rule_manager.go`:
- Around line 233-235: Replace the use of context.Background() in the pprof.Do
calls with the profiling context passed down from the caller so labels are
composed rather than replaced; specifically, where
pprof.Do(context.Background(), pprof.Labels("rule", rule.ID), func(_
context.Context) { shouldAlert, err =
rm.celEvaluator.EvaluateRule(enrichedEvent, rule.Expressions.RuleExpression) })
is used, thread the incoming context (the function's ctx/eventCtx) into pprof.Do
instead of context.Background() and propagate that same ctx into the closure so
the outer "event" labels remain composed with the "rule" label.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cd791834-8b1e-4da9-836f-f60c8790bd62

📥 Commits

Reviewing files that changed from the base of the PR and between 1a85870 and eaf003b.

📒 Files selected for processing (2)
  • pkg/containerwatcher/v2/event_handler_factory.go
  • pkg/rulemanager/rule_manager.go

.
Signed-off-by: Yakir Oren <yakiroren@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: WIP

Development

Successfully merging this pull request may close these issues.

2 participants