Repository navigation
fix: Stop sending the unsupported payload filter on FDv2 requests #2249
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
Merged
+300
−42
Merged
Changes from all commits
Commits
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
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
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
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 |
|---|---|---|
|
|
@@ -4,6 +4,24 @@ import { LDOptions } from '../src/api/options/LDOptions'; | |
| import LDClientImpl from '../src/LDClientImpl'; | ||
| import { createBasicPlatform } from './createBasicPlatform'; | ||
|
|
||
| function makeEventSource() { | ||
| return { | ||
| onopen: jest.fn(), | ||
| onclose: jest.fn(), | ||
| onerror: jest.fn(), | ||
| onretrying: jest.fn(), | ||
| addEventListener: jest.fn(), | ||
| close: jest.fn(), | ||
| }; | ||
| } | ||
|
|
||
| function requestUrls(platform: any): string[] { | ||
| return [ | ||
| ...platform.requests.fetch.mock.calls.map((c: any[]) => c[0] as string), | ||
| ...platform.requests.createEventSource.mock.calls.map((c: any[]) => c[0] as string), | ||
| ]; | ||
| } | ||
|
|
||
| describe('given a client using the FDv2 data system', () => { | ||
| const callbacks = { | ||
| onFailed: jest.fn(), | ||
|
|
@@ -55,8 +73,9 @@ describe('given a client using the FDv2 data system', () => { | |
| callbacks, | ||
| ); | ||
|
|
||
| expect(logger.warn).toHaveBeenCalledTimes(1); | ||
| expect(logger.warn).toHaveBeenCalledWith( | ||
| expect.stringContaining('Payload filtering is not supported with the FDv2 data system'), | ||
| 'Payload filtering is not supported with the FDv2 data system; the configured payload filter has no effect on FDv2 requests', | ||
| ); | ||
| }); | ||
|
|
||
|
|
@@ -67,4 +86,102 @@ describe('given a client using the FDv2 data system', () => { | |
| expect.stringContaining('Payload filtering is not supported'), | ||
| ); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['the default host', undefined, 'https://sdk.launchdarkly.com/sdk/latest-all'], | ||
| [ | ||
| 'a custom base URI', | ||
| { baseUri: 'https://fallback.example.com' }, | ||
| 'https://fallback.example.com/sdk/latest-all', | ||
| ], | ||
| ])( | ||
| 'uses the unfiltered FDv1 fallback endpoint with %s', | ||
| async (_name, fdv1Fallback, expectedUrl) => { | ||
| platform.requests.fetch = jest.fn(async (url: string) => { | ||
| const fallback = url.includes('/sdk/poll'); | ||
| const headers = new Map(fallback ? [['x-ld-fd-fallback', 'true']] : []); | ||
|
Comment on lines
+100
to
+102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return { | ||
| status: fallback ? 500 : 200, | ||
| headers, | ||
| text: async () => (fallback ? '' : JSON.stringify({ flags: {}, segments: {} })), | ||
| }; | ||
| }); | ||
| client = new LDClientImpl( | ||
| 'sdk-key', | ||
| platform, | ||
| makeOptions({ | ||
| payloadFilterKey: 'microservice-1', | ||
| dataSystem: { | ||
| dataSource: { | ||
| dataSourceOptionsType: 'custom', | ||
| initializers: [{ type: 'polling' }], | ||
| synchronizers: [{ type: 'polling' }], | ||
| }, | ||
| fdv1Fallback, | ||
| }, | ||
| }), | ||
| callbacks, | ||
| ); | ||
|
|
||
| // The FDv2 initializer response directs the SDK to the FDv1 fallback synchronizer. | ||
| await client.waitForInitialization({ timeout: 1 }); | ||
|
|
||
| const urls = requestUrls(platform); | ||
| const fdv1Urls = urls.filter((u) => u.includes('/sdk/latest-all')); | ||
| expect(fdv1Urls.length).toBeGreaterThan(0); | ||
| fdv1Urls.forEach((u) => { | ||
| expect(u).toBe(expectedUrl); | ||
| }); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| describe('given a client using the FDv1 data system', () => { | ||
| const callbacks = { | ||
| onFailed: jest.fn(), | ||
| onError: jest.fn(), | ||
| onReady: jest.fn(), | ||
| onUpdate: jest.fn(), | ||
| hasEventListeners: jest.fn(), | ||
| }; | ||
| let platform: any; | ||
| let client: LDClientImpl; | ||
|
|
||
| beforeEach(() => { | ||
| platform = createBasicPlatform(); | ||
| platform.requests.fetch = jest.fn(async () => { | ||
| throw new Error('no network in test'); | ||
| }); | ||
| platform.requests.createEventSource = jest.fn(() => makeEventSource()); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| client?.close(); | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['polling', false, '/sdk/latest-all'], | ||
| ['streaming', true, '/all'], | ||
| ])('sends the payload filter on %s requests', async (_name, stream, expectedPath) => { | ||
| client = new LDClientImpl( | ||
| 'sdk-key', | ||
| platform, | ||
| { | ||
| sendEvents: false, | ||
| diagnosticOptOut: true, | ||
| stream, | ||
| payloadFilterKey: 'microservice-1', | ||
| }, | ||
| callbacks, | ||
| ); | ||
|
|
||
| // Wait briefly so that the data source makes its request. | ||
| await client.waitForInitialization({ timeout: 0.02 }).catch(() => {}); | ||
|
|
||
| // The FDv1 request carries the filter. | ||
| const urls = requestUrls(platform).filter((u) => u.includes(expectedPath)); | ||
| expect(urls.length).toBeGreaterThan(0); | ||
| urls.forEach((u) => expect(u).toContain('filter=microservice-1')); | ||
| }); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Shared manager relies on caller normalization
Built-in SDKs normalize endpoints here. Direct callers of createFDv2DataManagerBase still get a warning for filtered endpoints, but the manager forwards them unchanged.
Was this helpful? React with 👍 or 👎 to provide feedback.