@splitsoftware/splitio-commons 1.6.2-rc.5 → 1.6.2-rc.8
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 +3 -0
- package/cjs/evaluator/index.js +10 -11
- package/cjs/integrations/ga/GaToSplit.js +8 -5
- package/cjs/sdkClient/sdkClient.js +3 -1
- package/cjs/sdkFactory/index.js +2 -2
- package/cjs/sdkManager/index.js +3 -11
- package/cjs/storages/AbstractSplitsCacheAsync.js +7 -9
- package/cjs/storages/AbstractSplitsCacheSync.js +7 -9
- package/cjs/storages/dataLoader.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +5 -6
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +10 -6
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/cjs/storages/inRedis/index.js +4 -3
- package/cjs/storages/inRedis/uniqueKeysCacheInRedis.js +11 -7
- package/cjs/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/cjs/trackers/strategy/strategyOptimized.js +2 -1
- package/cjs/trackers/telemetryTracker.js +6 -0
- package/cjs/trackers/uniqueKeysTracker.js +8 -1
- package/esm/evaluator/index.js +10 -11
- package/esm/integrations/ga/GaToSplit.js +8 -5
- package/esm/sdkClient/sdkClient.js +3 -1
- package/esm/sdkFactory/index.js +2 -2
- package/esm/sdkManager/index.js +3 -11
- package/esm/storages/AbstractSplitsCacheAsync.js +7 -9
- package/esm/storages/AbstractSplitsCacheSync.js +7 -9
- package/esm/storages/dataLoader.js +1 -1
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -6
- package/esm/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +10 -6
- package/esm/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/esm/storages/inRedis/index.js +4 -3
- package/esm/storages/inRedis/uniqueKeysCacheInRedis.js +11 -7
- package/esm/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/esm/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/esm/trackers/strategy/strategyOptimized.js +2 -1
- package/esm/trackers/telemetryTracker.js +6 -0
- package/esm/trackers/uniqueKeysTracker.js +8 -1
- package/package.json +1 -1
- package/src/evaluator/index.ts +8 -9
- package/src/integrations/ga/GaToSplit.ts +9 -5
- package/src/integrations/types.ts +2 -1
- package/src/sdkClient/sdkClient.ts +3 -1
- package/src/sdkFactory/index.ts +2 -2
- package/src/sdkManager/index.ts +3 -12
- package/src/storages/AbstractSplitsCacheAsync.ts +12 -14
- package/src/storages/AbstractSplitsCacheSync.ts +14 -16
- package/src/storages/dataLoader.ts +1 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +8 -10
- package/src/storages/inMemory/SplitsCacheInMemory.ts +10 -14
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +10 -6
- package/src/storages/inRedis/SplitsCacheInRedis.ts +21 -17
- package/src/storages/inRedis/index.ts +5 -4
- package/src/storages/inRedis/uniqueKeysCacheInRedis.ts +11 -8
- package/src/storages/pluggable/SplitsCachePluggable.ts +20 -17
- package/src/storages/types.ts +13 -13
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
- package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -2
- package/src/trackers/strategy/strategyOptimized.ts +1 -1
- package/src/trackers/telemetryTracker.ts +7 -2
- package/src/trackers/types.ts +6 -0
- package/src/trackers/uniqueKeysTracker.ts +13 -2
- package/types/integrations/types.d.ts +2 -1
- package/types/storages/AbstractSplitsCacheAsync.d.ts +6 -5
- package/types/storages/AbstractSplitsCacheSync.d.ts +5 -5
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +3 -3
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +3 -2
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +5 -4
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +6 -5
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +5 -4
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +6 -5
- package/types/storages/types.d.ts +13 -13
- package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
- package/types/trackers/types.d.ts +6 -0
- package/types/trackers/uniqueKeysTracker.d.ts +1 -1
|
@@ -13,11 +13,15 @@ var noopFilterAdapter = {
|
|
|
13
13
|
* or schedule to be sent; if not it will be added in an internal cache and sent in the next post.
|
|
14
14
|
*
|
|
15
15
|
* @param log Logger instance
|
|
16
|
-
* @param filterAdapter filter adapter
|
|
17
16
|
* @param uniqueKeysCache cache to save unique keys
|
|
17
|
+
* @param filterAdapter filter adapter
|
|
18
18
|
*/
|
|
19
19
|
function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
|
|
20
20
|
if (filterAdapter === void 0) { filterAdapter = noopFilterAdapter; }
|
|
21
|
+
var intervalId;
|
|
22
|
+
if (filterAdapter.refreshRate) {
|
|
23
|
+
intervalId = setInterval(filterAdapter.clear, filterAdapter.refreshRate);
|
|
24
|
+
}
|
|
21
25
|
return {
|
|
22
26
|
track: function (key, featureName) {
|
|
23
27
|
if (!filterAdapter.add(key, featureName)) {
|
|
@@ -25,6 +29,9 @@ function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
|
|
|
25
29
|
return;
|
|
26
30
|
}
|
|
27
31
|
uniqueKeysCache.track(key, featureName);
|
|
32
|
+
},
|
|
33
|
+
stop: function () {
|
|
34
|
+
clearInterval(intervalId);
|
|
28
35
|
}
|
|
29
36
|
};
|
|
30
37
|
}
|
package/esm/evaluator/index.js
CHANGED
|
@@ -32,44 +32,43 @@ export function evaluateFeature(log, key, splitName, attributes, storage) {
|
|
|
32
32
|
return getEvaluation(log, stringifiedSplit, key, attributes, storage);
|
|
33
33
|
}
|
|
34
34
|
export function evaluateFeatures(log, key, splitNames, attributes, storage) {
|
|
35
|
-
var
|
|
35
|
+
var parsedSplits;
|
|
36
36
|
try {
|
|
37
|
-
|
|
37
|
+
parsedSplits = storage.splits.getSplits(splitNames);
|
|
38
38
|
}
|
|
39
39
|
catch (e) {
|
|
40
40
|
// Exception on sync `getSplits` storage. Not possible ATM with InMemory and InLocal storages.
|
|
41
41
|
return treatmentsException(splitNames);
|
|
42
42
|
}
|
|
43
|
-
return
|
|
44
|
-
|
|
43
|
+
return thenable(parsedSplits) ?
|
|
44
|
+
parsedSplits.then(function (splits) { return getEvaluations(log, splitNames, splits, key, attributes, storage); })
|
|
45
45
|
.catch(function () {
|
|
46
46
|
// Exception on async `getSplits` storage. For example, when the storage is redis or
|
|
47
47
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
48
48
|
return treatmentsException(splitNames);
|
|
49
49
|
}) :
|
|
50
|
-
getEvaluations(log, splitNames,
|
|
50
|
+
getEvaluations(log, splitNames, parsedSplits, key, attributes, storage);
|
|
51
51
|
}
|
|
52
|
-
function getEvaluation(log,
|
|
52
|
+
function getEvaluation(log, splitJSON, key, attributes, storage) {
|
|
53
53
|
var evaluation = {
|
|
54
54
|
treatment: CONTROL,
|
|
55
55
|
label: LabelsConstants.SPLIT_NOT_FOUND,
|
|
56
56
|
config: null
|
|
57
57
|
};
|
|
58
|
-
if (
|
|
59
|
-
var
|
|
60
|
-
var split_1 = Engine.parse(log, splitJSON_1, storage);
|
|
58
|
+
if (splitJSON) {
|
|
59
|
+
var split_1 = Engine.parse(log, splitJSON, storage);
|
|
61
60
|
evaluation = split_1.getTreatment(key, attributes, evaluateFeature);
|
|
62
61
|
// If the storage is async and the evaluated split uses segment, evaluation is thenable
|
|
63
62
|
if (thenable(evaluation)) {
|
|
64
63
|
return evaluation.then(function (result) {
|
|
65
64
|
result.changeNumber = split_1.getChangeNumber();
|
|
66
|
-
result.config =
|
|
65
|
+
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
|
|
67
66
|
return result;
|
|
68
67
|
});
|
|
69
68
|
}
|
|
70
69
|
else {
|
|
71
70
|
evaluation.changeNumber = split_1.getChangeNumber(); // Always sync and optional
|
|
72
|
-
evaluation.config =
|
|
71
|
+
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
return evaluation;
|
|
@@ -13,7 +13,7 @@ var logNameMapper = 'ga-to-split:mapper';
|
|
|
13
13
|
* @param log Logger instance.
|
|
14
14
|
* @param autoRequire If true, log error when auto-require script is not detected
|
|
15
15
|
*/
|
|
16
|
-
function providePlugin(window, pluginName, pluginConstructor, log, autoRequire) {
|
|
16
|
+
function providePlugin(window, pluginName, pluginConstructor, log, autoRequire, telemetryTracker) {
|
|
17
17
|
// get reference to global command queue. Init it if not defined yet.
|
|
18
18
|
var gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
19
19
|
window[gaAlias] = window[gaAlias] || function () {
|
|
@@ -21,10 +21,13 @@ function providePlugin(window, pluginName, pluginConstructor, log, autoRequire)
|
|
|
21
21
|
};
|
|
22
22
|
// provides the plugin for use with analytics.js.
|
|
23
23
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
var hasAutoRequire = window[gaAlias].q && window[gaAlias].q.push !== [].push;
|
|
25
|
+
if (autoRequire && !hasAutoRequire) { // Expecting spy on ga.q push method but not found
|
|
26
26
|
log.error(logPrefix + 'integration is configured to autorequire the splitTracker plugin, but the necessary script does not seem to have run. Please check the docs.');
|
|
27
27
|
}
|
|
28
|
+
if (telemetryTracker && hasAutoRequire) {
|
|
29
|
+
telemetryTracker.addTag('integration:ga-autorequire');
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
32
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
30
33
|
var defaultMapping = {
|
|
@@ -157,7 +160,7 @@ export function fixEventTypeId(log, eventTypeId) {
|
|
|
157
160
|
* @param {object} log factory logger
|
|
158
161
|
*/
|
|
159
162
|
export function GaToSplit(sdkOptions, params) {
|
|
160
|
-
var storage = params.storage, _a = params.settings, coreSettings = _a.core, log = _a.log;
|
|
163
|
+
var storage = params.storage, _a = params.settings, coreSettings = _a.core, log = _a.log, telemetryTracker = params.telemetryTracker;
|
|
161
164
|
var defaultOptions = {
|
|
162
165
|
prefix: defaultPrefix,
|
|
163
166
|
// We set default identities if key and TT are present in settings.core
|
|
@@ -243,5 +246,5 @@ export function GaToSplit(sdkOptions, params) {
|
|
|
243
246
|
return SplitTracker;
|
|
244
247
|
}());
|
|
245
248
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
246
|
-
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true);
|
|
249
|
+
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true, telemetryTracker);
|
|
247
250
|
}
|
|
@@ -6,7 +6,7 @@ import { clientInputValidationDecorator } from './clientInputValidation';
|
|
|
6
6
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
7
7
|
*/
|
|
8
8
|
export function sdkClientFactory(params, isSharedClient) {
|
|
9
|
-
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker;
|
|
9
|
+
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker, uniqueKeysTracker = params.uniqueKeysTracker;
|
|
10
10
|
return objectAssign(
|
|
11
11
|
// Proto-linkage of the readiness Event Emitter
|
|
12
12
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
@@ -28,6 +28,8 @@ export function sdkClientFactory(params, isSharedClient) {
|
|
|
28
28
|
// Release the API Key if it is the main client
|
|
29
29
|
if (!isSharedClient)
|
|
30
30
|
releaseApiKey(settings.core.authorizationKey);
|
|
31
|
+
if (uniqueKeysTracker)
|
|
32
|
+
uniqueKeysTracker.stop();
|
|
31
33
|
// Cleanup storage
|
|
32
34
|
return storage.destroy();
|
|
33
35
|
});
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -52,7 +52,8 @@ export function sdkFactory(params) {
|
|
|
52
52
|
};
|
|
53
53
|
var storage = storageFactory(storageFactoryParams);
|
|
54
54
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
55
|
-
var
|
|
55
|
+
var telemetryTracker = telemetryTrackerFactory(storage.telemetry, platform.now);
|
|
56
|
+
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
56
57
|
var observer = impressionsObserverFactory();
|
|
57
58
|
var uniqueKeysTracker = storageFactoryParams.impressionsMode === NONE ? uniqueKeysTrackerFactory(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
58
59
|
var strategy;
|
|
@@ -68,7 +69,6 @@ export function sdkFactory(params) {
|
|
|
68
69
|
}
|
|
69
70
|
var impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
|
|
70
71
|
var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
|
|
71
|
-
var telemetryTracker = telemetryTrackerFactory(storage.telemetry, platform.now);
|
|
72
72
|
// splitApi is used by SyncManager and Browser signal listener
|
|
73
73
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
74
74
|
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
package/esm/sdkManager/index.js
CHANGED
|
@@ -12,15 +12,7 @@ function collectTreatments(splitObject) {
|
|
|
12
12
|
// Then extract the treatments from the partitions
|
|
13
13
|
return allTreatmentsCondition ? allTreatmentsCondition.partitions.map(function (v) { return v.treatment; }) : [];
|
|
14
14
|
}
|
|
15
|
-
function objectToView(
|
|
16
|
-
var splitObject;
|
|
17
|
-
try {
|
|
18
|
-
// @ts-expect-error
|
|
19
|
-
splitObject = JSON.parse(json);
|
|
20
|
-
}
|
|
21
|
-
catch (e) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
15
|
+
function objectToView(splitObject) {
|
|
24
16
|
if (!splitObject)
|
|
25
17
|
return null;
|
|
26
18
|
return {
|
|
@@ -32,9 +24,9 @@ function objectToView(json) {
|
|
|
32
24
|
configs: splitObject.configurations || {}
|
|
33
25
|
};
|
|
34
26
|
}
|
|
35
|
-
function objectsToViews(
|
|
27
|
+
function objectsToViews(splitObjects) {
|
|
36
28
|
var views = [];
|
|
37
|
-
|
|
29
|
+
splitObjects.forEach(function (split) {
|
|
38
30
|
var view = objectToView(split);
|
|
39
31
|
if (view)
|
|
40
32
|
views.push(view);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { objectAssign } from '../utils/lang/objectAssign';
|
|
1
2
|
/**
|
|
2
3
|
* This class provides a skeletal implementation of the ISplitsCacheAsync interface
|
|
3
4
|
* to minimize the effort required to implement this interface.
|
|
@@ -31,15 +32,12 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
|
31
32
|
AbstractSplitsCacheAsync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
32
33
|
var _this = this;
|
|
33
34
|
return this.getSplit(name).then(function (split) {
|
|
34
|
-
if (split) {
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var newSplit = JSON.stringify(parsedSplit);
|
|
41
|
-
return _this.addSplit(name, newSplit);
|
|
42
|
-
}
|
|
35
|
+
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
36
|
+
var newSplit = objectAssign({}, split);
|
|
37
|
+
newSplit.killed = true;
|
|
38
|
+
newSplit.defaultTreatment = defaultTreatment;
|
|
39
|
+
newSplit.changeNumber = changeNumber;
|
|
40
|
+
return _this.addSplit(name, newSplit);
|
|
43
41
|
}
|
|
44
42
|
return false;
|
|
45
43
|
}).catch(function () { return false; });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { objectAssign } from '../utils/lang/objectAssign';
|
|
1
2
|
/**
|
|
2
3
|
* This class provides a skeletal implementation of the ISplitsCacheSync interface
|
|
3
4
|
* to minimize the effort required to implement this interface.
|
|
@@ -44,15 +45,12 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
44
45
|
*/
|
|
45
46
|
AbstractSplitsCacheSync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
46
47
|
var split = this.getSplit(name);
|
|
47
|
-
if (split) {
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var newSplit = JSON.stringify(parsedSplit);
|
|
54
|
-
return this.addSplit(name, newSplit);
|
|
55
|
-
}
|
|
48
|
+
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
49
|
+
var newSplit = objectAssign({}, split);
|
|
50
|
+
newSplit.killed = true;
|
|
51
|
+
newSplit.defaultTreatment = defaultTreatment;
|
|
52
|
+
newSplit.changeNumber = changeNumber;
|
|
53
|
+
return this.addSplit(name, newSplit);
|
|
56
54
|
}
|
|
57
55
|
return false;
|
|
58
56
|
};
|
|
@@ -32,7 +32,7 @@ export function dataLoaderFactory(preloadedData) {
|
|
|
32
32
|
storage.splits.clear();
|
|
33
33
|
storage.splits.setChangeNumber(since);
|
|
34
34
|
// splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
|
|
35
|
-
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return
|
|
35
|
+
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }));
|
|
36
36
|
// add mySegments data
|
|
37
37
|
var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userId];
|
|
38
38
|
if (!mySegmentsData) {
|
|
@@ -93,9 +93,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
93
93
|
var splitFromLocalStorage = localStorage.getItem(splitKey);
|
|
94
94
|
var previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
|
|
95
95
|
this._decrementCounts(previousSplit);
|
|
96
|
-
localStorage.setItem(splitKey, split);
|
|
97
|
-
|
|
98
|
-
this._incrementCounts(parsedSplit);
|
|
96
|
+
localStorage.setItem(splitKey, JSON.stringify(split));
|
|
97
|
+
this._incrementCounts(split);
|
|
99
98
|
return true;
|
|
100
99
|
}
|
|
101
100
|
catch (e) {
|
|
@@ -107,8 +106,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
107
106
|
try {
|
|
108
107
|
var split = this.getSplit(name);
|
|
109
108
|
localStorage.removeItem(this.keys.buildSplitKey(name));
|
|
110
|
-
|
|
111
|
-
this._decrementCounts(parsedSplit);
|
|
109
|
+
this._decrementCounts(split);
|
|
112
110
|
return true;
|
|
113
111
|
}
|
|
114
112
|
catch (e) {
|
|
@@ -117,7 +115,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
117
115
|
}
|
|
118
116
|
};
|
|
119
117
|
SplitsCacheInLocal.prototype.getSplit = function (name) {
|
|
120
|
-
|
|
118
|
+
var item = localStorage.getItem(this.keys.buildSplitKey(name));
|
|
119
|
+
return item && JSON.parse(item);
|
|
121
120
|
};
|
|
122
121
|
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
123
122
|
// when cache is ready but using a new split query, we must clear all split data
|
|
@@ -22,9 +22,8 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
22
22
|
this.splitsWithSegmentsCount = 0;
|
|
23
23
|
};
|
|
24
24
|
SplitsCacheInMemory.prototype.addSplit = function (name, split) {
|
|
25
|
-
var
|
|
26
|
-
if (
|
|
27
|
-
var previousSplit = JSON.parse(splitFromMemory);
|
|
25
|
+
var previousSplit = this.getSplit(name);
|
|
26
|
+
if (previousSplit) { // We had this Split already
|
|
28
27
|
if (previousSplit.trafficTypeName) {
|
|
29
28
|
var previousTtName = previousSplit.trafficTypeName;
|
|
30
29
|
this.ttCache[previousTtName]--;
|
|
@@ -35,19 +34,18 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
35
34
|
this.splitsWithSegmentsCount--;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
if (parsedSplit) {
|
|
37
|
+
if (split) {
|
|
40
38
|
// Store the Split.
|
|
41
39
|
this.splitsCache[name] = split;
|
|
42
40
|
// Update TT cache
|
|
43
|
-
var ttName =
|
|
41
|
+
var ttName = split.trafficTypeName;
|
|
44
42
|
if (ttName) { // safeguard
|
|
45
43
|
if (!this.ttCache[ttName])
|
|
46
44
|
this.ttCache[ttName] = 0;
|
|
47
45
|
this.ttCache[ttName]++;
|
|
48
46
|
}
|
|
49
47
|
// Add to segments count for the new version of the Split
|
|
50
|
-
if (usesSegments(
|
|
48
|
+
if (usesSegments(split))
|
|
51
49
|
this.splitsWithSegmentsCount++;
|
|
52
50
|
return true;
|
|
53
51
|
}
|
|
@@ -60,15 +58,14 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
60
58
|
if (split) {
|
|
61
59
|
// Delete the Split
|
|
62
60
|
delete this.splitsCache[name];
|
|
63
|
-
var
|
|
64
|
-
var ttName = parsedSplit.trafficTypeName;
|
|
61
|
+
var ttName = split.trafficTypeName;
|
|
65
62
|
if (ttName) { // safeguard
|
|
66
63
|
this.ttCache[ttName]--; // Update tt cache
|
|
67
64
|
if (!this.ttCache[ttName])
|
|
68
65
|
delete this.ttCache[ttName];
|
|
69
66
|
}
|
|
70
67
|
// Update the segments count.
|
|
71
|
-
if (usesSegments(
|
|
68
|
+
if (usesSegments(split))
|
|
72
69
|
this.splitsWithSegmentsCount--;
|
|
73
70
|
return true;
|
|
74
71
|
}
|
|
@@ -3,11 +3,13 @@ import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCache
|
|
|
3
3
|
import { LOG_PREFIX, REFRESH_RATE, TTL_REFRESH } from './constants';
|
|
4
4
|
var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
|
|
5
5
|
__extends(ImpressionCountsCacheInRedis, _super);
|
|
6
|
-
function ImpressionCountsCacheInRedis(log, key, redis, impressionCountsCacheSize) {
|
|
6
|
+
function ImpressionCountsCacheInRedis(log, key, redis, impressionCountsCacheSize, refreshRate) {
|
|
7
|
+
if (refreshRate === void 0) { refreshRate = REFRESH_RATE; }
|
|
7
8
|
var _this = _super.call(this, impressionCountsCacheSize) || this;
|
|
8
9
|
_this.log = log;
|
|
9
10
|
_this.key = key;
|
|
10
11
|
_this.redis = redis;
|
|
12
|
+
_this.refreshRate = refreshRate;
|
|
11
13
|
_this.onFullQueue = function () { _this.postImpressionCountsInRedis(); };
|
|
12
14
|
return _this;
|
|
13
15
|
}
|
|
@@ -15,6 +17,8 @@ var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
|
|
|
15
17
|
var _this = this;
|
|
16
18
|
var counts = this.pop();
|
|
17
19
|
var keys = Object.keys(counts);
|
|
20
|
+
if (!keys)
|
|
21
|
+
return Promise.resolve(false);
|
|
18
22
|
var pipeline = this.redis.pipeline();
|
|
19
23
|
keys.forEach(function (key) {
|
|
20
24
|
pipeline.hincrby(_this.key, key, counts[key]);
|
|
@@ -28,15 +32,15 @@ var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
|
|
|
28
32
|
})
|
|
29
33
|
.catch(function (err) {
|
|
30
34
|
_this.log.error(LOG_PREFIX + "Error in impression counts pipeline: " + err + ".");
|
|
31
|
-
return false;
|
|
35
|
+
return Promise.resolve(false);
|
|
32
36
|
});
|
|
33
37
|
};
|
|
34
|
-
ImpressionCountsCacheInRedis.prototype.start = function (
|
|
35
|
-
|
|
36
|
-
this.handle = setInterval(this.postImpressionCountsInRedis.bind(this), refreshRate);
|
|
38
|
+
ImpressionCountsCacheInRedis.prototype.start = function () {
|
|
39
|
+
this.intervalId = setInterval(this.postImpressionCountsInRedis.bind(this), this.refreshRate);
|
|
37
40
|
};
|
|
38
41
|
ImpressionCountsCacheInRedis.prototype.stop = function () {
|
|
39
|
-
clearInterval(this.
|
|
42
|
+
clearInterval(this.intervalId);
|
|
43
|
+
return this.postImpressionCountsInRedis();
|
|
40
44
|
};
|
|
41
45
|
return ImpressionCountsCacheInRedis;
|
|
42
46
|
}(ImpressionCountsCacheInMemory));
|
|
@@ -59,17 +59,17 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
59
59
|
var splitKey = this.keys.buildSplitKey(name);
|
|
60
60
|
return this.redis.get(splitKey).then(function (splitFromStorage) {
|
|
61
61
|
// handling parsing errors
|
|
62
|
-
var parsedPreviousSplit,
|
|
62
|
+
var parsedPreviousSplit, newStringifiedSplit;
|
|
63
63
|
try {
|
|
64
64
|
parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
|
|
65
|
-
|
|
65
|
+
newStringifiedSplit = JSON.stringify(split);
|
|
66
66
|
}
|
|
67
67
|
catch (e) {
|
|
68
68
|
throw new Error('Error parsing split definition: ' + e);
|
|
69
69
|
}
|
|
70
70
|
return Promise.all([
|
|
71
|
-
_this.redis.set(splitKey,
|
|
72
|
-
_this._incrementCounts(
|
|
71
|
+
_this.redis.set(splitKey, newStringifiedSplit),
|
|
72
|
+
_this._incrementCounts(split),
|
|
73
73
|
// If it's an update, we decrement the traffic type of the existing split,
|
|
74
74
|
parsedPreviousSplit && _this._decrementCounts(parsedPreviousSplit)
|
|
75
75
|
]);
|
|
@@ -96,8 +96,7 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
96
96
|
var _this = this;
|
|
97
97
|
return this.getSplit(name).then(function (split) {
|
|
98
98
|
if (split) {
|
|
99
|
-
|
|
100
|
-
_this._decrementCounts(parsedSplit);
|
|
99
|
+
_this._decrementCounts(split);
|
|
101
100
|
}
|
|
102
101
|
return _this.redis.del(_this.keys.buildSplitKey(name));
|
|
103
102
|
});
|
|
@@ -120,7 +119,8 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
120
119
|
this.log.error(LOG_PREFIX + this.redisError);
|
|
121
120
|
return Promise.reject(this.redisError);
|
|
122
121
|
}
|
|
123
|
-
return this.redis.get(this.keys.buildSplitKey(name))
|
|
122
|
+
return this.redis.get(this.keys.buildSplitKey(name))
|
|
123
|
+
.then(function (maybeSplit) { return maybeSplit && JSON.parse(maybeSplit); });
|
|
124
124
|
};
|
|
125
125
|
/**
|
|
126
126
|
* Set till number.
|
|
@@ -155,7 +155,12 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
155
155
|
*/
|
|
156
156
|
SplitsCacheInRedis.prototype.getAll = function () {
|
|
157
157
|
var _this = this;
|
|
158
|
-
return this.redis.keys(this.keys.searchPatternForSplitKeys())
|
|
158
|
+
return this.redis.keys(this.keys.searchPatternForSplitKeys())
|
|
159
|
+
.then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
|
|
160
|
+
.then(processPipelineAnswer)
|
|
161
|
+
.then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
|
|
162
|
+
return JSON.parse(splitDefinition);
|
|
163
|
+
}); });
|
|
159
164
|
};
|
|
160
165
|
/**
|
|
161
166
|
* Get list of split names.
|
|
@@ -215,7 +220,8 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
215
220
|
var keys = names.map(function (name) { return _this.keys.buildSplitKey(name); });
|
|
216
221
|
return (_a = this.redis).mget.apply(_a, keys).then(function (splitDefinitions) {
|
|
217
222
|
names.forEach(function (name, idx) {
|
|
218
|
-
|
|
223
|
+
var split = splitDefinitions[idx];
|
|
224
|
+
splits[name] = split && JSON.parse(split);
|
|
219
225
|
});
|
|
220
226
|
return Promise.resolve(splits);
|
|
221
227
|
})
|
|
@@ -44,11 +44,12 @@ export function InRedisStorage(options) {
|
|
|
44
44
|
// When using REDIS we should:
|
|
45
45
|
// 1- Disconnect from the storage
|
|
46
46
|
destroy: function () {
|
|
47
|
-
|
|
47
|
+
var promises = [];
|
|
48
48
|
if (impressionCountsCache)
|
|
49
|
-
impressionCountsCache.stop();
|
|
49
|
+
promises.push(impressionCountsCache.stop());
|
|
50
50
|
if (uniqueKeysCache)
|
|
51
|
-
uniqueKeysCache.stop();
|
|
51
|
+
promises.push(uniqueKeysCache.stop());
|
|
52
|
+
return Promise.all(promises).then(function () { redisClient.disconnect(); });
|
|
52
53
|
// @TODO check that caches works as expected when redisClient is disconnected
|
|
53
54
|
}
|
|
54
55
|
};
|
|
@@ -5,19 +5,23 @@ import { DEFAULT_CACHE_SIZE, REFRESH_RATE, TTL_REFRESH } from './constants';
|
|
|
5
5
|
import { LOG_PREFIX } from './constants';
|
|
6
6
|
var UniqueKeysCacheInRedis = /** @class */ (function (_super) {
|
|
7
7
|
__extends(UniqueKeysCacheInRedis, _super);
|
|
8
|
-
function UniqueKeysCacheInRedis(log, key, redis, uniqueKeysQueueSize) {
|
|
8
|
+
function UniqueKeysCacheInRedis(log, key, redis, uniqueKeysQueueSize, refreshRate) {
|
|
9
9
|
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = DEFAULT_CACHE_SIZE; }
|
|
10
|
+
if (refreshRate === void 0) { refreshRate = REFRESH_RATE; }
|
|
10
11
|
var _this = _super.call(this, uniqueKeysQueueSize) || this;
|
|
11
12
|
_this.log = log;
|
|
12
13
|
_this.key = key;
|
|
13
14
|
_this.redis = redis;
|
|
15
|
+
_this.refreshRate = refreshRate;
|
|
14
16
|
_this.onFullQueue = function () { _this.postUniqueKeysInRedis(); };
|
|
15
17
|
return _this;
|
|
16
18
|
}
|
|
17
19
|
UniqueKeysCacheInRedis.prototype.postUniqueKeysInRedis = function () {
|
|
18
20
|
var _this = this;
|
|
19
|
-
var pipeline = this.redis.pipeline();
|
|
20
21
|
var featureNames = Object.keys(this.uniqueKeysTracker);
|
|
22
|
+
if (!featureNames)
|
|
23
|
+
return Promise.resolve(false);
|
|
24
|
+
var pipeline = this.redis.pipeline();
|
|
21
25
|
for (var i = 0; i < featureNames.length; i++) {
|
|
22
26
|
var featureName = featureNames[i];
|
|
23
27
|
var featureKeys = setToArray(this.uniqueKeysTracker[featureName]);
|
|
@@ -37,15 +41,15 @@ var UniqueKeysCacheInRedis = /** @class */ (function (_super) {
|
|
|
37
41
|
})
|
|
38
42
|
.catch(function (err) {
|
|
39
43
|
_this.log.error(LOG_PREFIX + "Error in uniqueKeys pipeline: " + err + ".");
|
|
40
|
-
return false;
|
|
44
|
+
return Promise.resolve(false);
|
|
41
45
|
});
|
|
42
46
|
};
|
|
43
|
-
UniqueKeysCacheInRedis.prototype.start = function (
|
|
44
|
-
|
|
45
|
-
this.handle = setInterval(this.postUniqueKeysInRedis.bind(this), refreshRate);
|
|
47
|
+
UniqueKeysCacheInRedis.prototype.start = function () {
|
|
48
|
+
this.intervalId = setInterval(this.postUniqueKeysInRedis.bind(this), this.refreshRate);
|
|
46
49
|
};
|
|
47
50
|
UniqueKeysCacheInRedis.prototype.stop = function () {
|
|
48
|
-
clearInterval(this.
|
|
51
|
+
clearInterval(this.intervalId);
|
|
52
|
+
return this.postUniqueKeysInRedis();
|
|
49
53
|
};
|
|
50
54
|
return UniqueKeysCacheInRedis;
|
|
51
55
|
}(UniqueKeysCacheInMemory));
|
|
@@ -46,17 +46,17 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
46
46
|
var splitKey = this.keys.buildSplitKey(name);
|
|
47
47
|
return this.wrapper.get(splitKey).then(function (splitFromStorage) {
|
|
48
48
|
// handling parsing error
|
|
49
|
-
var parsedPreviousSplit,
|
|
49
|
+
var parsedPreviousSplit, stringifiedNewSplit;
|
|
50
50
|
try {
|
|
51
51
|
parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
|
|
52
|
-
|
|
52
|
+
stringifiedNewSplit = JSON.stringify(split);
|
|
53
53
|
}
|
|
54
54
|
catch (e) {
|
|
55
55
|
throw new Error('Error parsing split definition: ' + e);
|
|
56
56
|
}
|
|
57
57
|
return Promise.all([
|
|
58
|
-
_this.wrapper.set(splitKey,
|
|
59
|
-
_this._incrementCounts(
|
|
58
|
+
_this.wrapper.set(splitKey, stringifiedNewSplit),
|
|
59
|
+
_this._incrementCounts(split),
|
|
60
60
|
// If it's an update, we decrement the traffic type and segment count of the existing split,
|
|
61
61
|
parsedPreviousSplit && _this._decrementCounts(parsedPreviousSplit)
|
|
62
62
|
]);
|
|
@@ -80,8 +80,7 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
80
80
|
var _this = this;
|
|
81
81
|
return this.getSplit(name).then(function (split) {
|
|
82
82
|
if (split) {
|
|
83
|
-
|
|
84
|
-
_this._decrementCounts(parsedSplit);
|
|
83
|
+
_this._decrementCounts(split);
|
|
85
84
|
}
|
|
86
85
|
return _this.wrapper.del(_this.keys.buildSplitKey(name));
|
|
87
86
|
});
|
|
@@ -101,7 +100,8 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
101
100
|
* or rejected if wrapper operation fails.
|
|
102
101
|
*/
|
|
103
102
|
SplitsCachePluggable.prototype.getSplit = function (name) {
|
|
104
|
-
return this.wrapper.get(this.keys.buildSplitKey(name))
|
|
103
|
+
return this.wrapper.get(this.keys.buildSplitKey(name))
|
|
104
|
+
.then(function (maybeSplit) { return maybeSplit && JSON.parse(maybeSplit); });
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
107
107
|
* Get list of splits.
|
|
@@ -114,7 +114,8 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
114
114
|
return this.wrapper.getMany(keys).then(function (splitDefinitions) {
|
|
115
115
|
var splits = {};
|
|
116
116
|
names.forEach(function (name, idx) {
|
|
117
|
-
|
|
117
|
+
var split = splitDefinitions[idx];
|
|
118
|
+
splits[name] = split && JSON.parse(split);
|
|
118
119
|
});
|
|
119
120
|
return Promise.resolve(splits);
|
|
120
121
|
});
|
|
@@ -126,7 +127,11 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
126
127
|
*/
|
|
127
128
|
SplitsCachePluggable.prototype.getAll = function () {
|
|
128
129
|
var _this = this;
|
|
129
|
-
return this.wrapper.getKeysByPrefix(this.keys.buildSplitKeyPrefix())
|
|
130
|
+
return this.wrapper.getKeysByPrefix(this.keys.buildSplitKeyPrefix())
|
|
131
|
+
.then(function (listOfKeys) { return _this.wrapper.getMany(listOfKeys); })
|
|
132
|
+
.then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
|
|
133
|
+
return JSON.parse(splitDefinition);
|
|
134
|
+
}); });
|
|
130
135
|
};
|
|
131
136
|
/**
|
|
132
137
|
* Get list of split names.
|
|
@@ -24,8 +24,7 @@ export function fromObjectUpdaterFactory(splitsParser, storage, readiness, setti
|
|
|
24
24
|
log.debug(SYNC_OFFLINE_DATA, [JSON.stringify(splitsMock)]);
|
|
25
25
|
forOwn(splitsMock, function (val, name) {
|
|
26
26
|
splits.push([
|
|
27
|
-
name,
|
|
28
|
-
JSON.stringify({
|
|
27
|
+
name, {
|
|
29
28
|
name: name,
|
|
30
29
|
status: 'ACTIVE',
|
|
31
30
|
killed: false,
|
|
@@ -34,7 +33,7 @@ export function fromObjectUpdaterFactory(splitsParser, storage, readiness, setti
|
|
|
34
33
|
conditions: val.conditions || [],
|
|
35
34
|
configurations: val.configurations,
|
|
36
35
|
trafficTypeName: val.trafficTypeName
|
|
37
|
-
}
|
|
36
|
+
}
|
|
38
37
|
]);
|
|
39
38
|
});
|
|
40
39
|
return Promise.all([
|
|
@@ -37,7 +37,7 @@ export function computeSplitsMutation(entries) {
|
|
|
37
37
|
var segments = new _Set();
|
|
38
38
|
var computed = entries.reduce(function (accum, split) {
|
|
39
39
|
if (split.status === 'ACTIVE') {
|
|
40
|
-
accum.added.push([split.name,
|
|
40
|
+
accum.added.push([split.name, split]);
|
|
41
41
|
parseSegments(split).forEach(function (segmentName) {
|
|
42
42
|
segments.add(segmentName);
|
|
43
43
|
});
|
|
@@ -14,7 +14,8 @@ export function strategyOptimizedFactory(impressionsObserver, impressionsCounter
|
|
|
14
14
|
impression.pt = impressionsObserver.testAndSet(impression);
|
|
15
15
|
var now = Date.now();
|
|
16
16
|
// Increments impression counter per featureName
|
|
17
|
-
|
|
17
|
+
if (impression.pt)
|
|
18
|
+
impressionsCounter.track(impression.feature, now, 1);
|
|
18
19
|
// Checks if the impression should be added in queue to be sent
|
|
19
20
|
if (!impression.pt || impression.pt < truncateTimeFrame(now)) {
|
|
20
21
|
impressionsToStore.push(impression);
|
|
@@ -46,6 +46,11 @@ export function telemetryTrackerFactory(telemetryCache, now) {
|
|
|
46
46
|
if (e === TOKEN_REFRESH)
|
|
47
47
|
telemetryCache.recordTokenRefreshes();
|
|
48
48
|
}
|
|
49
|
+
},
|
|
50
|
+
addTag: function (tag) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
if (telemetryCache.addTag)
|
|
53
|
+
telemetryCache.addTag(tag);
|
|
49
54
|
}
|
|
50
55
|
};
|
|
51
56
|
}
|
|
@@ -56,6 +61,7 @@ export function telemetryTrackerFactory(telemetryCache, now) {
|
|
|
56
61
|
trackHttp: noopTrack,
|
|
57
62
|
sessionLength: function () { },
|
|
58
63
|
streamingEvent: function () { },
|
|
64
|
+
addTag: function () { }
|
|
59
65
|
};
|
|
60
66
|
}
|
|
61
67
|
}
|