Skip to content

Commit 92170bc

Browse files
support configs fetcher
1 parent db9e597 commit 92170bc

10 files changed

Lines changed: 75 additions & 12 deletions

File tree

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"root": true,
23
"extends": [
34
"eslint:recommended"
45
],

src/sdkClient/sdkLifecycle.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import SplitIO from '../../types/splitio';
21
import { releaseApiKey, validateAndTrackApiKey } from '../utils/inputValidation/apiKey';
32
import { ISdkFactoryContext } from '../sdkFactory/types';
43

@@ -7,7 +6,7 @@ const COOLDOWN_TIME_IN_MILLIS = 1000;
76
/**
87
* Creates an Sdk client, i.e., a base client with status, init, flush and destroy interface
98
*/
10-
export function sdkLifecycleFactory(params: ISdkFactoryContext, isSharedClient?: boolean): Pick<SplitIO.ConfigsClient, 'init' | 'flush' | 'destroy'> {
9+
export function sdkLifecycleFactory(params: ISdkFactoryContext, isSharedClient?: boolean): { init(): void; flush(): Promise<void>; destroy(): Promise<void> } {
1110
const { sdkReadinessManager, syncManager, storage, signalListener, settings, telemetryTracker, impressionsTracker } = params;
1211

1312
let hasInit = false;

src/sync/polling/pollingManagerSS.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import { ISdkFactoryContextSync } from '../../sdkFactory/types';
99
*/
1010
export function pollingManagerSSFactory(
1111
params: ISdkFactoryContextSync,
12-
// @TODO
1312
): IPollingManager {
1413

1514
const { splitApi, storage, readiness, settings } = params;
1615
const log = settings.log;
1716

18-
const splitsSyncTask: ISplitsSyncTask = splitsSyncTaskFactory(splitApi.fetchSplitChanges, storage, readiness, settings);
17+
const fetchingConfigs = settings.definitionsType === 'configs';
18+
19+
const splitsSyncTask: ISplitsSyncTask = splitsSyncTaskFactory(fetchingConfigs ? splitApi.fetchConfigs : splitApi.fetchSplitChanges, storage, readiness, settings);
1920
const segmentsSyncTask: ISegmentsSyncTask = segmentsSyncTaskFactory(splitApi.fetchSegmentChanges, storage, readiness, settings);
2021

2122
return {
@@ -25,7 +26,7 @@ export function pollingManagerSSFactory(
2526
// Start periodic fetching (polling)
2627
start() {
2728
log.info(POLLING_START);
28-
log.debug(LOG_PREFIX_SYNC_POLLING + `Definitions will be refreshed each ${settings.scheduler.featuresRefreshRate} millis`);
29+
log.debug(LOG_PREFIX_SYNC_POLLING + `${fetchingConfigs ? 'configs' : 'feature flags'} will be refreshed each ${fetchingConfigs ? settings.scheduler.configsRefreshRate : settings.scheduler.featuresRefreshRate} millis`);
2930
log.debug(LOG_PREFIX_SYNC_POLLING + `Segments will be refreshed each ${settings.scheduler.segmentsRefreshRate} millis`);
3031

3132
const startingUp = splitsSyncTask.start();

src/sync/polling/syncTasks/splitsSyncTask.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function splitsSyncTaskFactory(
2929
settings.startup.retriesOnFailureBeforeReady,
3030
isClientSide
3131
),
32-
settings.scheduler.featuresRefreshRate,
33-
'splitChangesUpdater',
32+
settings.definitionsType === 'configs' ? settings.scheduler.configsRefreshRate : settings.scheduler.featuresRefreshRate,
33+
settings.definitionsType === 'configs' ? 'configsUpdater' : 'splitChangesUpdater',
3434
);
3535
}

src/sync/submitters/__tests__/telemetrySubmitter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Telemetry submitter', () => {
7777
expect(recordTimeUntilReadySpy).toBeCalledTimes(1);
7878

7979
expect(postMetricsConfig).toBeCalledWith(JSON.stringify({
80-
oM: 0, st: 'memory', aF: 0, rF: 0, sE: true, rR: { sp: 0.001, se: 0.001, im: 0.001, ev: 0.001, te: 0.1 }, uO: { s: true, e: true, a: true, st: true, t: true }, iQ: 1, eQ: 1, iM: 0, iL: false, hP: false, tR: 0, tC: 0, nR: 0, t: [], i: ['NoopIntegration'], uC: 0, fsT: 0, fsI: 0
80+
oM: 0, st: 'memory', aF: 0, rF: 0, sE: true, rR: { sp: 0.001, cf: 0.001, se: 0.001, im: 0.001, ev: 0.001, te: 0.1 }, uO: { s: true, e: true, a: true, st: true, t: true }, iQ: 1, eQ: 1, iM: 0, iL: false, hP: false, tR: 0, tC: 0, nR: 0, t: [], i: ['NoopIntegration'], uC: 0, fsT: 0, fsI: 0
8181
}));
8282

8383
// Stop submitter, to not execute the 1st periodic metrics/usage POST

src/sync/submitters/telemetrySubmitter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export function telemetryCacheConfigAdapter(telemetry: ITelemetryCacheSync, sett
8181
sE: settings.streamingEnabled,
8282
rR: {
8383
sp: scheduler.featuresRefreshRate / 1000,
84+
cf: scheduler.configsRefreshRate / 1000,
8485
se: isServerSide ? scheduler.segmentsRefreshRate / 1000 : undefined,
8586
ms: isServerSide ? undefined : scheduler.segmentsRefreshRate / 1000,
8687
im: scheduler.impressionsRefreshRate / 1000,

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface ISettings extends SplitIO.ISettings {
1212
};
1313
readonly log: ILogger;
1414
readonly initialRolloutPlan?: RolloutPlan;
15+
readonly definitionsType?: 'ff' | 'configs'; // default is 'ff'
1516
}
1617

1718
/**

src/utils/settingsValidation/__tests__/settings.mocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const fullSettings: ISettings = {
3838
},
3939
scheduler: {
4040
featuresRefreshRate: 1,
41+
configsRefreshRate: 1,
4142
impressionsRefreshRate: 1,
4243
telemetryRefreshRate: 1,
4344
segmentsRefreshRate: 1,

src/utils/settingsValidation/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export const base = {
2929
scheduler: {
3030
// fetch feature updates each 60 sec
3131
featuresRefreshRate: 60,
32+
// fetch configs updates each 60 sec
33+
configsRefreshRate: 60,
3234
// fetch segments updates each 60 sec
3335
segmentsRefreshRate: 60,
3436
// publish telemetry stats each 3600 secs (1 hour)
@@ -129,6 +131,7 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
129131
// Scheduler periods
130132
const { scheduler, startup } = withDefaults;
131133
scheduler.featuresRefreshRate = fromSecondsToMillis(scheduler.featuresRefreshRate);
134+
scheduler.configsRefreshRate = fromSecondsToMillis(scheduler.configsRefreshRate);
132135
scheduler.segmentsRefreshRate = fromSecondsToMillis(scheduler.segmentsRefreshRate);
133136
scheduler.offlineRefreshRate = fromSecondsToMillis(scheduler.offlineRefreshRate);
134137
scheduler.eventsPushRate = fromSecondsToMillis(scheduler.eventsPushRate);

types/splitio.d.ts

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ declare namespace SplitIO {
615615
readonly mode: SDKMode;
616616
readonly scheduler: {
617617
featuresRefreshRate: number;
618+
configsRefreshRate: number;
618619
impressionsRefreshRate: number;
619620
impressionsQueueSize: number;
620621
/**
@@ -2310,6 +2311,65 @@ declare namespace SplitIO {
23102311
getObject(index: number): Config;
23112312
}
23122313

2314+
interface ConfigsOptions {
2315+
/**
2316+
* Your SDK key.
2317+
*
2318+
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/account-settings/api-keys/}
2319+
*/
2320+
authorizationKey: string;
2321+
/**
2322+
* Configs definitions refresh rate for polling, in seconds.
2323+
*
2324+
* @defaultValue `60`
2325+
*/
2326+
configsRefreshRate?: number;
2327+
/**
2328+
* Logging level.
2329+
*
2330+
* @defaultValue `'NONE'`
2331+
*/
2332+
logLevel?: LogLevel;
2333+
/**
2334+
* Time in seconds until SDK ready timeout is emitted.
2335+
*
2336+
* @defaultValue `10`
2337+
*/
2338+
timeout?: number;
2339+
/**
2340+
* Custom endpoints to replace the default ones used by the SDK.
2341+
*/
2342+
urls?: UrlSettings;
2343+
// /**
2344+
// * Defines what impressions are sent to Split servers.
2345+
// * - DEBUG: all impressions are sent.
2346+
// * - OPTIMIZED: will send unique impressions to Split servers, avoiding a considerable amount of traffic that duplicated impressions could generate.
2347+
// * - NONE: will send unique keys evaluated per config to Split servers instead of full blown impressions.
2348+
// *
2349+
// * @defaultValue `'OPTIMIZED'`
2350+
// */
2351+
// impressionsMode?: ImpressionsMode;
2352+
// /**
2353+
// * The SDK posts the queued events data in bulks. This parameter controls the posting rate in seconds.
2354+
// *
2355+
// * @defaultValue `1800`
2356+
// */
2357+
// eventsPushRate?: number;
2358+
// /**
2359+
// * The SDK sends impressions back to Split servers. This parameter controls how often this data is sent, in seconds.
2360+
// *
2361+
// * @defaultValue `1800`
2362+
// */
2363+
// impressionsRefreshRate?: number;
2364+
// /**
2365+
// * Boolean flag to enable the streaming service as default synchronization mechanism. In the event of any issue with streaming,
2366+
// * the SDK would fallback to the polling mechanism. If false, the SDK would poll for changes as usual without attempting to use streaming.
2367+
// *
2368+
// * @defaultValue `true`
2369+
// */
2370+
// streamingEnabled?: boolean;
2371+
}
2372+
23132373
/**
23142374
* Configs SDK client interface.
23152375
*/
@@ -2322,10 +2382,6 @@ declare namespace SplitIO {
23222382
* Logger API.
23232383
*/
23242384
Logger: ILoggerAPI;
2325-
/**
2326-
* Initializes the client.
2327-
*/
2328-
init(): void;
23292385
/**
23302386
* Flushes the client.
23312387
*/

0 commit comments

Comments
 (0)