feat(flags): add flagSelection to load only matching flags #1305
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1305"
general
weight: 0.35
joepeeples
What
Adds the
flagSelectionoption todatadog_flags, so the precompute request asks only for flags that match the selected tags or key patterns. Behavior matches the iOS (DataDog/dd-sdk-ios#3344), Android (DataDog/dd-sdk-android#4031) and browser SDKs.FlagSelection({tags, keyPatterns})(newflag_selection.dart, exported fromdatadog_flagsanddatadog_flags_flutter) andDatadogFlagsConfiguration.flagSelection. The constructor staysconst; the selection is canonicalized when a client is built.White_Spacecode points with a linear scan (notString.trim(), which differs at U+0085 and U+FEFF), keeps interior whitespace, drops empty values, dedupes, and sorts by UTF-8 bytes. Unpaired surrogates aremalformed_selection. Limits: 31 values per list, 200 UTF-8 bytes per value, precedencemalformed_selection>too_many_values>invalid_key_pattern>invalid_tag. Both lists empty means no selection.data.attributes.flag_selection {tags, key_patterns}, omitted without a selection (includeIfNull: false; generated code regenerated).DD-Flag-Selection-Ignored: read only on a 2xx response with a decoded body when a selection was sent. Only the 5 server reasons are reported; anything else (including repeated fields, whichpackage:httpjoins with,) isunknown; an empty value is absent. Logged after the assignments are installed.-
flagSelection was not sent (<reason>: <limit>). Loading the full flag configuration., once per OpenFeature provider (not again on context changes or refreshes), or once per client built throughDatadogFlags.sharedClient.-
flagSelection was ignored by the server (<reason>). Loaded the full flag configuration.FlagsDatastores the canonical selection, and a snapshot fetched under another selection (or without one) is not restored. Selected assignments are written underselectedFlags, a key older SDKs do not read, so a downgraded SDK never takes them as the full flag set.DatadogFlagsStoreis unchanged.datadog_flags_flutterpasses the option through.DD-Flag-Selection-Ignoredand list it inAccess-Control-Expose-Headers.datadog_flagshas no telemetry channel.DatadogOpenFeatureProvider.verbosityto aFlagsLoggerLevel(debug,warning,error; exported from both packages) also printsdatadog_flagsdiagnostics at or above that level in any build mode, including release builds, where the Dart developer log is not shown. It isnullby default, which prints nothing, as on iOS and Android.Tests
test/fixtures/flag-selection/selection-vectors.jsonmirrors DataDog/ffe-system-test-dataflag-selection/selection-vectors.jsonat29ba6bf2e7514cf1b75c046b8956a22565221ee8(pin in the sibling README).selection_vectors.dartcompiles the same vectors in for web, and a VM test fails if the two differ. One test per case: 38 SDK cases run, the 6rawQuerycases are skipped by name (URL decoding does not apply to a POST body).Validation (Flutter 3.50.0, Dart 3.14.0):
| Command (in
packages/datadog_flags) | Result ||---|---|
|
flutter test| 333 passed, 6 skipped (therawQueryvectors) ||
dart test --platform chrome| 329 passed, 6 skipped (VM-only file tests excluded) ||
dart test --platform chrome --compiler dart2wasm| 329 passed, 6 skipped ||
dart format --output=none --set-exit-if-changed .| clean ||
dart analyze .| no issues ||
dart run build_runner build| no diff after regeneration |packages/datadog_flags_flutter(path overrides for local packages):flutter test18 passed,flutter analyze lib testno issues, format clean.build_runnerwith the pinnedjson_serializable 6.14.1does not compile against the newestsource_helper(1.4.0); the generated file was produced withsource_helper 1.3.13through a local, uncommitted override.Staging (us1 staging)
SDK commit
9965239f, against us1 staging (DD_SITE=datad0g.com, envstaging). A small harness app depends ondatadog_flagsby path and registersDatadogOpenFeatureProviderwithflagSelection. The cases and expected flag keys come from the shared flag-selection fixture, run against staging flags tagged for it.| Platform | Cases | Result |
|---|---|---|
| Dart VM (Dart 3.14.0) | 73 | 73 passed |
| Flutter web, release (dart2js), headless Chromium | 73 | 73 passed |
| Flutter web, debug (DDC), headless Chromium | 73 | 73 passed |
*, literal?and[); tags OR key patterns; selections that match no flag; 31 values, and 100 raw values that canonicalize to 31; SDK-dropped selections (too_many_values,invalid_key_pattern,invalid_tag,malformed_selection); and a selection the server ignores (too_many_values).flag_selectionrequest body (canonical order, or absent),DD-Flag-Selection-Ignored, and the error logs.DD-Flag-Selection-IgnoredinAccess-Control-Expose-Headers, and the SDK readtoo_many_valuescross-origin fromhttp://localhost.dart:developerlog()to a no-op, so a release web build shows no SDK logs unlessverbosityis set.typed_evaluationexample, with a localflagSelectionedit, resolves flags inside the selection and returnsflagNotFoundoutside it.Dependencies
FlagsLoggerfrom #1291; this PR adds itserror()level.flags_configuration,flags_repository,flags_storeandprecompute_request; whichever merges second resolves the overlap.Logging frequency
The OpenFeature provider builds a new client for each context revision. Those clients share one drop log, so the "not sent" error is logged once per provider, not at each context change or refresh. Clients created through
DatadogFlags.sharedClientlog once per client.