Repository navigation
feat: add payloadFilter option to request a filtered environment - #422
abelonogov-ld wants to merge 5 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Risk: medium.
Automated risk review (dry run): Medium
This PR would not be automatically approved. Human approval required.
Why: This adds a public LDConfig.Builder.payloadFilter option that changes flag-data request URLs across FDv1/FDv2 streaming and polling (StreamingDataSource, HttpFeatureFlagFetcher, FDv2StreamingSynchronizer, DataSystemComponents). That is a meaningful SDK behavior change spanning several data-source paths, so it is Medium even with unit tests and a clean Bugbot check.
If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.
Sent by Cursor Approval Agent: Dry-Run PR Approver
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # contract-tests/src/main/java/com/launchdarkly/sdktest/TestService.java # launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/DataSystemComponentsTest.java
| @Nullable | ||
| private final FDv2Requestor requestor; | ||
| private final boolean evaluationReasons; | ||
| private final String payloadFilter; |
There was a problem hiding this comment.
we've been actively deprecating and removing payload filters from FDv2. either we decide to reverse course on that work, or we should leave payload filtering to FDv1
There was a problem hiding this comment.
Agreed. payloadFilters cannot be added to FDv2 sources as it is deprecated.
…ry environment payloadFilter stays the filter for the primary environment and the default for every secondary environment. A secondary environment named in secondaryPayloadFilters uses its own key instead, or requests the full environment if the key is null or empty. Names that are not secondary environments are logged when the config is built and ignored. Data sources look up their environment's filter by ClientContext.getEnvironmentName(). Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approved under Rule 2 (allowed PR authors): this author is not on the SDK approval list, and the change is above the low-risk threshold. Cursor Bugbot passed with no findings; human review is needed and no reviewers were assigned.
Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver
…nt(name, mobileKey, payloadFilter) A secondary environment's payload filter is now given together with its mobile key, so it can't name an unknown environment or drift from the keys. payloadFilter applies only to the primary environment; secondary environments are unfiltered unless added with a filter. secondaryEnvironment throws IllegalArgumentException on the same name and key conflicts as secondaryMobileKeys. getPayloadFilter(String) returns null for unknown environment names.
There was a problem hiding this comment.
Risk: medium. Not approved under Rule 2 (allowed PR authors): this author is not on the SDK approval list, and the change is above the low-risk threshold. Cursor Bugbot passed with no findings; human review is needed and no reviewers were assigned.
Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver
FDv2 filters flag data by the views linked to the mobile key, and LaunchDarkly no longer supports payload filters on FDv2 requests. Stop sending the filter from the FDv2 streaming and polling synchronizers, keep it on the FDv1 fallback, and warn when a filter is combined with the data system. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Risk: medium. Not approved under Rule 2 (allowed PR authors): this author is not on the SDK approval list, and the change is above the low-risk threshold. Cursor Bugbot passed with no findings; human review is needed and no reviewers were assigned.
Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver


Requirements
Related issues
Mirrors
payloadFilterKeyin the React Native and browser SDKs (js-core#551) and follows the filtered environments SDK spec. iOS counterpart: ios-client-sdk#548.Describe the solution you've provided
Adds
LDConfig.Builder.payloadFilter(String). When set, the SDK addsfilter=<key>to every FDv1 flag data request:/meval, GET and REPORT)/msdk/evalx, GET and REPORT), including the FDv1 fallback synchronizer in the data systemFDv2 requests don't get the filter. With FDv2, LaunchDarkly filters flag data by the views linked to the mobile key ("custom payload"), so an app picks a filtered payload by picking a mobile key, with no SDK option. The FDv2 payload filter is being removed across SDKs: the harness dropped its FDv2 filter scenarios (sdk-test-harness#431), and Go and Java deprecated it (go-server-sdk#440). When a filter is combined with
dataSystem(...),build()logs a warning for each environment that has one.The two cases use the same API:
A mobile key with a custom payload works only with FDv2. LaunchDarkly rejects FDv1 requests made with it with
422(FDV2REL 1.1.1.3). For the same reason, the Relay Proxy spec forbids sending the FDv1 fallback directive for such a key (1.1.1.6).The key is checked when the config is built. A null or empty key means no filter. A key that doesn't match
^[a-zA-Z0-9][._\-a-zA-Z0-9]*$is dropped with an error log, and the full environment is requested, as the spec requires (filtering-strictbehavior).Payload filters belong to a project, and secondary mobile keys may be in other projects, so a secondary environment's filter is given together with its mobile key:
Builder.payloadFilter(String)applies only to the primary environment.Builder.secondaryEnvironment(String name, String mobileKey, String payloadFilter)adds a secondary environment, with an optional filter (null means none). It throwsIllegalArgumentExceptionon the same name and key conflicts assecondaryMobileKeys(Map).LDConfig.getPayloadFilter(String environmentName)returns an environment's filter, or null for an unknown name.Apps that don't use filters are unaffected:
secondaryMobileKeys(Map)is unchanged and its environments have no filter. Calling it replaces every secondary environment, including ones added with a filter.build()validates every environment's filter once. Data sources look it up withClientContext.getEnvironmentName(), so the value reaches FDv1 data sources throughClientContext.getConfig()and the FDv1 fallback synchronizer through the internalDataSourceBuildInputsInternal, with no changes to the publicClientContextorDataSourceBuildInputsAPIs.The contract-test service now maps the harness's
streaming.filter/polling.filterto the new option and declares thefilteringandfiltering-strictcapabilities.Describe alternatives you've considered
StreamingDataSourceBuilder/PollingDataSourceBuilder, as the Java server SDK does. A single top-level option matches React Native and covers the FDv2 data system without changes to each builder.Map<String, String>of filters by environment name next tosecondaryMobileKeys(Map), withpayloadFilteras the default. The two maps can drift apart, and a mistyped name silently falls back to another project's filter.Additional context
This PR only sends the parameter; the SDK does no filtering of its own and doesn't change how it picks streaming or polling. The server doesn't currently apply the filter on every mobile endpoint:
/msdk/evalx): the streamer drops the query string before it reaches the origin, so these responses are unfiltered./meval): the filter is forwarded and applied to the initialputwhen thepayload-filter-gonfalon-sdk-endpointsflag is on. Live updates are only routed by filter whenpayload-filter-streamer-updatesis on.So an app that switches between streaming and polling may see the full flag set after a poll. The React Native SDK has the same limitation today.
I haven't run the contract test harness against this branch locally. All 782 unit tests pass.
Note
Overview
Adds
LDConfig.Builder.payloadFilter(String)so apps can request a LaunchDarkly filtered environment. When set and valid, the SDK appendsfilter=<key>on flag-data HTTP calls across FDv1 streaming and polling (GET/REPORT) and FDv2 streaming and polling (including FDv1 fallback in the data system).Invalid or empty keys are normalized at
build(): empty becomes no filter; keys outside^[a-zA-Z0-9][._\-a-zA-Z0-9]*$are dropped with an error log and the SDK requests the full environment (filtering-strict).The option is threaded through
LDUtil,DataSourceBuildInputsInternal, and existing request builders without changing publicClientContext/DataSourceBuildInputsAPIs. Contract tests accept harnessstreaming.filter/polling.filter, map them topayloadFilter, and advertisefilteringandfiltering-strictcapabilities.Reviewed by Cursor Bugbot for commit 71d96b6. Bugbot is set up for automated code reviews on this repo. Configure here.