@splitsoftware/splitio-commons 2.3.0 → 2.3.1-rc.0
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 +4 -0
- package/README.md +1 -0
- package/cjs/evaluator/Engine.js +40 -61
- package/cjs/evaluator/combiners/and.js +2 -6
- package/cjs/evaluator/combiners/ifelseif.js +6 -6
- package/cjs/evaluator/condition/index.js +6 -5
- package/cjs/evaluator/index.js +11 -11
- package/cjs/evaluator/matchers/index.js +3 -1
- package/cjs/evaluator/matchers/matcherTypes.js +1 -0
- package/cjs/evaluator/matchers/prerequisites.js +22 -0
- package/cjs/evaluator/matchers/rbsegment.js +56 -0
- package/cjs/evaluator/matchersTransform/index.js +4 -0
- package/cjs/evaluator/parser/index.js +2 -2
- package/cjs/evaluator/value/sanitize.js +1 -0
- package/cjs/logger/constants.js +5 -3
- package/cjs/logger/messages/debug.js +4 -2
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/sdkManager/index.js +2 -1
- package/cjs/services/splitApi.js +3 -4
- package/cjs/services/splitHttpClient.js +1 -1
- package/cjs/storages/AbstractSplitsCacheSync.js +5 -2
- package/cjs/storages/KeyBuilder.js +9 -0
- package/cjs/storages/KeyBuilderCS.js +3 -0
- package/cjs/storages/KeyBuilderSS.js +3 -0
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +117 -0
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +9 -14
- package/cjs/storages/inLocalStorage/index.js +5 -1
- package/cjs/storages/inLocalStorage/validateCache.js +2 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +3 -0
- package/cjs/storages/inMemory/InMemoryStorageCS.js +4 -0
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +61 -0
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +1 -0
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +64 -0
- package/cjs/storages/inRedis/index.js +2 -0
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +64 -0
- package/cjs/storages/pluggable/index.js +2 -0
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +54 -4
- 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 +59 -33
- package/cjs/sync/streaming/SSEHandler/index.js +1 -0
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +106 -77
- package/cjs/sync/streaming/constants.js +2 -1
- package/cjs/sync/streaming/pushManager.js +3 -16
- package/cjs/sync/syncManagerOnline.js +2 -2
- package/cjs/utils/constants/index.js +6 -2
- package/cjs/utils/labels/index.js +2 -1
- package/esm/evaluator/Engine.js +40 -62
- package/esm/evaluator/combiners/and.js +2 -6
- package/esm/evaluator/combiners/ifelseif.js +7 -7
- package/esm/evaluator/condition/index.js +6 -5
- package/esm/evaluator/index.js +12 -12
- package/esm/evaluator/matchers/index.js +3 -1
- package/esm/evaluator/matchers/matcherTypes.js +1 -0
- package/esm/evaluator/matchers/prerequisites.js +18 -0
- package/esm/evaluator/matchers/rbsegment.js +52 -0
- package/esm/evaluator/matchersTransform/index.js +4 -0
- package/esm/evaluator/parser/index.js +2 -2
- package/esm/evaluator/value/sanitize.js +1 -0
- package/esm/logger/constants.js +2 -0
- package/esm/logger/messages/debug.js +4 -2
- package/esm/logger/messages/warn.js +1 -1
- package/esm/sdkManager/index.js +2 -1
- package/esm/services/splitApi.js +3 -4
- package/esm/services/splitHttpClient.js +1 -1
- package/esm/storages/AbstractSplitsCacheSync.js +5 -2
- package/esm/storages/KeyBuilder.js +9 -0
- package/esm/storages/KeyBuilderCS.js +3 -0
- package/esm/storages/KeyBuilderSS.js +3 -0
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +114 -0
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +9 -14
- package/esm/storages/inLocalStorage/index.js +5 -1
- package/esm/storages/inLocalStorage/validateCache.js +2 -1
- package/esm/storages/inMemory/InMemoryStorage.js +3 -0
- package/esm/storages/inMemory/InMemoryStorageCS.js +4 -0
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +58 -0
- package/esm/storages/inMemory/SplitsCacheInMemory.js +1 -0
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +61 -0
- package/esm/storages/inRedis/index.js +2 -0
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +61 -0
- package/esm/storages/pluggable/index.js +2 -0
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +54 -4
- 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 +59 -33
- package/esm/sync/streaming/SSEHandler/index.js +2 -1
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +102 -73
- package/esm/sync/streaming/constants.js +1 -0
- package/esm/sync/streaming/pushManager.js +6 -19
- package/esm/sync/syncManagerOnline.js +2 -2
- package/esm/utils/constants/index.js +5 -1
- package/esm/utils/labels/index.js +1 -0
- package/package.json +1 -1
- package/src/dtos/types.ts +41 -8
- package/src/evaluator/Engine.ts +42 -69
- package/src/evaluator/combiners/and.ts +5 -4
- package/src/evaluator/combiners/ifelseif.ts +7 -9
- package/src/evaluator/condition/engineUtils.ts +1 -1
- package/src/evaluator/condition/index.ts +12 -12
- package/src/evaluator/index.ts +12 -14
- package/src/evaluator/matchers/index.ts +3 -1
- package/src/evaluator/matchers/matcherTypes.ts +1 -0
- package/src/evaluator/matchers/prerequisites.ts +24 -0
- package/src/evaluator/matchers/rbsegment.ts +74 -0
- package/src/evaluator/matchersTransform/index.ts +3 -0
- 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 +5 -4
- package/src/logger/constants.ts +2 -0
- package/src/logger/messages/debug.ts +4 -2
- package/src/logger/messages/warn.ts +1 -1
- package/src/sdkManager/index.ts +3 -2
- package/src/services/splitApi.ts +3 -4
- package/src/services/splitHttpClient.ts +1 -1
- package/src/services/types.ts +1 -1
- package/src/storages/AbstractSplitsCacheSync.ts +6 -3
- package/src/storages/KeyBuilder.ts +12 -0
- package/src/storages/KeyBuilderCS.ts +4 -0
- package/src/storages/KeyBuilderSS.ts +4 -0
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +136 -0
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +10 -14
- package/src/storages/inLocalStorage/index.ts +5 -1
- package/src/storages/inLocalStorage/validateCache.ts +3 -1
- package/src/storages/inMemory/InMemoryStorage.ts +3 -0
- package/src/storages/inMemory/InMemoryStorageCS.ts +4 -0
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +68 -0
- package/src/storages/inMemory/SplitsCacheInMemory.ts +1 -0
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +79 -0
- package/src/storages/inRedis/index.ts +2 -0
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +76 -0
- package/src/storages/pluggable/index.ts +2 -0
- package/src/storages/types.ts +33 -1
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +65 -4
- package/src/sync/polling/fetchers/types.ts +1 -0
- 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 +70 -43
- package/src/sync/streaming/SSEHandler/index.ts +2 -1
- package/src/sync/streaming/SSEHandler/types.ts +2 -2
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +98 -68
- package/src/sync/streaming/constants.ts +1 -0
- package/src/sync/streaming/parseUtils.ts +2 -2
- package/src/sync/streaming/pushManager.ts +6 -18
- package/src/sync/streaming/types.ts +3 -2
- package/src/sync/syncManagerOnline.ts +2 -2
- package/src/utils/constants/index.ts +6 -1
- package/src/utils/labels/index.ts +1 -0
- package/src/utils/lang/index.ts +1 -1
- package/types/splitio.d.ts +5 -1
|
@@ -1,103 +1,132 @@
|
|
|
1
|
+
import { STREAMING_PARSING_SPLIT_UPDATE } from '../../../logger/constants';
|
|
1
2
|
import { SDK_SPLITS_ARRIVED } from '../../../readiness/constants';
|
|
2
3
|
import { Backoff } from '../../../utils/Backoff';
|
|
3
4
|
import { SPLITS } from '../../../utils/constants';
|
|
5
|
+
import { RB_SEGMENT_UPDATE } from '../constants';
|
|
6
|
+
import { parseFFUpdatePayload } from '../parseUtils';
|
|
4
7
|
import { FETCH_BACKOFF_BASE, FETCH_BACKOFF_MAX_WAIT, FETCH_BACKOFF_MAX_RETRIES } from './constants';
|
|
5
8
|
/**
|
|
6
9
|
* SplitsUpdateWorker factory
|
|
7
10
|
*/
|
|
8
|
-
export function SplitsUpdateWorker(log,
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
11
|
+
export function SplitsUpdateWorker(log, storage, splitsSyncTask, splitsEventEmitter, telemetryTracker, segmentsSyncTask) {
|
|
12
|
+
var ff = SplitsUpdateWorker(storage.splits);
|
|
13
|
+
var rbs = SplitsUpdateWorker(storage.rbSegments);
|
|
14
|
+
function SplitsUpdateWorker(cache) {
|
|
15
|
+
var maxChangeNumber = -1;
|
|
16
|
+
var handleNewEvent = false;
|
|
17
|
+
var isHandlingEvent;
|
|
18
|
+
var cdnBypass;
|
|
19
|
+
var instantUpdate;
|
|
20
|
+
var backoff = new Backoff(__handleSplitUpdateCall, FETCH_BACKOFF_BASE, FETCH_BACKOFF_MAX_WAIT);
|
|
21
|
+
function __handleSplitUpdateCall() {
|
|
22
|
+
isHandlingEvent = true;
|
|
23
|
+
if (maxChangeNumber > cache.getChangeNumber()) {
|
|
24
|
+
handleNewEvent = false;
|
|
25
|
+
// fetch splits revalidating data if cached
|
|
26
|
+
splitsSyncTask.execute(true, cdnBypass ? maxChangeNumber : undefined, instantUpdate).then(function () {
|
|
27
|
+
if (!isHandlingEvent)
|
|
28
|
+
return; // halt if `stop` has been called
|
|
29
|
+
if (handleNewEvent) {
|
|
30
|
+
__handleSplitUpdateCall();
|
|
46
31
|
}
|
|
47
32
|
else {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
if (instantUpdate)
|
|
34
|
+
telemetryTracker.trackUpdatesFromSSE(SPLITS);
|
|
35
|
+
// fetch new registered segments for server-side API. Not retrying on error
|
|
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
|
+
}
|
|
51
57
|
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
isHandlingEvent = false;
|
|
62
|
+
}
|
|
75
63
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
}
|
|
82
|
+
if (backoff.timeoutID || !isHandlingEvent)
|
|
83
|
+
__handleSplitUpdateCall();
|
|
84
|
+
backoff.reset();
|
|
85
|
+
},
|
|
86
|
+
stop: function () {
|
|
87
|
+
isHandlingEvent = false;
|
|
88
|
+
backoff.reset();
|
|
89
|
+
},
|
|
90
|
+
isSync: function () {
|
|
91
|
+
return maxChangeNumber <= cache.getChangeNumber();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
79
94
|
}
|
|
80
95
|
return {
|
|
81
|
-
put:
|
|
96
|
+
put: function (parsedData) {
|
|
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
|
+
},
|
|
82
111
|
/**
|
|
83
112
|
* Invoked by NotificationProcessor on SPLIT_KILL event
|
|
84
113
|
*
|
|
85
|
-
* @param changeNumber - change number of the
|
|
114
|
+
* @param changeNumber - change number of the notification
|
|
86
115
|
* @param splitName - name of split to kill
|
|
87
116
|
* @param defaultTreatment - default treatment value
|
|
88
117
|
*/
|
|
89
118
|
killSplit: function (_a) {
|
|
90
119
|
var changeNumber = _a.changeNumber, splitName = _a.splitName, defaultTreatment = _a.defaultTreatment;
|
|
91
|
-
if (
|
|
120
|
+
if (storage.splits.killLocally(splitName, defaultTreatment, changeNumber)) {
|
|
92
121
|
// trigger an SDK_UPDATE if Split was killed locally
|
|
93
122
|
splitsEventEmitter.emit(SDK_SPLITS_ARRIVED, true);
|
|
94
123
|
}
|
|
95
124
|
// queues the SplitChanges fetch (only if changeNumber is newer)
|
|
96
|
-
put({ changeNumber: changeNumber });
|
|
125
|
+
ff.put({ changeNumber: changeNumber });
|
|
97
126
|
},
|
|
98
127
|
stop: function () {
|
|
99
|
-
|
|
100
|
-
|
|
128
|
+
ff.stop();
|
|
129
|
+
rbs.stop();
|
|
101
130
|
}
|
|
102
131
|
};
|
|
103
132
|
}
|
|
@@ -27,6 +27,7 @@ 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';
|
|
30
31
|
// Control-type push notifications, handled by NotificationKeeper
|
|
31
32
|
export var CONTROL = 'CONTROL';
|
|
32
33
|
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, 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
|
|
11
|
+
import { MEMBERSHIPS_MS_UPDATE, MEMBERSHIPS_LS_UPDATE, PUSH_NONRETRYABLE_ERROR, PUSH_SUBSYSTEM_DOWN, SECONDS_BEFORE_EXPIRATION, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE, RB_SEGMENT_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 } from '../../logger/constants';
|
|
13
13
|
import { UpdateStrategy } from './SSEHandler/types';
|
|
14
|
-
import { getDelay, isInBitmap, parseBitmap,
|
|
14
|
+
import { getDelay, isInBitmap, parseBitmap, 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
|
|
46
|
+
var splitsUpdateWorker = SplitsUpdateWorker(log, storage, 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,21 +179,8 @@ 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
|
-
|
|
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
|
-
});
|
|
182
|
+
pushEmitter.on(SPLIT_UPDATE, splitsUpdateWorker.put);
|
|
183
|
+
pushEmitter.on(RB_SEGMENT_UPDATE, splitsUpdateWorker.put);
|
|
197
184
|
function handleMySegmentsUpdate(parsedData) {
|
|
198
185
|
switch (parsedData.u) {
|
|
199
186
|
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() || storage.rbSegments.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() || storage.rbSegments.usesSegments())
|
|
141
141
|
mySegmentsSyncTask.start();
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -86,7 +86,11 @@ 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.3';
|
|
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';
|
|
94
|
+
export var STANDARD_SEGMENT = 'standard';
|
|
95
|
+
export var LARGE_SEGMENT = 'large';
|
|
96
|
+
export var RULE_BASED_SEGMENT = 'rule-based';
|
package/package.json
CHANGED
package/src/dtos/types.ts
CHANGED
|
@@ -66,6 +66,11 @@ 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
|
+
|
|
69
74
|
interface IInLargeSegmentMatcher extends ISplitMatcherBase {
|
|
70
75
|
matcherType: 'IN_LARGE_SEGMENT',
|
|
71
76
|
userDefinedLargeSegmentMatcherData: IInLargeSegmentMatcherData
|
|
@@ -176,7 +181,7 @@ export type ISplitMatcher = IAllKeysMatcher | IInSegmentMatcher | IWhitelistMatc
|
|
|
176
181
|
ILessThanOrEqualToMatcher | IBetweenMatcher | IEqualToSetMatcher | IContainsAnyOfSetMatcher | IContainsAllOfSetMatcher | IPartOfSetMatcher |
|
|
177
182
|
IStartsWithMatcher | IEndsWithMatcher | IContainsStringMatcher | IInSplitTreatmentMatcher | IEqualToBooleanMatcher | IMatchesStringMatcher |
|
|
178
183
|
IEqualToSemverMatcher | IGreaterThanOrEqualToSemverMatcher | ILessThanOrEqualToSemverMatcher | IBetweenSemverMatcher | IInListSemverMatcher |
|
|
179
|
-
IInLargeSegmentMatcher
|
|
184
|
+
IInLargeSegmentMatcher | IInRBSegmentMatcher
|
|
180
185
|
|
|
181
186
|
/** Split object */
|
|
182
187
|
export interface ISplitPartition {
|
|
@@ -189,19 +194,39 @@ export interface ISplitCondition {
|
|
|
189
194
|
combiner: 'AND',
|
|
190
195
|
matchers: ISplitMatcher[]
|
|
191
196
|
}
|
|
192
|
-
partitions
|
|
193
|
-
label
|
|
194
|
-
conditionType
|
|
197
|
+
partitions?: ISplitPartition[]
|
|
198
|
+
label?: string
|
|
199
|
+
conditionType?: 'ROLLOUT' | 'WHITELIST'
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface IExcludedSegment {
|
|
203
|
+
type: 'standard' | 'large' | 'rule-based',
|
|
204
|
+
name: string,
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface IRBSegment {
|
|
208
|
+
name: string,
|
|
209
|
+
changeNumber: number,
|
|
210
|
+
status: 'ACTIVE' | 'ARCHIVED',
|
|
211
|
+
conditions?: ISplitCondition[],
|
|
212
|
+
excluded?: {
|
|
213
|
+
keys?: string[] | null,
|
|
214
|
+
segments?: IExcludedSegment[] | null
|
|
215
|
+
}
|
|
195
216
|
}
|
|
196
217
|
|
|
197
218
|
export interface ISplit {
|
|
198
219
|
name: string,
|
|
199
220
|
changeNumber: number,
|
|
221
|
+
status: 'ACTIVE' | 'ARCHIVED',
|
|
222
|
+
conditions: ISplitCondition[],
|
|
223
|
+
prerequisites?: {
|
|
224
|
+
n: string,
|
|
225
|
+
ts: string[]
|
|
226
|
+
}[]
|
|
200
227
|
killed: boolean,
|
|
201
228
|
defaultTreatment: string,
|
|
202
229
|
trafficTypeName: string,
|
|
203
|
-
conditions: ISplitCondition[],
|
|
204
|
-
status: 'ACTIVE' | 'ARCHIVED',
|
|
205
230
|
seed: number,
|
|
206
231
|
trafficAllocation?: number,
|
|
207
232
|
trafficAllocationSeed?: number
|
|
@@ -217,8 +242,16 @@ export type ISplitPartial = Pick<ISplit, 'conditions' | 'configurations' | 'traf
|
|
|
217
242
|
|
|
218
243
|
/** Interface of the parsed JSON response of `/splitChanges` */
|
|
219
244
|
export interface ISplitChangesResponse {
|
|
220
|
-
|
|
221
|
-
|
|
245
|
+
ff?: {
|
|
246
|
+
t: number,
|
|
247
|
+
s?: number,
|
|
248
|
+
d: ISplit[]
|
|
249
|
+
},
|
|
250
|
+
rbs?: {
|
|
251
|
+
t: number,
|
|
252
|
+
s?: number,
|
|
253
|
+
d: IRBSegment[]
|
|
254
|
+
}
|
|
222
255
|
}
|
|
223
256
|
|
|
224
257
|
/** Interface of the parsed JSON response of `/segmentChanges/{segmentName}` */
|
package/src/evaluator/Engine.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { get } from '../utils/lang';
|
|
1
|
+
import { get, isString } 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 {
|
|
5
|
+
import { NO_CONDITION_MATCH, SPLIT_ARCHIVED, SPLIT_KILLED, PREREQUISITES_NOT_MET } 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,
|
|
10
|
+
import { IEvaluation, IEvaluationResult, ISplitEvaluator } from './types';
|
|
11
11
|
import { ILogger } from '../logger/types';
|
|
12
|
+
import { ENGINE_DEFAULT } from '../logger/constants';
|
|
13
|
+
import { prerequisitesMatcherContext } from './matchers/prerequisites';
|
|
12
14
|
|
|
13
15
|
function evaluationResult(result: IEvaluation | undefined, defaultTreatment: string): IEvaluationResult {
|
|
14
16
|
return {
|
|
@@ -17,84 +19,55 @@ function evaluationResult(result: IEvaluation | undefined, defaultTreatment: str
|
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
export
|
|
22
|
+
export function engineParser(log: ILogger, split: ISplit, storage: IStorageSync | IStorageAsync) {
|
|
23
|
+
const { killed, seed, trafficAllocation, trafficAllocationSeed, status, conditions, prerequisites } = split;
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
const defaultTreatment = isString(split.defaultTreatment) ? split.defaultTreatment : CONTROL;
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
27
|
+
const evaluator = parser(log, conditions, storage);
|
|
28
|
+
const prerequisiteMatcher = prerequisitesMatcherContext(prerequisites, storage, log);
|
|
29
|
+
|
|
30
|
+
return {
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
const conditions = splitFlatStructure.conditions;
|
|
32
|
-
const evaluator = parser(log, conditions, storage);
|
|
32
|
+
getTreatment(key: SplitIO.SplitKey, attributes: SplitIO.Attributes | undefined, splitEvaluator: ISplitEvaluator): MaybeThenable<IEvaluationResult> {
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
}
|
|
34
|
+
const parsedKey = keyParser(key);
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
function evaluate(prerequisitesMet: boolean) {
|
|
37
|
+
if (!prerequisitesMet) {
|
|
38
|
+
log.debug(ENGINE_DEFAULT, ['Prerequisite not met']);
|
|
39
|
+
return {
|
|
40
|
+
treatment: defaultTreatment,
|
|
41
|
+
label: PREREQUISITES_NOT_MET
|
|
42
|
+
};
|
|
43
|
+
}
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
trafficAllocationSeed
|
|
48
|
-
} = this.baseInfo;
|
|
49
|
-
let parsedKey;
|
|
50
|
-
let treatment;
|
|
51
|
-
let label;
|
|
45
|
+
const evaluation = evaluator(parsedKey, seed, trafficAllocation, trafficAllocationSeed, attributes, splitEvaluator) as MaybeThenable<IEvaluation>;
|
|
46
|
+
|
|
47
|
+
return thenable(evaluation) ?
|
|
48
|
+
evaluation.then(result => evaluationResult(result, defaultTreatment)) :
|
|
49
|
+
evaluationResult(evaluation, defaultTreatment);
|
|
50
|
+
}
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
parsedKey = keyParser(key);
|
|
55
|
-
} catch (err) {
|
|
56
|
-
return {
|
|
52
|
+
if (status === 'ARCHIVED') return {
|
|
57
53
|
treatment: CONTROL,
|
|
58
|
-
label:
|
|
54
|
+
label: SPLIT_ARCHIVED
|
|
59
55
|
};
|
|
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
|
-
);
|
|
77
56
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
57
|
+
if (killed) {
|
|
58
|
+
log.debug(ENGINE_DEFAULT, ['Flag is killed']);
|
|
59
|
+
return {
|
|
60
|
+
treatment: defaultTreatment,
|
|
61
|
+
label: SPLIT_KILLED
|
|
62
|
+
};
|
|
84
63
|
}
|
|
85
|
-
}
|
|
86
64
|
|
|
87
|
-
|
|
88
|
-
treatment,
|
|
89
|
-
label
|
|
90
|
-
};
|
|
91
|
-
}
|
|
65
|
+
const prerequisitesMet = prerequisiteMatcher({ key, attributes }, splitEvaluator);
|
|
92
66
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
67
|
+
return thenable(prerequisitesMet) ?
|
|
68
|
+
prerequisitesMet.then(evaluate) :
|
|
69
|
+
evaluate(prerequisitesMet);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
96
72
|
|
|
97
|
-
getChangeNumber() {
|
|
98
|
-
return this.baseInfo.changeNumber;
|
|
99
|
-
}
|
|
100
73
|
}
|
|
@@ -2,10 +2,11 @@ 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 { ISplitEvaluator } from '../types';
|
|
6
6
|
import { ENGINE_COMBINER_AND } from '../../logger/constants';
|
|
7
|
+
import SplitIO from '../../../types/splitio';
|
|
7
8
|
|
|
8
|
-
export function andCombinerContext(log: ILogger, matchers:
|
|
9
|
+
export function andCombinerContext(log: ILogger, matchers: Array<(key: SplitIO.SplitKey, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) => MaybeThenable<boolean>>) {
|
|
9
10
|
|
|
10
11
|
function andResults(results: boolean[]): boolean {
|
|
11
12
|
// Array.prototype.every is supported by target environments
|
|
@@ -15,8 +16,8 @@ export function andCombinerContext(log: ILogger, matchers: IMatcher[]) {
|
|
|
15
16
|
return hasMatchedAll;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
return function andCombiner(
|
|
19
|
-
const matcherResults = matchers.map(matcher => matcher(
|
|
19
|
+
return function andCombiner(key: SplitIO.SplitKey, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator): MaybeThenable<boolean> {
|
|
20
|
+
const matcherResults = matchers.map(matcher => matcher(key, attributes, splitEvaluator));
|
|
20
21
|
|
|
21
22
|
// If any matching result is a thenable we should use Promise.all
|
|
22
23
|
if (findIndex(matcherResults, thenable) !== -1) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { findIndex } from '../../utils/lang';
|
|
1
|
+
import { findIndex, isBoolean } 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,14 +18,12 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
for (let i = 0; i < len; i++) {
|
|
21
|
+
function computeEvaluation(predicateResults: Array<IEvaluation | boolean | undefined>): IEvaluation | boolean | undefined {
|
|
22
|
+
for (let i = 0, len = predicateResults.length; i < len; i++) {
|
|
25
23
|
const evaluation = predicateResults[i];
|
|
26
24
|
|
|
27
25
|
if (evaluation !== undefined) {
|
|
28
|
-
log.debug(ENGINE_COMBINER_IFELSEIF, [evaluation.treatment]);
|
|
26
|
+
if (!isBoolean(evaluation)) log.debug(ENGINE_COMBINER_IFELSEIF, [evaluation.treatment]);
|
|
29
27
|
|
|
30
28
|
return evaluation;
|
|
31
29
|
}
|
|
@@ -35,7 +33,7 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
35
33
|
return undefined;
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
function ifElseIfCombiner(key: SplitIO.
|
|
36
|
+
function ifElseIfCombiner(key: SplitIO.SplitKeyObject, seed?: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
|
|
39
37
|
// In Async environments we are going to have async predicates. There is none way to know
|
|
40
38
|
// before hand so we need to evaluate all the predicates, verify for thenables, and finally,
|
|
41
39
|
// define how to return the treatment (wrap result into a Promise or not).
|
|
@@ -43,10 +41,10 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
43
41
|
|
|
44
42
|
// if we find a thenable
|
|
45
43
|
if (findIndex(predicateResults, thenable) !== -1) {
|
|
46
|
-
return Promise.all(predicateResults).then(results =>
|
|
44
|
+
return Promise.all(predicateResults).then(results => computeEvaluation(results));
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
return
|
|
47
|
+
return computeEvaluation(predicateResults as IEvaluation[]);
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
// 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, treatments: { getTreatmentFor: (x: number) => string }) {
|
|
8
|
+
export function getTreatment(log: ILogger, key: string, seed: number | undefined, treatments: { getTreatmentFor: (x: number) => string }) {
|
|
9
9
|
const _bucket = bucket(key, seed);
|
|
10
10
|
|
|
11
11
|
const treatment = treatments.getTreatmentFor(_bucket);
|