Skip to content

header_rewrite: count operators executed and conditions evaluated#13271

Closed
moonchen wants to merge 1 commit into
apache:masterfrom
moonchen:header-rewrite-work-metrics
Closed

header_rewrite: count operators executed and conditions evaluated#13271
moonchen wants to merge 1 commit into
apache:masterfrom
moonchen:header-rewrite-work-metrics

Conversation

@moonchen

Copy link
Copy Markdown
Contributor

A transaction's header_rewrite CPU scales with how many operators it runs and
conditions it evaluates, which is set by the configured rules -- the per-hook
invocation count alone cannot distinguish a small ruleset from a large one. Add
proxy.process.plugin.header_rewrite.{operators,conditions}, incremented in the
inline Operator::do_exec and Condition::do_eval chain walkers. do_eval respects
short-circuit, so only conditions actually evaluated are counted. The counters
are created once, from both TSPluginInit and TSRemapInit.

A transaction's header_rewrite CPU scales with how many operators it runs and
conditions it evaluates, which is set by the configured rules -- the per-hook
invocation count alone cannot distinguish a small ruleset from a large one.  Add
proxy.process.plugin.header_rewrite.{operators,conditions}, incremented in the
inline Operator::do_exec and Condition::do_eval chain walkers.  do_eval respects
short-circuit, so only conditions actually evaluated are counted.  The counters
are created once, from both TSPluginInit and TSRemapInit.
Copilot AI review requested due to automatic review settings June 15, 2026 20:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds process-wide “work” metrics to the header_rewrite plugin to better model CPU cost per transaction by counting operators executed and conditions evaluated, rather than relying only on per-hook invocation counts.

Changes:

  • Add new metrics proxy.process.plugin.header_rewrite.operators and .conditions, created once and incremented in the hot-path chain walkers (Operator::do_exec, Condition::do_eval).
  • Initialize the metrics from both global plugin init (TSPluginInit) and remap init (TSRemapInit) so global + remap usage share the same process stat IDs.
  • Add a gold test plus a minimal rules file to validate the metrics are present and increasing.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/gold_tests/pluginTest/header_rewrite/rules/metrics.conf Adds a simple ruleset that triggers known operator/condition activity for metric validation.
tests/gold_tests/pluginTest/header_rewrite/header_rewrite_metrics.test.py Adds a gold test that drives traffic and queries the new metrics via traffic_ctl.
plugins/header_rewrite/statement.h Declares global stat IDs and init_hrw_work_stats() for the new metrics.
plugins/header_rewrite/statement.cc Defines stat IDs and implements one-time creation via TSStatCreate.
plugins/header_rewrite/operator.h Increments the operators-executed metric once per operator execution in do_exec().
plugins/header_rewrite/condition.h Increments the conditions-evaluated metric once per evaluated condition in do_eval() (short-circuit respected).
plugins/header_rewrite/header_rewrite.cc Calls init_hrw_work_stats() from both TSPluginInit and TSRemapInit.

Comment on lines +59 to +60
tr.Processes.Default.Streams.stdout = Testers.ContainsExpression(
r'proxy\.process\.plugin\.header_rewrite\.operators [1-9]', 'header_rewrite operators executed should be counted')
Comment on lines +68 to +69
tr.Processes.Default.Streams.stdout = Testers.ContainsExpression(
r'proxy\.process\.plugin\.header_rewrite\.conditions [1-9]', 'header_rewrite conditions evaluated should be counted')
@moonchen moonchen marked this pull request as draft June 15, 2026 20:24
@moonchen moonchen closed this Jun 15, 2026
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.

2 participants