Repository navigation
Conversation
Introduce PercentagePhase alongside existing cron-based Phase to support probabilistic request rejection during brownout windows. Configuration uses `type: percentage` with `reject_percentage` (1-100), while existing `type: cron` behavior remains unchanged for backward compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new brownout “percentage” phase type to support probabilistic request rejection as an alternative (or complement) to cron-window-based brownouts, while keeping existing cron behavior as the default.
Changes:
- Introduces
PercentagePhaseand updates brownout evaluation to reject based onrandom_int(1, 100) <= reject_percentagewhen a percentage phase is active. - Extends bundle configuration to support
type: percentagewithreject_percentage(1–100) and validates required options per type. - Adds/extends tests covering percentage-phase behavior and mixed cron/percentage strategies (plus sorting idempotence with mixed types).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/Brownout/PercentagePhase.php |
New phase model for percentage-based rejection. |
src/Brownout/BrownoutChecker.php |
Evaluates percentage phases via RNG; adds overrideable randomInt() for test determinism. |
src/Brownout/Strategy.php |
Broadens strategy phases to allow `Phase |
src/ApiDeprecationBundle.php |
Builds strategies from config, supporting type: percentage and mixed phase lists. |
config/definition.php |
Adds phase type and reject_percentage, plus conditional validation per type. |
tests/Brownout/BrownoutCheckerTest.php |
Adds deterministic tests for percentage-phase boundaries and mixed strategies. |
tests/ApiDeprecationBundleTest.php |
Adds property-based test for mixed-phase sorting idempotence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| ->end() | ||
| ->validate() | ||
| ->ifTrue(function (array $v): bool { | ||
| return $v['type'] === 'cron' && ($v['cron'] === null || $v['duration'] === null); |
Comment on lines
+47
to
+61
| \assert(\is_int($phaseConfig['reject_percentage'])); | ||
|
|
||
| $phases[] = new PercentagePhase( | ||
| $interval, | ||
| $phaseConfig['reject_percentage'], | ||
| ); | ||
| } else { | ||
| \assert(\is_string($phaseConfig['cron'])); | ||
| \assert(\is_int($phaseConfig['duration'])); | ||
|
|
||
| $phases[] = new Phase( | ||
| $interval, | ||
| $phaseConfig['cron'], | ||
| $phaseConfig['duration'], | ||
| ); |
Comment on lines
+51
to
62
| ->validate() | ||
| ->ifTrue(function (array $v): bool { | ||
| return $v['type'] === 'cron' && ($v['cron'] === null || $v['duration'] === null); | ||
| }) | ||
| ->thenInvalid('Phase type "cron" requires "cron" and "duration" options.') | ||
| ->end() | ||
| ->validate() | ||
| ->ifTrue(function (array $v): bool { | ||
| return $v['type'] === 'percentage' && $v['reject_percentage'] === null; | ||
| }) | ||
| ->thenInvalid('Phase type "percentage" requires "reject_percentage" option.') | ||
| ->end() |
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.
Summary
PercentagePhaseclass for probabilistic request rejection during brownoutstype: percentagein phase configuration withreject_percentage(1-100)type: cronbehavior unchanged (backward compatible, defaults tocron)Configuration example
Test plan
Closes #10
🤖 Generated with Claude Code