@splitsoftware/splitio-commons 2.2.1-rc.0 → 2.2.1-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +2 -3
- package/README.md +0 -1
- package/cjs/evaluator/Engine.js +61 -40
- package/cjs/evaluator/combiners/and.js +6 -2
- package/cjs/evaluator/combiners/ifelseif.js +6 -6
- package/cjs/evaluator/condition/index.js +5 -6
- package/cjs/evaluator/index.js +11 -11
- package/cjs/evaluator/matchers/index.js +1 -3
- package/cjs/evaluator/matchers/matcherTypes.js +0 -1
- package/cjs/evaluator/matchersTransform/index.js +0 -4
- package/cjs/evaluator/parser/index.js +2 -2
- package/cjs/evaluator/value/sanitize.js +0 -1
- package/cjs/logger/constants.js +3 -5
- package/cjs/logger/messages/debug.js +2 -4
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/sdkManager/index.js +1 -2
- package/cjs/services/splitApi.js +4 -3
- package/cjs/storages/AbstractSplitsCacheSync.js +2 -5
- package/cjs/storages/KeyBuilder.js +0 -9
- package/cjs/storages/KeyBuilderCS.js +0 -3
- package/cjs/storages/KeyBuilderSS.js +0 -3
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/cjs/storages/inLocalStorage/index.js +1 -5
- package/cjs/storages/inLocalStorage/validateCache.js +1 -2
- package/cjs/storages/inMemory/InMemoryStorage.js +0 -3
- package/cjs/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/cjs/storages/inRedis/index.js +9 -5
- package/cjs/storages/pluggable/index.js +0 -2
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +4 -51
- package/cjs/sync/polling/pollingManagerCS.js +7 -7
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +33 -51
- package/cjs/sync/streaming/SSEHandler/index.js +0 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +77 -106
- package/cjs/sync/streaming/constants.js +1 -2
- package/cjs/sync/streaming/pushManager.js +16 -3
- package/cjs/sync/syncManagerOnline.js +2 -2
- package/cjs/utils/constants/index.js +2 -3
- package/cjs/utils/labels/index.js +1 -2
- package/esm/evaluator/Engine.js +62 -40
- package/esm/evaluator/combiners/and.js +6 -2
- package/esm/evaluator/combiners/ifelseif.js +7 -7
- package/esm/evaluator/condition/index.js +5 -6
- package/esm/evaluator/index.js +12 -12
- package/esm/evaluator/matchers/index.js +1 -3
- package/esm/evaluator/matchers/matcherTypes.js +0 -1
- package/esm/evaluator/matchersTransform/index.js +0 -4
- package/esm/evaluator/parser/index.js +2 -2
- package/esm/evaluator/value/sanitize.js +0 -1
- package/esm/logger/constants.js +0 -2
- package/esm/logger/messages/debug.js +2 -4
- package/esm/logger/messages/warn.js +1 -1
- package/esm/sdkManager/index.js +1 -2
- package/esm/services/splitApi.js +4 -3
- package/esm/storages/AbstractSplitsCacheSync.js +2 -5
- package/esm/storages/KeyBuilder.js +0 -9
- package/esm/storages/KeyBuilderCS.js +0 -3
- package/esm/storages/KeyBuilderSS.js +0 -3
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/esm/storages/inLocalStorage/index.js +1 -5
- package/esm/storages/inLocalStorage/validateCache.js +1 -2
- package/esm/storages/inMemory/InMemoryStorage.js +0 -3
- package/esm/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/esm/storages/inRedis/index.js +9 -5
- package/esm/storages/pluggable/index.js +0 -2
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +4 -51
- package/esm/sync/polling/pollingManagerCS.js +7 -7
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/esm/sync/polling/updaters/splitChangesUpdater.js +33 -51
- package/esm/sync/streaming/SSEHandler/index.js +1 -2
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +73 -102
- package/esm/sync/streaming/constants.js +0 -1
- package/esm/sync/streaming/pushManager.js +19 -6
- package/esm/sync/syncManagerOnline.js +2 -2
- package/esm/utils/constants/index.js +1 -2
- package/esm/utils/labels/index.js +0 -1
- package/package.json +1 -1
- package/src/dtos/types.ts +8 -36
- package/src/evaluator/Engine.ts +69 -42
- package/src/evaluator/combiners/and.ts +4 -5
- package/src/evaluator/combiners/ifelseif.ts +9 -7
- package/src/evaluator/condition/engineUtils.ts +1 -1
- package/src/evaluator/condition/index.ts +12 -12
- package/src/evaluator/index.ts +14 -12
- package/src/evaluator/matchers/index.ts +1 -3
- package/src/evaluator/matchers/matcherTypes.ts +0 -1
- package/src/evaluator/matchersTransform/index.ts +0 -3
- package/src/evaluator/parser/index.ts +3 -3
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +4 -5
- package/src/logger/constants.ts +0 -2
- package/src/logger/messages/debug.ts +2 -4
- package/src/logger/messages/warn.ts +1 -1
- package/src/sdkManager/index.ts +2 -3
- package/src/services/splitApi.ts +4 -3
- package/src/services/types.ts +1 -1
- package/src/storages/AbstractSplitsCacheSync.ts +3 -6
- package/src/storages/KeyBuilder.ts +0 -12
- package/src/storages/KeyBuilderCS.ts +0 -4
- package/src/storages/KeyBuilderSS.ts +0 -4
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +14 -10
- package/src/storages/inLocalStorage/index.ts +1 -5
- package/src/storages/inLocalStorage/validateCache.ts +1 -3
- package/src/storages/inMemory/InMemoryStorage.ts +0 -3
- package/src/storages/inMemory/InMemoryStorageCS.ts +0 -4
- package/src/storages/inRedis/index.ts +11 -7
- package/src/storages/pluggable/index.ts +0 -2
- package/src/storages/types.ts +1 -33
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +4 -62
- package/src/sync/polling/fetchers/types.ts +0 -1
- package/src/sync/polling/pollingManagerCS.ts +7 -7
- package/src/sync/polling/syncTasks/splitsSyncTask.ts +1 -1
- package/src/sync/polling/types.ts +2 -2
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -2
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
- package/src/sync/polling/updaters/splitChangesUpdater.ts +42 -61
- package/src/sync/streaming/SSEHandler/index.ts +1 -2
- package/src/sync/streaming/SSEHandler/types.ts +2 -2
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +68 -98
- package/src/sync/streaming/constants.ts +0 -1
- package/src/sync/streaming/parseUtils.ts +2 -2
- package/src/sync/streaming/pushManager.ts +18 -6
- package/src/sync/streaming/types.ts +2 -3
- package/src/sync/syncManagerOnline.ts +2 -2
- package/src/utils/constants/index.ts +1 -2
- package/src/utils/labels/index.ts +0 -1
- package/src/utils/lang/index.ts +1 -1
- package/types/splitio.d.ts +1 -5
- package/cjs/evaluator/matchers/prerequisites.js +0 -22
- package/cjs/evaluator/matchers/rbsegment.js +0 -44
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +0 -117
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +0 -61
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +0 -64
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +0 -64
- package/esm/evaluator/matchers/prerequisites.js +0 -18
- package/esm/evaluator/matchers/rbsegment.js +0 -40
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +0 -114
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +0 -58
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +0 -61
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +0 -61
- package/src/evaluator/matchers/prerequisites.ts +0 -24
- package/src/evaluator/matchers/rbsegment.ts +0 -62
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +0 -136
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +0 -68
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +0 -79
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +0 -76
|
@@ -1,132 +1,103 @@
|
|
|
1
|
-
import { STREAMING_PARSING_SPLIT_UPDATE } from '../../../logger/constants';
|
|
2
1
|
import { SDK_SPLITS_ARRIVED } from '../../../readiness/constants';
|
|
3
2
|
import { Backoff } from '../../../utils/Backoff';
|
|
4
3
|
import { SPLITS } from '../../../utils/constants';
|
|
5
|
-
import { RB_SEGMENT_UPDATE } from '../constants';
|
|
6
|
-
import { parseFFUpdatePayload } from '../parseUtils';
|
|
7
4
|
import { FETCH_BACKOFF_BASE, FETCH_BACKOFF_MAX_WAIT, FETCH_BACKOFF_MAX_RETRIES } from './constants';
|
|
8
5
|
/**
|
|
9
6
|
* SplitsUpdateWorker factory
|
|
10
7
|
*/
|
|
11
|
-
export function SplitsUpdateWorker(log,
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
export function SplitsUpdateWorker(log, splitsCache, splitsSyncTask, splitsEventEmitter, telemetryTracker, segmentsSyncTask) {
|
|
9
|
+
var maxChangeNumber = 0;
|
|
10
|
+
var handleNewEvent = false;
|
|
11
|
+
var isHandlingEvent;
|
|
12
|
+
var cdnBypass;
|
|
13
|
+
var payload;
|
|
14
|
+
var backoff = new Backoff(__handleSplitUpdateCall, FETCH_BACKOFF_BASE, FETCH_BACKOFF_MAX_WAIT);
|
|
15
|
+
function __handleSplitUpdateCall() {
|
|
16
|
+
isHandlingEvent = true;
|
|
17
|
+
if (maxChangeNumber > splitsCache.getChangeNumber()) {
|
|
18
|
+
handleNewEvent = false;
|
|
19
|
+
var splitUpdateNotification_1 = payload ? { payload: payload, changeNumber: maxChangeNumber } : undefined;
|
|
20
|
+
// fetch splits revalidating data if cached
|
|
21
|
+
splitsSyncTask.execute(true, cdnBypass ? maxChangeNumber : undefined, splitUpdateNotification_1).then(function () {
|
|
22
|
+
if (!isHandlingEvent)
|
|
23
|
+
return; // halt if `stop` has been called
|
|
24
|
+
if (handleNewEvent) {
|
|
25
|
+
__handleSplitUpdateCall();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
if (splitUpdateNotification_1)
|
|
29
|
+
telemetryTracker.trackUpdatesFromSSE(SPLITS);
|
|
30
|
+
// fetch new registered segments for server-side API. Not retrying on error
|
|
31
|
+
if (segmentsSyncTask)
|
|
32
|
+
segmentsSyncTask.execute(true);
|
|
33
|
+
var attempts = backoff.attempts + 1;
|
|
34
|
+
if (maxChangeNumber <= splitsCache.getChangeNumber()) {
|
|
35
|
+
log.debug("Refresh completed" + (cdnBypass ? ' bypassing the CDN' : '') + " in " + attempts + " attempts.");
|
|
36
|
+
isHandlingEvent = false;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (attempts < FETCH_BACKOFF_MAX_RETRIES) {
|
|
40
|
+
backoff.scheduleCall();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (cdnBypass) {
|
|
44
|
+
log.debug("No changes fetched after " + attempts + " attempts with CDN bypassed.");
|
|
45
|
+
isHandlingEvent = false;
|
|
31
46
|
}
|
|
32
47
|
else {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (segmentsSyncTask)
|
|
37
|
-
segmentsSyncTask.execute(true);
|
|
38
|
-
var attempts = backoff.attempts + 1;
|
|
39
|
-
if (ff.isSync() && rbs.isSync()) {
|
|
40
|
-
log.debug("Refresh completed" + (cdnBypass ? ' bypassing the CDN' : '') + " in " + attempts + " attempts.");
|
|
41
|
-
isHandlingEvent = false;
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (attempts < FETCH_BACKOFF_MAX_RETRIES) {
|
|
45
|
-
backoff.scheduleCall();
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (cdnBypass) {
|
|
49
|
-
log.debug("No changes fetched after " + attempts + " attempts with CDN bypassed.");
|
|
50
|
-
isHandlingEvent = false;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
backoff.reset();
|
|
54
|
-
cdnBypass = true;
|
|
55
|
-
__handleSplitUpdateCall();
|
|
56
|
-
}
|
|
48
|
+
backoff.reset();
|
|
49
|
+
cdnBypass = true;
|
|
50
|
+
__handleSplitUpdateCall();
|
|
57
51
|
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
isHandlingEvent = false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
/**
|
|
66
|
-
* Invoked by NotificationProcessor on SPLIT_UPDATE or RB_SEGMENT_UPDATE event
|
|
67
|
-
*
|
|
68
|
-
* @param changeNumber - change number of the notification
|
|
69
|
-
*/
|
|
70
|
-
put: function (_a, payload) {
|
|
71
|
-
var changeNumber = _a.changeNumber, pcn = _a.pcn, type = _a.type;
|
|
72
|
-
var currentChangeNumber = cache.getChangeNumber();
|
|
73
|
-
if (changeNumber <= currentChangeNumber || changeNumber <= maxChangeNumber)
|
|
74
|
-
return;
|
|
75
|
-
maxChangeNumber = changeNumber;
|
|
76
|
-
handleNewEvent = true;
|
|
77
|
-
cdnBypass = false;
|
|
78
|
-
instantUpdate = undefined;
|
|
79
|
-
if (payload && currentChangeNumber === pcn) {
|
|
80
|
-
instantUpdate = { payload: payload, changeNumber: changeNumber, type: type };
|
|
81
52
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
isHandlingEvent = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Invoked by NotificationProcessor on SPLIT_UPDATE event
|
|
61
|
+
*
|
|
62
|
+
* @param changeNumber - change number of the SPLIT_UPDATE notification
|
|
63
|
+
*/
|
|
64
|
+
function put(_a, _payload) {
|
|
65
|
+
var changeNumber = _a.changeNumber, pcn = _a.pcn;
|
|
66
|
+
var currentChangeNumber = splitsCache.getChangeNumber();
|
|
67
|
+
if (changeNumber <= currentChangeNumber || changeNumber <= maxChangeNumber)
|
|
68
|
+
return;
|
|
69
|
+
maxChangeNumber = changeNumber;
|
|
70
|
+
handleNewEvent = true;
|
|
71
|
+
cdnBypass = false;
|
|
72
|
+
payload = undefined;
|
|
73
|
+
if (_payload && currentChangeNumber === pcn) {
|
|
74
|
+
payload = _payload;
|
|
75
|
+
}
|
|
76
|
+
if (backoff.timeoutID || !isHandlingEvent)
|
|
77
|
+
__handleSplitUpdateCall();
|
|
78
|
+
backoff.reset();
|
|
94
79
|
}
|
|
95
80
|
return {
|
|
96
|
-
put:
|
|
97
|
-
if (parsedData.d && parsedData.c !== undefined) {
|
|
98
|
-
try {
|
|
99
|
-
var payload = parseFFUpdatePayload(parsedData.c, parsedData.d);
|
|
100
|
-
if (payload) {
|
|
101
|
-
(parsedData.type === RB_SEGMENT_UPDATE ? rbs : ff).put(parsedData, payload);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
catch (e) {
|
|
106
|
-
log.warn(STREAMING_PARSING_SPLIT_UPDATE, [parsedData.type, e]);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
(parsedData.type === RB_SEGMENT_UPDATE ? rbs : ff).put(parsedData);
|
|
110
|
-
},
|
|
81
|
+
put: put,
|
|
111
82
|
/**
|
|
112
83
|
* Invoked by NotificationProcessor on SPLIT_KILL event
|
|
113
84
|
*
|
|
114
|
-
* @param changeNumber - change number of the notification
|
|
85
|
+
* @param changeNumber - change number of the SPLIT_UPDATE notification
|
|
115
86
|
* @param splitName - name of split to kill
|
|
116
87
|
* @param defaultTreatment - default treatment value
|
|
117
88
|
*/
|
|
118
89
|
killSplit: function (_a) {
|
|
119
90
|
var changeNumber = _a.changeNumber, splitName = _a.splitName, defaultTreatment = _a.defaultTreatment;
|
|
120
|
-
if (
|
|
91
|
+
if (splitsCache.killLocally(splitName, defaultTreatment, changeNumber)) {
|
|
121
92
|
// trigger an SDK_UPDATE if Split was killed locally
|
|
122
93
|
splitsEventEmitter.emit(SDK_SPLITS_ARRIVED, true);
|
|
123
94
|
}
|
|
124
95
|
// queues the SplitChanges fetch (only if changeNumber is newer)
|
|
125
|
-
|
|
96
|
+
put({ changeNumber: changeNumber });
|
|
126
97
|
},
|
|
127
98
|
stop: function () {
|
|
128
|
-
|
|
129
|
-
|
|
99
|
+
isHandlingEvent = false;
|
|
100
|
+
backoff.reset();
|
|
130
101
|
}
|
|
131
102
|
};
|
|
132
103
|
}
|
|
@@ -27,7 +27,6 @@ export var MEMBERSHIPS_LS_UPDATE = 'MEMBERSHIPS_LS_UPDATE';
|
|
|
27
27
|
export var SEGMENT_UPDATE = 'SEGMENT_UPDATE';
|
|
28
28
|
export var SPLIT_KILL = 'SPLIT_KILL';
|
|
29
29
|
export var SPLIT_UPDATE = 'SPLIT_UPDATE';
|
|
30
|
-
export var RB_SEGMENT_UPDATE = 'RB_SEGMENT_UPDATE';
|
|
31
30
|
// Control-type push notifications, handled by NotificationKeeper
|
|
32
31
|
export var CONTROL = 'CONTROL';
|
|
33
32
|
export var OCCUPANCY = 'OCCUPANCY';
|
|
@@ -8,10 +8,10 @@ import { authenticateFactory, hashUserKey } from './AuthClient';
|
|
|
8
8
|
import { forOwn } from '../../utils/lang';
|
|
9
9
|
import { SSEClient } from './SSEClient';
|
|
10
10
|
import { getMatching } from '../../utils/key';
|
|
11
|
-
import { MEMBERSHIPS_MS_UPDATE, MEMBERSHIPS_LS_UPDATE, PUSH_NONRETRYABLE_ERROR, PUSH_SUBSYSTEM_DOWN, SECONDS_BEFORE_EXPIRATION, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE,
|
|
12
|
-
import { STREAMING_FALLBACK, STREAMING_REFRESH_TOKEN, STREAMING_CONNECTING, STREAMING_DISABLED, ERROR_STREAMING_AUTH, STREAMING_DISCONNECTING, STREAMING_RECONNECT, STREAMING_PARSING_MEMBERSHIPS_UPDATE } from '../../logger/constants';
|
|
11
|
+
import { MEMBERSHIPS_MS_UPDATE, MEMBERSHIPS_LS_UPDATE, PUSH_NONRETRYABLE_ERROR, PUSH_SUBSYSTEM_DOWN, SECONDS_BEFORE_EXPIRATION, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE, PUSH_RETRYABLE_ERROR, PUSH_SUBSYSTEM_UP, ControlType } from './constants';
|
|
12
|
+
import { STREAMING_FALLBACK, STREAMING_REFRESH_TOKEN, STREAMING_CONNECTING, STREAMING_DISABLED, ERROR_STREAMING_AUTH, STREAMING_DISCONNECTING, STREAMING_RECONNECT, STREAMING_PARSING_MEMBERSHIPS_UPDATE, STREAMING_PARSING_SPLIT_UPDATE } from '../../logger/constants';
|
|
13
13
|
import { UpdateStrategy } from './SSEHandler/types';
|
|
14
|
-
import { getDelay, isInBitmap, parseBitmap, parseKeyList } from './parseUtils';
|
|
14
|
+
import { getDelay, isInBitmap, parseBitmap, parseFFUpdatePayload, parseKeyList } from './parseUtils';
|
|
15
15
|
import { hash64 } from '../../utils/murmur3/murmur3_64';
|
|
16
16
|
import { TOKEN_REFRESH, AUTH_REJECTION } from '../../utils/constants';
|
|
17
17
|
/**
|
|
@@ -43,7 +43,7 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
43
43
|
// MySegmentsUpdateWorker (client-side) are initiated in `add` method
|
|
44
44
|
var segmentsUpdateWorker = userKey ? undefined : SegmentsUpdateWorker(log, pollingManager.segmentsSyncTask, storage.segments);
|
|
45
45
|
// For server-side we pass the segmentsSyncTask, used by SplitsUpdateWorker to fetch new segments
|
|
46
|
-
var splitsUpdateWorker = SplitsUpdateWorker(log, storage, pollingManager.splitsSyncTask, readiness.splits, telemetryTracker, userKey ? undefined : pollingManager.segmentsSyncTask);
|
|
46
|
+
var splitsUpdateWorker = SplitsUpdateWorker(log, storage.splits, pollingManager.splitsSyncTask, readiness.splits, telemetryTracker, userKey ? undefined : pollingManager.segmentsSyncTask);
|
|
47
47
|
// [Only for client-side] map of hashes to user keys, to dispatch membership update events to the corresponding MySegmentsUpdateWorker
|
|
48
48
|
var userKeyHashes = {};
|
|
49
49
|
// [Only for client-side] map of user keys to their corresponding hash64 and MySegmentsUpdateWorkers.
|
|
@@ -179,8 +179,21 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
179
179
|
});
|
|
180
180
|
/** Functions related to synchronization (Queues and Workers in the spec) */
|
|
181
181
|
pushEmitter.on(SPLIT_KILL, splitsUpdateWorker.killSplit);
|
|
182
|
-
pushEmitter.on(SPLIT_UPDATE,
|
|
183
|
-
|
|
182
|
+
pushEmitter.on(SPLIT_UPDATE, function (parsedData) {
|
|
183
|
+
if (parsedData.d && parsedData.c !== undefined) {
|
|
184
|
+
try {
|
|
185
|
+
var payload = parseFFUpdatePayload(parsedData.c, parsedData.d);
|
|
186
|
+
if (payload) {
|
|
187
|
+
splitsUpdateWorker.put(parsedData, payload);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
192
|
+
log.warn(STREAMING_PARSING_SPLIT_UPDATE, [e]);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
splitsUpdateWorker.put(parsedData);
|
|
196
|
+
});
|
|
184
197
|
function handleMySegmentsUpdate(parsedData) {
|
|
185
198
|
switch (parsedData.u) {
|
|
186
199
|
case UpdateStrategy.BoundedFetchRequest: {
|
|
@@ -127,7 +127,7 @@ export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFacto
|
|
|
127
127
|
if (pushManager) {
|
|
128
128
|
if (pollingManager.isRunning()) {
|
|
129
129
|
// if doing polling, we must start the periodic fetch of data
|
|
130
|
-
if (storage.splits.usesSegments()
|
|
130
|
+
if (storage.splits.usesSegments())
|
|
131
131
|
mySegmentsSyncTask.start();
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
@@ -137,7 +137,7 @@ export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFacto
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
else {
|
|
140
|
-
if (storage.splits.usesSegments()
|
|
140
|
+
if (storage.splits.usesSegments())
|
|
141
141
|
mySegmentsSyncTask.start();
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -86,8 +86,7 @@ export var NON_REQUESTED = 1;
|
|
|
86
86
|
export var DISABLED = 0;
|
|
87
87
|
export var ENABLED = 1;
|
|
88
88
|
export var PAUSED = 2;
|
|
89
|
-
export var FLAG_SPEC_VERSION = '1.
|
|
89
|
+
export var FLAG_SPEC_VERSION = '1.2';
|
|
90
90
|
// Matcher types
|
|
91
91
|
export var IN_SEGMENT = 'IN_SEGMENT';
|
|
92
92
|
export var IN_LARGE_SEGMENT = 'IN_LARGE_SEGMENT';
|
|
93
|
-
export var IN_RULE_BASED_SEGMENT = 'IN_RULE_BASED_SEGMENT';
|
package/package.json
CHANGED
package/src/dtos/types.ts
CHANGED
|
@@ -66,11 +66,6 @@ interface IInSegmentMatcher extends ISplitMatcherBase {
|
|
|
66
66
|
userDefinedSegmentMatcherData: IInSegmentMatcherData
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
interface IInRBSegmentMatcher extends ISplitMatcherBase {
|
|
70
|
-
matcherType: 'IN_RULE_BASED_SEGMENT',
|
|
71
|
-
userDefinedSegmentMatcherData: IInSegmentMatcherData
|
|
72
|
-
}
|
|
73
|
-
|
|
74
69
|
interface IInLargeSegmentMatcher extends ISplitMatcherBase {
|
|
75
70
|
matcherType: 'IN_LARGE_SEGMENT',
|
|
76
71
|
userDefinedLargeSegmentMatcherData: IInLargeSegmentMatcherData
|
|
@@ -181,7 +176,7 @@ export type ISplitMatcher = IAllKeysMatcher | IInSegmentMatcher | IWhitelistMatc
|
|
|
181
176
|
ILessThanOrEqualToMatcher | IBetweenMatcher | IEqualToSetMatcher | IContainsAnyOfSetMatcher | IContainsAllOfSetMatcher | IPartOfSetMatcher |
|
|
182
177
|
IStartsWithMatcher | IEndsWithMatcher | IContainsStringMatcher | IInSplitTreatmentMatcher | IEqualToBooleanMatcher | IMatchesStringMatcher |
|
|
183
178
|
IEqualToSemverMatcher | IGreaterThanOrEqualToSemverMatcher | ILessThanOrEqualToSemverMatcher | IBetweenSemverMatcher | IInListSemverMatcher |
|
|
184
|
-
IInLargeSegmentMatcher
|
|
179
|
+
IInLargeSegmentMatcher
|
|
185
180
|
|
|
186
181
|
/** Split object */
|
|
187
182
|
export interface ISplitPartition {
|
|
@@ -194,34 +189,19 @@ export interface ISplitCondition {
|
|
|
194
189
|
combiner: 'AND',
|
|
195
190
|
matchers: ISplitMatcher[]
|
|
196
191
|
}
|
|
197
|
-
partitions
|
|
198
|
-
label
|
|
199
|
-
conditionType
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export interface IRBSegment {
|
|
203
|
-
name: string,
|
|
204
|
-
changeNumber: number,
|
|
205
|
-
status: 'ACTIVE' | 'ARCHIVED',
|
|
206
|
-
conditions?: ISplitCondition[],
|
|
207
|
-
excluded?: {
|
|
208
|
-
keys?: string[],
|
|
209
|
-
segments?: string[]
|
|
210
|
-
}
|
|
192
|
+
partitions: ISplitPartition[]
|
|
193
|
+
label: string
|
|
194
|
+
conditionType: 'ROLLOUT' | 'WHITELIST'
|
|
211
195
|
}
|
|
212
196
|
|
|
213
197
|
export interface ISplit {
|
|
214
198
|
name: string,
|
|
215
199
|
changeNumber: number,
|
|
216
|
-
status: 'ACTIVE' | 'ARCHIVED',
|
|
217
|
-
conditions: ISplitCondition[],
|
|
218
|
-
prerequisites?: {
|
|
219
|
-
n: string,
|
|
220
|
-
ts: string[]
|
|
221
|
-
}[]
|
|
222
200
|
killed: boolean,
|
|
223
201
|
defaultTreatment: string,
|
|
224
202
|
trafficTypeName: string,
|
|
203
|
+
conditions: ISplitCondition[],
|
|
204
|
+
status: 'ACTIVE' | 'ARCHIVED',
|
|
225
205
|
seed: number,
|
|
226
206
|
trafficAllocation?: number,
|
|
227
207
|
trafficAllocationSeed?: number
|
|
@@ -237,16 +217,8 @@ export type ISplitPartial = Pick<ISplit, 'conditions' | 'configurations' | 'traf
|
|
|
237
217
|
|
|
238
218
|
/** Interface of the parsed JSON response of `/splitChanges` */
|
|
239
219
|
export interface ISplitChangesResponse {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
s?: number,
|
|
243
|
-
d: ISplit[]
|
|
244
|
-
},
|
|
245
|
-
rbs?: {
|
|
246
|
-
t: number,
|
|
247
|
-
s?: number,
|
|
248
|
-
d: IRBSegment[]
|
|
249
|
-
}
|
|
220
|
+
till: number,
|
|
221
|
+
splits: ISplit[]
|
|
250
222
|
}
|
|
251
223
|
|
|
252
224
|
/** Interface of the parsed JSON response of `/segmentChanges/{segmentName}` */
|
package/src/evaluator/Engine.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { get
|
|
1
|
+
import { get } from '../utils/lang';
|
|
2
2
|
import { parser } from './parser';
|
|
3
3
|
import { keyParser } from '../utils/key';
|
|
4
4
|
import { thenable } from '../utils/promise/thenable';
|
|
5
|
-
import { NO_CONDITION_MATCH, SPLIT_ARCHIVED, SPLIT_KILLED
|
|
5
|
+
import { EXCEPTION, NO_CONDITION_MATCH, SPLIT_ARCHIVED, SPLIT_KILLED } from '../utils/labels';
|
|
6
6
|
import { CONTROL } from '../utils/constants';
|
|
7
7
|
import { ISplit, MaybeThenable } from '../dtos/types';
|
|
8
8
|
import SplitIO from '../../types/splitio';
|
|
9
9
|
import { IStorageAsync, IStorageSync } from '../storages/types';
|
|
10
|
-
import { IEvaluation, IEvaluationResult, ISplitEvaluator } from './types';
|
|
10
|
+
import { IEvaluation, IEvaluationResult, IEvaluator, ISplitEvaluator } from './types';
|
|
11
11
|
import { ILogger } from '../logger/types';
|
|
12
|
-
import { ENGINE_DEFAULT } from '../logger/constants';
|
|
13
|
-
import { prerequisitesMatcherContext } from './matchers/prerequisites';
|
|
14
12
|
|
|
15
13
|
function evaluationResult(result: IEvaluation | undefined, defaultTreatment: string): IEvaluationResult {
|
|
16
14
|
return {
|
|
@@ -19,55 +17,84 @@ function evaluationResult(result: IEvaluation | undefined, defaultTreatment: str
|
|
|
19
17
|
};
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
export
|
|
23
|
-
const { killed, seed, trafficAllocation, trafficAllocationSeed, status, conditions, prerequisites } = split;
|
|
20
|
+
export class Engine {
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
constructor(private baseInfo: ISplit, private evaluator: IEvaluator) {
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
getTreatment(key: SplitIO.SplitKey, attributes: SplitIO.Attributes | undefined, splitEvaluator: ISplitEvaluator): MaybeThenable<IEvaluationResult> {
|
|
24
|
+
// in case we don't have a default treatment in the instantiation, use 'control'
|
|
25
|
+
if (typeof this.baseInfo.defaultTreatment !== 'string') {
|
|
26
|
+
this.baseInfo.defaultTreatment = CONTROL;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
33
29
|
|
|
34
|
-
|
|
30
|
+
static parse(log: ILogger, splitFlatStructure: ISplit, storage: IStorageSync | IStorageAsync) {
|
|
31
|
+
const conditions = splitFlatStructure.conditions;
|
|
32
|
+
const evaluator = parser(log, conditions, storage);
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
log.debug(ENGINE_DEFAULT, ['Prerequisite not met']);
|
|
39
|
-
return {
|
|
40
|
-
treatment: defaultTreatment,
|
|
41
|
-
label: PREREQUISITES_NOT_MET
|
|
42
|
-
};
|
|
43
|
-
}
|
|
34
|
+
return new Engine(splitFlatStructure, evaluator);
|
|
35
|
+
}
|
|
44
36
|
|
|
45
|
-
|
|
37
|
+
getKey() {
|
|
38
|
+
return this.baseInfo.name;
|
|
39
|
+
}
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
getTreatment(key: SplitIO.SplitKey, attributes: SplitIO.Attributes | undefined, splitEvaluator: ISplitEvaluator): MaybeThenable<IEvaluationResult> {
|
|
42
|
+
const {
|
|
43
|
+
killed,
|
|
44
|
+
seed,
|
|
45
|
+
defaultTreatment,
|
|
46
|
+
trafficAllocation,
|
|
47
|
+
trafficAllocationSeed
|
|
48
|
+
} = this.baseInfo;
|
|
49
|
+
let parsedKey;
|
|
50
|
+
let treatment;
|
|
51
|
+
let label;
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
try {
|
|
54
|
+
parsedKey = keyParser(key);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
return {
|
|
53
57
|
treatment: CONTROL,
|
|
54
|
-
label:
|
|
58
|
+
label: EXCEPTION
|
|
55
59
|
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (this.isGarbage()) {
|
|
63
|
+
treatment = CONTROL;
|
|
64
|
+
label = SPLIT_ARCHIVED;
|
|
65
|
+
} else if (killed) {
|
|
66
|
+
treatment = defaultTreatment;
|
|
67
|
+
label = SPLIT_KILLED;
|
|
68
|
+
} else {
|
|
69
|
+
const evaluation = this.evaluator(
|
|
70
|
+
parsedKey,
|
|
71
|
+
seed,
|
|
72
|
+
trafficAllocation,
|
|
73
|
+
trafficAllocationSeed,
|
|
74
|
+
attributes,
|
|
75
|
+
splitEvaluator
|
|
76
|
+
);
|
|
56
77
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
// Evaluation could be async, so we should handle that case checking for a
|
|
79
|
+
// thenable object
|
|
80
|
+
if (thenable(evaluation)) {
|
|
81
|
+
return evaluation.then(result => evaluationResult(result, defaultTreatment));
|
|
82
|
+
} else {
|
|
83
|
+
return evaluationResult(evaluation, defaultTreatment);
|
|
63
84
|
}
|
|
85
|
+
}
|
|
64
86
|
|
|
65
|
-
|
|
87
|
+
return {
|
|
88
|
+
treatment,
|
|
89
|
+
label
|
|
90
|
+
};
|
|
91
|
+
}
|
|
66
92
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
};
|
|
93
|
+
isGarbage() {
|
|
94
|
+
return this.baseInfo.status === 'ARCHIVED';
|
|
95
|
+
}
|
|
72
96
|
|
|
97
|
+
getChangeNumber() {
|
|
98
|
+
return this.baseInfo.changeNumber;
|
|
99
|
+
}
|
|
73
100
|
}
|
|
@@ -2,11 +2,10 @@ import { findIndex } from '../../utils/lang';
|
|
|
2
2
|
import { ILogger } from '../../logger/types';
|
|
3
3
|
import { thenable } from '../../utils/promise/thenable';
|
|
4
4
|
import { MaybeThenable } from '../../dtos/types';
|
|
5
|
-
import {
|
|
5
|
+
import { IMatcher } from '../types';
|
|
6
6
|
import { ENGINE_COMBINER_AND } from '../../logger/constants';
|
|
7
|
-
import SplitIO from '../../../types/splitio';
|
|
8
7
|
|
|
9
|
-
export function andCombinerContext(log: ILogger, matchers:
|
|
8
|
+
export function andCombinerContext(log: ILogger, matchers: IMatcher[]) {
|
|
10
9
|
|
|
11
10
|
function andResults(results: boolean[]): boolean {
|
|
12
11
|
// Array.prototype.every is supported by target environments
|
|
@@ -16,8 +15,8 @@ export function andCombinerContext(log: ILogger, matchers: Array<(key: SplitIO.S
|
|
|
16
15
|
return hasMatchedAll;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
return function andCombiner(
|
|
20
|
-
const matcherResults = matchers.map(matcher => matcher(
|
|
18
|
+
return function andCombiner(...params: any): MaybeThenable<boolean> {
|
|
19
|
+
const matcherResults = matchers.map(matcher => matcher(...params));
|
|
21
20
|
|
|
22
21
|
// If any matching result is a thenable we should use Promise.all
|
|
23
22
|
if (findIndex(matcherResults, thenable) !== -1) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { findIndex
|
|
1
|
+
import { findIndex } from '../../utils/lang';
|
|
2
2
|
import { ILogger } from '../../logger/types';
|
|
3
3
|
import { thenable } from '../../utils/promise/thenable';
|
|
4
4
|
import { UNSUPPORTED_MATCHER_TYPE } from '../../utils/labels';
|
|
@@ -18,12 +18,14 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function
|
|
22
|
-
|
|
21
|
+
function computeTreatment(predicateResults: Array<IEvaluation | undefined>) {
|
|
22
|
+
const len = predicateResults.length;
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < len; i++) {
|
|
23
25
|
const evaluation = predicateResults[i];
|
|
24
26
|
|
|
25
27
|
if (evaluation !== undefined) {
|
|
26
|
-
|
|
28
|
+
log.debug(ENGINE_COMBINER_IFELSEIF, [evaluation.treatment]);
|
|
27
29
|
|
|
28
30
|
return evaluation;
|
|
29
31
|
}
|
|
@@ -33,7 +35,7 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
33
35
|
return undefined;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
function ifElseIfCombiner(key: SplitIO.
|
|
38
|
+
function ifElseIfCombiner(key: SplitIO.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
|
|
37
39
|
// In Async environments we are going to have async predicates. There is none way to know
|
|
38
40
|
// before hand so we need to evaluate all the predicates, verify for thenables, and finally,
|
|
39
41
|
// define how to return the treatment (wrap result into a Promise or not).
|
|
@@ -41,10 +43,10 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
41
43
|
|
|
42
44
|
// if we find a thenable
|
|
43
45
|
if (findIndex(predicateResults, thenable) !== -1) {
|
|
44
|
-
return Promise.all(predicateResults).then(results =>
|
|
46
|
+
return Promise.all(predicateResults).then(results => computeTreatment(results));
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
return
|
|
49
|
+
return computeTreatment(predicateResults as IEvaluation[]);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
// if there is none predicates, then there was an error in parsing phase
|
|
@@ -5,7 +5,7 @@ import { bucket } from '../../utils/murmur3/murmur3';
|
|
|
5
5
|
/**
|
|
6
6
|
* Get the treatment name given a key, a seed, and the percentage of each treatment.
|
|
7
7
|
*/
|
|
8
|
-
export function getTreatment(log: ILogger, key: string, seed: number
|
|
8
|
+
export function getTreatment(log: ILogger, key: string, seed: number, treatments: { getTreatmentFor: (x: number) => string }) {
|
|
9
9
|
const _bucket = bucket(key, seed);
|
|
10
10
|
|
|
11
11
|
const treatment = treatments.getTreatmentFor(_bucket);
|