Repository navigation
feat(flags): Bucket rollouts by feature name for new flags - #184
Conversation
fad8b09 to
5aedcb9
Compare
|
Rust
New features require a separate hash for each feature, rather than reusing the cached identity-only hash. A possible follow-up, #187, could reduce their check time to ~576 ns (~9% faster), based on a prototype benchmark. These are Rust microbenchmarks, not request-level timings. |
e561ddf to
00704a5
Compare
00704a5 to
d2dd4fb
Compare
d2dd4fb to
1ce09a2
Compare
| "type": "string", | ||
| "pattern": "^\\d{4}-\\d{2}-\\d{2}(?:T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:[-+]\\d{2}:?\\d{2})?)?$", | ||
| "description": "The datetime when this feature was created." | ||
| "description": "The datetime when this feature was created. This value selects the rollout hash. Keep it unchanged: moving it across the feature-bucketing cutoff can change which organizations are included in a partial rollout." |
There was a problem hiding this comment.
| "description": "The datetime when this feature was created. This value selects the rollout hash. Keep it unchanged: moving it across the feature-bucketing cutoff can change which organizations are included in a partial rollout." | |
| "description": "The datetime when this feature was created. This value impacts the rollout hash method, and should not be changed. Changing the `created_at` value will change which organizations are included in a partial rollout." |
We can be more direct here.
| - A feature's `segments` are tried in order; the **first** segment whose conditions all match (logical AND) decides the result via its rollout. If no segment matches, the feature is off. A feature with `enabled: false` is always off. | ||
| - Rollout: `rollout: 0` → off, `>= 100` → on, otherwise the context is in the rollout iff `id % 100 <= rollout`. The `<=` matches flagpole, so migrating a feature does not move orgs between buckets, even though it means a partial rollout covers one bucket more than its number suggests. | ||
| - The context `id` is a SHA-1 hash built from the identity fields: each identity field present in the data, sorted, joined as `key:value:...`. If no `identity_fields` are set, **all** data keys are used (so the id — and the rollout bucket — changes whenever any field differs). | ||
| - Features with a `created_at` after 2026-10-05 at 00:00:00 UTC bucket by feature name as well: their id is the same hash over `name:key:value:...`, so two such features at the same rollout reach different orgs, and the same orgs no longer land in the low buckets of every new flag. Features created at or before that instant, or with a `created_at` that does not parse, keep the identity-only id so their in-flight rollouts do not move. |
There was a problem hiding this comment.
| - Features with a `created_at` after 2026-10-05 at 00:00:00 UTC bucket by feature name as well: their id is the same hash over `name:key:value:...`, so two such features at the same rollout reach different orgs, and the same orgs no longer land in the low buckets of every new flag. Features created at or before that instant, or with a `created_at` that does not parse, keep the identity-only id so their in-flight rollouts do not move. | |
| - Features with a `created_at` after `2026-10-05 00:00:00 UTC` will include the feature name in the context id, so that rollout rates for different features select different groups of organizations. Features created before `2026-10-05` do not include the feature name in context id. |
We can be be less verbose here.
| /// | ||
| /// Must not predate the deploy of this rule. |
There was a problem hiding this comment.
This is not helpful to keep around forever.
| /// | |
| /// Must not predate the deploy of this rule. |
| const FEATURE_BUCKETING_EPOCH: NaiveDateTime = NaiveDate::from_ymd_opt(2026, 10, 5) | ||
| .unwrap() | ||
| .and_time(NaiveTime::MIN); |
There was a problem hiding this comment.
Your comment says UTC, but this is a Naive datetime. Why the discrepancy? All of these operations could be handled with NaiveDate objects (after parsing NativeDateTime) as we don't need time precision.
There was a problem hiding this comment.
Agreed, I’ll switch to NaiveDate and update.
The parser normalizes to UTC, which is why the comment says that.
| /// Accepts a date, a naive datetime with an optional fraction, or a datetime | ||
| /// with a UTC offset; naive values are taken as UTC. Values that do not parse | ||
| /// return `None`. | ||
| fn parse_created_at(raw: &str) -> Option<NaiveDateTime> { |
There was a problem hiding this comment.
Do we need the time components? It seems overly precise given that most values in use are date only.
| } | ||
|
|
||
| fn matches(&self, context: &FeatureContext) -> bool { | ||
| fn matches(&self, feature_name: &str, context: &FeatureContext) -> bool { |
There was a problem hiding this comment.
Should feature names be an input to from_json() instead? Now that features need to know their names, doing it when the struct is initialized is a better design.
| context.identity_fields(vec!["organization_id"]); | ||
| let feature_name = format!( | ||
| "organizations:{}-{organization_id}", | ||
| "x".repeat(organization_id % 128) |
There was a problem hiding this comment.
Why 128? Seems like a magic number.
There was a problem hiding this comment.
No special reason for 128, just varying the feature name length.
I’ll make those cases explicit so it’s clearer what we’re testing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
||
| #[test] | ||
| fn test_bucket_id_align_with_python() { | ||
| // Pinned against the reference tests in getsentry/sentry#125364. |
There was a problem hiding this comment.
Nit: Should this be pointing to a specific line of code instead of a pr?
The referenced Sentry PR was closed after flagpole moved to sentry-options, so replace the link with the formula that reproduces the expected buckets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The debug log recorded the identity-only context id, which is not the bucket that features created after the cutoff roll out on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
This PR targets
mainand keeps the existingBigIntremainder calculation. #187 is a possible future optimization, not a dependency.Use the feature name in the rollout hash for new features:
sha1("name:key:value:..."). This prevents all new features from using the same rollout population at a given percentage.FeatureContext::bucket_id(feature_name)method.Feature::from_json(), and usechronoto parse thecreated_atdate when it constructs a feature during evaluation. Store the cutoff comparison inbuckets_by_feature. Each check constructs a newFeature, so this result is not cached across checks.Feature::matches()passes its name toSegment::in_rolloutonly when that flag is set.Compatibility
The cutoff is the date 2026-10-05, compared by date only.
created_atdate is after the cutoff, so the first features to use it are dated 2026-10-06.created_atvalues also keep that hash.2026-10-05T23:00:00-02:00counts as 2026-10-06.FeatureContext::id()and its existing ID cache. Existing partial rollouts keep their organization assignments.Test plan
BigIntcalculation.clippy::alldenied. Python client results are shown in the PR checks.Release order
sentry,getsentry, andseer.If deployment cannot finish before the cutoff, move
FEATURE_BUCKETING_EPOCHin this repo to a later date before release.Refs VDY-161