-
Notifications
You must be signed in to change notification settings - Fork 964
feat(myyoast): gradual rollout of the MyYoast OAuth connection #23376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
diedexx
wants to merge
4
commits into
trunk
Choose a base branch
from
DE/rt-1208-gradual-rollout
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8137251
feat(myyoast): gate the connection behind a gradual per-site rollout
diedexx ba66137
feat(myyoast): surface the DCR registration brake with its Retry-After
diedexx 41e0f82
refactor(myyoast): address review feedback on the gradual rollout
diedexx f849d83
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into DE/rt-120…
diedexx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?php | ||
|
|
||
| namespace Yoast\WP\SEO\Conditionals; | ||
|
|
||
| /** | ||
| * Feature-flag conditional whose default state is a gradual, deterministic rollout | ||
| * across a share of sites. | ||
| * | ||
| * The `YOAST_SEO_<FEATURE>` constant remains an explicit override: when it is defined | ||
| * in wp-config.php it wins outright (`true` forces the feature on, `false` forces it off), | ||
| * exactly like a plain {@see Feature_Flag_Conditional}. This is the per-site testing lever. | ||
| * | ||
| * When the constant is *not* defined, the feature falls back to the gradual-rollout | ||
| * heuristic: it is enabled for a slowly widening share of sites. A site's bucket is derived | ||
| * from a stable hash of the feature name plus the site URL, so the same site stays in (or out | ||
| * of) the rollout consistently across plugin releases. | ||
| * | ||
| * The share is expressed in per-mille (0-1000), not percent, because at the install base this | ||
| * rides on (10M+ sites) a single percent is too coarse for the first rollout steps; per-mille | ||
| * lets a rollout start at 0.1% (a share of 1). | ||
| * | ||
| * The hash input deliberately includes the feature name, so a site that buckets low for one | ||
| * feature is not automatically early for every feature - there are no permanently "lucky" sites | ||
| * that always receive new features first. | ||
| * | ||
| * This machinery is temporary by design: once a feature reaches a 100% share with no | ||
| * regressions, the concrete conditional reverts to extending {@see Feature_Flag_Conditional} | ||
| * directly and this class can be removed. | ||
| */ | ||
| abstract class Gradual_Rollout_Conditional extends Feature_Flag_Conditional { | ||
|
|
||
| /** | ||
| * The number of buckets sites are distributed across. | ||
| * | ||
| * @var int | ||
| */ | ||
| private const BUCKET_COUNT = 1000; | ||
|
|
||
| /** | ||
| * Returns whether the feature is enabled. | ||
| * | ||
| * The `YOAST_SEO_<FEATURE>` constant, when defined, is an explicit override and wins. | ||
| * Otherwise the gradual-rollout share decides. | ||
| * | ||
| * @return bool Whether the conditional is met. | ||
| */ | ||
| public function is_met() { | ||
| $constant = 'YOAST_SEO_' . \strtoupper( $this->get_feature_flag() ); | ||
|
|
||
| // An explicit constant always wins (true forces on, false forces off). | ||
| if ( \defined( $constant ) ) { | ||
| return ( \constant( $constant ) === true ); | ||
| } | ||
|
|
||
| return $this->is_in_rollout_cohort(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the current rollout share in per-mille (0-1000). | ||
| * | ||
| * 0 means the feature is enabled for no sites, 1000 for all sites. The value is | ||
| * raised release over release as the rollout widens. | ||
| * | ||
| * @return int The rollout share in per-mille. | ||
| */ | ||
| abstract protected function get_rollout_share(): int; | ||
|
|
||
| /** | ||
| * Determines whether this site falls within the current rollout share. | ||
| * | ||
| * @return bool Whether this site is in the rollout cohort. | ||
| */ | ||
| private function is_in_rollout_cohort(): bool { | ||
| $share = \max( 0, \min( self::BUCKET_COUNT, $this->get_rollout_share() ) ); | ||
|
|
||
| if ( $share <= 0 ) { | ||
| return false; | ||
| } | ||
|
|
||
| if ( $share >= self::BUCKET_COUNT ) { | ||
| return true; | ||
| } | ||
|
|
||
| // Hash the feature name together with the site URL so cohorts differ per feature | ||
| // (no permanently lucky sites). sprintf( '%u' ) reads crc32's result as unsigned, | ||
| // which keeps the modulo correct on 32-bit platforms where crc32 can be negative. | ||
| $bucket = ( (int) \sprintf( '%u', \crc32( $this->get_feature_name() . \site_url() ) ) % self::BUCKET_COUNT ); | ||
|
|
||
| return ( $bucket < $share ); | ||
| } | ||
| } |
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
49 changes: 49 additions & 0 deletions
49
src/myyoast-client/application/exceptions/registration-temporarily-unavailable-exception.php
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
| // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. | ||
|
|
||
| namespace Yoast\WP\SEO\MyYoast_Client\Application\Exceptions; | ||
|
|
||
| /** | ||
| * Exception thrown when the server temporarily refuses new Dynamic Client | ||
| * Registrations (HTTP 503 `temporarily_unavailable`). | ||
| * | ||
| * This happens when the registration emergency brake is engaged server-side during | ||
| * a controlled rollout. It is a transient condition: the caller should fall back to | ||
| * the legacy auth path and try again later. | ||
| * | ||
| * Extends {@see Registration_Failed_Exception} so existing handlers that catch | ||
| * registration failures keep working; handlers that want to surface the suggested | ||
| * retry delay can catch this subtype and read {@see self::get_retry_after_seconds()}. | ||
| */ | ||
| class Registration_Temporarily_Unavailable_Exception extends Registration_Failed_Exception { | ||
|
|
||
| /** | ||
| * The server-suggested retry delay in seconds, or null when none was provided. | ||
| * | ||
| * Display-only: the plugin does not schedule or enforce a wait based on this value. | ||
| * | ||
| * @var int|null | ||
| */ | ||
| private $retry_after_seconds; | ||
|
|
||
| /** | ||
| * Constructs the exception. | ||
| * | ||
| * @param string $message The exception message. | ||
| * @param int|null $retry_after_seconds The server-suggested retry delay in seconds, or null when unknown. | ||
| */ | ||
| public function __construct( string $message, ?int $retry_after_seconds = null ) { | ||
| parent::__construct( $message ); | ||
|
|
||
| $this->retry_after_seconds = $retry_after_seconds; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the server-suggested retry delay in seconds, or null when none was provided. | ||
| * | ||
| * @return int|null The retry delay in seconds, or null. | ||
| */ | ||
| public function get_retry_after_seconds(): ?int { | ||
| return $this->retry_after_seconds; | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.