Skip to content

Commit 8feffee

Browse files
feat: Add FLAGD_SYNC_PORT support for in-process providers with backwards compatibility (#1413)
Signed-off-by: marcozabel <marco.zabel@dynatrace.com> Signed-off-by: Marco Zabel <49674991+marcozabel@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent eb86cbb commit 8feffee

File tree

7 files changed

+45
-3
lines changed

7 files changed

+45
-3
lines changed

libs/providers/flagd/src/e2e/step-definitions/providerSteps.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FlagdContainer } from '../tests/flagdContainer';
33
import type { State, Steps } from './state';
44
import { FlagdProvider } from '../../lib/flagd-provider';
55
import type { FlagdProviderOptions } from '../../lib/configuration';
6+
import { ProviderStatus } from '@openfeature/server-sdk';
67

78
export const providerSteps: Steps =
89
(state: State) =>
@@ -67,6 +68,21 @@ export const providerSteps: Steps =
6768
state.providerType = providerType;
6869
});
6970

71+
function mapProviderState(state: string): ProviderStatus {
72+
const mappedState = state.toUpperCase().replace('-', '_');
73+
const status = Object.values(ProviderStatus).find((s) => s === mappedState);
74+
75+
if (!status) {
76+
throw new Error(`Unknown provider status: ${state}`);
77+
}
78+
79+
return status;
80+
}
81+
82+
then(/^the client should be in (.*) state/, (providerState: string) => {
83+
expect(state.client?.providerStatus).toBe(mapProviderState(providerState));
84+
});
85+
7086
when(/^the connection is lost for (\d+)s$/, async (time) => {
7187
console.log('stopping flagd');
7288
await fetch('http://' + container.getLaunchpadUrl() + '/restart?seconds=' + time);

libs/providers/flagd/src/e2e/step-definitions/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export function mapValueToType(value: string, type: string): any {
1919
return value.toLowerCase() as ResolverType;
2020
case 'CacheType':
2121
return value as CacheOption;
22+
case 'StringList':
23+
return value.split(',').map((item) => item.trim());
2224
case 'Object':
2325
if (value == 'null') {
2426
return undefined;

libs/providers/flagd/src/e2e/tests/in-process.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('in-process', () => {
2222
// remove filters as we add support for features
2323
// see: https://github.com/open-feature/js-sdk-contrib/issues/1096 and child issues
2424
tagFilter:
25-
'@in-process and not @targetURI and not @customCert and not @events and not @sync and not @grace and not @metadata and not @contextEnrichment',
25+
'@in-process and not @targetURI and not @forbidden and not @customCert and not @events and not @sync and not @grace and not @metadata and not @unixsocket and not @sync-payload and not @contextEnrichment',
2626
scenarioNameTemplate: (vars) => {
2727
return `${vars.scenarioTitle} (${vars.scenarioTags.join(',')} ${vars.featureTags.join(',')})`;
2828
},

libs/providers/flagd/src/e2e/tests/rpc.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('rpc', () => {
2323
tagFilter:
2424
// remove filters as we add support for features
2525
// see: https://github.com/open-feature/js-sdk-contrib/issues/1096 and child issues
26-
'@rpc and not @targetURI and not @customCert and not @events and not @stream and not @grace and not @metadata and not @contextEnrichment and not @caching',
26+
'@rpc and not @targetURI and not @customCert and not @forbidden and not @events and not @stream and not @grace and not @metadata and not @contextEnrichment and not @caching',
2727
scenarioNameTemplate: (vars) => {
2828
return `${vars.scenarioTitle} (${vars.scenarioTags.join(',')} ${vars.featureTags.join(',')})`;
2929
},

libs/providers/flagd/src/lib/configuration.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ describe('Configuration', () => {
6161
});
6262
});
6363

64+
it('should use flagd sync port over flagd port environment option', () => {
65+
const port = 8080;
66+
const syncPort = 9090;
67+
68+
process.env['FLAGD_PORT'] = `${port}`;
69+
process.env['FLAGD_SYNC_PORT'] = `${syncPort}`;
70+
71+
expect(getConfig()).toStrictEqual(
72+
expect.objectContaining({
73+
port: syncPort,
74+
}),
75+
);
76+
});
77+
6478
it('should use incoming options over defaults and environment variable', () => {
6579
const options: FlagdProviderOptions = {
6680
host: 'test',
@@ -76,6 +90,7 @@ describe('Configuration', () => {
7690

7791
process.env['FLAGD_HOST'] = 'override';
7892
process.env['FLAGD_PORT'] = '8080';
93+
process.env['FLAGD_SYNC_PORT'] = '9090';
7994
process.env['FLAGD_TLS'] = 'false';
8095
process.env['FLAGD_DEFAULT_AUTHORITY'] = 'test-authority-override';
8196

@@ -87,6 +102,11 @@ describe('Configuration', () => {
87102
expect(getConfig()).toStrictEqual(expect.objectContaining({ port: 8013 }));
88103
});
89104

105+
it('should ignore an invalid sync port set as an environment variable', () => {
106+
process.env['FLAGD_SYNC_PORT'] = 'invalid number';
107+
expect(getConfig()).toStrictEqual(expect.objectContaining({ port: 8013 }));
108+
});
109+
90110
describe('port handling', () => {
91111
describe('for "in-process" evaluation', () => {
92112
const resolverType = 'in-process';

libs/providers/flagd/src/lib/configuration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const DEFAULT_IN_PROCESS_CONFIG: Config = { ...DEFAULT_CONFIG, resolverType: 'in
101101
enum ENV_VAR {
102102
FLAGD_HOST = 'FLAGD_HOST',
103103
FLAGD_PORT = 'FLAGD_PORT',
104+
FLAGD_SYNC_PORT = 'FLAGD_SYNC_PORT',
104105
FLAGD_DEADLINE_MS = 'FLAGD_DEADLINE_MS',
105106
FLAGD_TLS = 'FLAGD_TLS',
106107
FLAGD_SOCKET_PATH = 'FLAGD_SOCKET_PATH',
@@ -137,6 +138,9 @@ const getEnvVarConfig = (): Partial<Config> => {
137138
...(Number(process.env[ENV_VAR.FLAGD_PORT]) && {
138139
port: Number(process.env[ENV_VAR.FLAGD_PORT]),
139140
}),
141+
...(Number(process.env[ENV_VAR.FLAGD_SYNC_PORT]) && {
142+
port: Number(process.env[ENV_VAR.FLAGD_SYNC_PORT]),
143+
}),
140144
...(Number(process.env[ENV_VAR.FLAGD_DEADLINE_MS]) && {
141145
deadlineMs: Number(process.env[ENV_VAR.FLAGD_DEADLINE_MS]),
142146
}),

0 commit comments

Comments
 (0)