header_rewrite: count operators executed and conditions evaluated#13271
Closed
moonchen wants to merge 1 commit into
Closed
header_rewrite: count operators executed and conditions evaluated#13271moonchen wants to merge 1 commit into
moonchen wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
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.operatorsand.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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.