@splitsoftware/splitio-commons 1.6.2-rc.1 → 1.6.2-rc.10
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/cjs/consent/sdkUserConsent.js +2 -2
- package/cjs/evaluator/index.js +15 -16
- package/cjs/integrations/ga/GaToSplit.js +8 -5
- package/cjs/sdkClient/client.js +19 -7
- package/cjs/sdkClient/sdkClient.js +3 -1
- package/cjs/sdkFactory/index.js +15 -6
- package/cjs/sdkManager/index.js +3 -11
- package/cjs/services/splitApi.js +6 -6
- package/cjs/storages/AbstractSplitsCacheAsync.js +8 -10
- package/cjs/storages/AbstractSplitsCacheSync.js +8 -10
- package/cjs/storages/KeyBuilderSS.js +54 -9
- package/cjs/storages/dataLoader.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +5 -7
- package/cjs/storages/inLocalStorage/index.js +5 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +6 -2
- package/cjs/storages/inMemory/InMemoryStorageCS.js +6 -2
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +10 -5
- package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +73 -0
- package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +78 -0
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +50 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +59 -0
- package/cjs/storages/inRedis/constants.js +4 -1
- package/cjs/storages/inRedis/index.js +17 -2
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +43 -0
- package/cjs/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +50 -0
- package/cjs/storages/pluggable/index.js +42 -17
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/cjs/sync/submitters/telemetrySubmitter.js +8 -4
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +16 -59
- package/cjs/trackers/impressionsTracker.js +17 -15
- package/cjs/trackers/strategy/strategyNone.js +1 -1
- package/cjs/trackers/strategy/strategyOptimized.js +2 -1
- package/cjs/trackers/telemetryTracker.js +6 -0
- package/cjs/trackers/uniqueKeysTracker.js +11 -42
- package/cjs/utils/constants/index.js +3 -2
- package/cjs/utils/lang/maps.js +15 -7
- package/cjs/utils/redis/RedisMock.js +31 -0
- package/cjs/utils/settingsValidation/index.js +0 -3
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/evaluator/index.js +15 -16
- package/esm/integrations/ga/GaToSplit.js +8 -5
- package/esm/sdkClient/client.js +19 -7
- package/esm/sdkClient/sdkClient.js +3 -1
- package/esm/sdkFactory/index.js +16 -7
- package/esm/sdkManager/index.js +3 -11
- package/esm/services/splitApi.js +6 -6
- package/esm/storages/AbstractSplitsCacheAsync.js +8 -10
- package/esm/storages/AbstractSplitsCacheSync.js +8 -10
- package/esm/storages/KeyBuilderSS.js +50 -8
- package/esm/storages/dataLoader.js +1 -1
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -7
- package/esm/storages/inLocalStorage/index.js +6 -2
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/esm/storages/inMemory/InMemoryStorage.js +8 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +7 -3
- package/esm/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +9 -5
- package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +70 -0
- package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +75 -0
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +47 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +56 -0
- package/esm/storages/inRedis/constants.js +3 -0
- package/esm/storages/inRedis/index.js +18 -3
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +40 -0
- package/esm/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/esm/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +47 -0
- package/esm/storages/pluggable/index.js +43 -18
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/esm/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/esm/sync/submitters/telemetrySubmitter.js +9 -5
- package/esm/sync/submitters/uniqueKeysSubmitter.js +15 -56
- package/esm/trackers/impressionsTracker.js +17 -15
- package/esm/trackers/strategy/strategyNone.js +1 -1
- package/esm/trackers/strategy/strategyOptimized.js +2 -1
- package/esm/trackers/telemetryTracker.js +6 -0
- package/esm/trackers/uniqueKeysTracker.js +11 -42
- package/esm/utils/constants/index.js +1 -0
- package/esm/utils/lang/maps.js +15 -7
- package/esm/utils/redis/RedisMock.js +28 -0
- package/esm/utils/settingsValidation/index.js +0 -3
- package/package.json +1 -2
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/evaluator/index.ts +14 -15
- package/src/integrations/ga/GaToSplit.ts +9 -5
- package/src/integrations/types.ts +2 -1
- package/src/logger/.DS_Store +0 -0
- package/src/sdkClient/client.ts +21 -8
- package/src/sdkClient/sdkClient.ts +3 -1
- package/src/sdkFactory/index.ts +17 -7
- package/src/sdkManager/index.ts +3 -12
- package/src/services/splitApi.ts +6 -6
- package/src/services/types.ts +2 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +13 -15
- package/src/storages/AbstractSplitsCacheSync.ts +15 -17
- package/src/storages/KeyBuilderSS.ts +61 -9
- package/src/storages/dataLoader.ts +1 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +8 -11
- package/src/storages/inLocalStorage/index.ts +5 -2
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +16 -1
- package/src/storages/inMemory/InMemoryStorage.ts +7 -4
- package/src/storages/inMemory/InMemoryStorageCS.ts +6 -3
- package/src/storages/inMemory/SplitsCacheInMemory.ts +10 -14
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +10 -6
- package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +82 -0
- package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +88 -0
- package/src/storages/inRedis/EventsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +53 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +21 -17
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +122 -2
- package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +65 -0
- package/src/storages/inRedis/constants.ts +3 -0
- package/src/storages/inRedis/index.ts +15 -5
- package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +47 -0
- package/src/storages/pluggable/SplitsCachePluggable.ts +20 -17
- package/src/storages/pluggable/TelemetryCachePluggable.ts +147 -2
- package/src/storages/pluggable/UniqueKeysCachePluggable.ts +56 -0
- package/src/storages/pluggable/index.ts +44 -19
- package/src/storages/types.ts +38 -30
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
- package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -2
- package/src/sync/submitters/telemetrySubmitter.ts +15 -8
- package/src/sync/submitters/types.ts +18 -6
- package/src/sync/submitters/uniqueKeysSubmitter.ts +18 -61
- package/src/trackers/impressionsTracker.ts +16 -15
- package/src/trackers/strategy/strategyNone.ts +1 -1
- package/src/trackers/strategy/strategyOptimized.ts +1 -1
- package/src/trackers/telemetryTracker.ts +7 -2
- package/src/trackers/types.ts +9 -7
- package/src/trackers/uniqueKeysTracker.ts +15 -47
- package/src/types.ts +0 -1
- package/src/utils/constants/index.ts +1 -0
- package/src/utils/lang/maps.ts +20 -8
- package/src/utils/redis/RedisMock.ts +33 -0
- package/src/utils/settingsValidation/index.ts +1 -4
- package/types/integrations/types.d.ts +2 -1
- package/types/services/types.d.ts +2 -2
- package/types/storages/AbstractSplitsCacheAsync.d.ts +7 -6
- package/types/storages/AbstractSplitsCacheSync.d.ts +6 -6
- package/types/storages/KeyBuilderSS.d.ts +9 -2
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +3 -4
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +5 -1
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +3 -2
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -3
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +35 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +37 -0
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +14 -0
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +6 -5
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +16 -1
- package/types/storages/inRedis/constants.d.ts +3 -0
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +15 -0
- package/types/storages/pluggable/ImpressionCountsCachePluggable.d.ts +14 -0
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +6 -5
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +17 -1
- package/types/storages/pluggable/UniqueKeysCachePluggable.d.ts +14 -0
- package/types/storages/types.d.ts +35 -35
- package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
- package/types/sync/submitters/telemetrySubmitter.d.ts +1 -1
- package/types/sync/submitters/types.d.ts +12 -6
- package/types/sync/submitters/uniqueKeysSubmitter.d.ts +0 -14
- package/types/trackers/types.d.ts +9 -11
- package/types/trackers/uniqueKeysTracker.d.ts +3 -3
- package/types/types.d.ts +0 -1
- package/types/utils/constants/index.d.ts +1 -0
- package/types/utils/lang/maps.d.ts +6 -2
- package/types/utils/redis/RedisMock.d.ts +4 -0
- package/types/utils/settingsValidation/index.d.ts +0 -1
- package/types/sdkClient/types.d.ts +0 -18
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +0 -20
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
- package/types/sync/offline/LocalhostFromFile.d.ts +0 -2
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +0 -2
- package/types/sync/submitters/eventsSyncTask.d.ts +0 -8
- package/types/sync/submitters/impressionCountsSyncTask.d.ts +0 -13
- package/types/sync/submitters/impressionsSyncTask.d.ts +0 -14
- package/types/sync/submitters/metricsSyncTask.d.ts +0 -12
- package/types/sync/submitters/submitterSyncTask.d.ts +0 -10
- package/types/sync/syncTaskComposite.d.ts +0 -5
- package/types/trackers/filter/bloomFilter.d.ts +0 -10
- package/types/trackers/filter/dictionaryFilter.d.ts +0 -8
- package/types/trackers/filter/types.d.ts +0 -5
- package/types/utils/timeTracker/index.d.ts +0 -70
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __extends } from "tslib";
|
|
2
2
|
import { KeyBuilder } from './KeyBuilder';
|
|
3
|
-
|
|
3
|
+
import { MAX_LATENCY_BUCKET_COUNT } from './inMemory/TelemetryCacheInMemory';
|
|
4
|
+
var METHOD_NAMES = {
|
|
4
5
|
t: 'treatment',
|
|
5
6
|
ts: 'treatments',
|
|
6
7
|
tc: 'treatmentWithConfig',
|
|
@@ -11,7 +12,10 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
11
12
|
__extends(KeyBuilderSS, _super);
|
|
12
13
|
function KeyBuilderSS(prefix, metadata) {
|
|
13
14
|
var _this = _super.call(this, prefix) || this;
|
|
14
|
-
_this.
|
|
15
|
+
_this.latencyPrefix = _this.prefix + ".telemetry.latencies";
|
|
16
|
+
_this.exceptionPrefix = _this.prefix + ".telemetry.exceptions";
|
|
17
|
+
_this.initPrefix = _this.prefix + ".telemetry.init";
|
|
18
|
+
_this.versionablePrefix = metadata.s + "/" + metadata.n + "/" + metadata.i;
|
|
15
19
|
return _this;
|
|
16
20
|
}
|
|
17
21
|
KeyBuilderSS.prototype.buildRegisteredSegmentsKey = function () {
|
|
@@ -20,6 +24,12 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
20
24
|
KeyBuilderSS.prototype.buildImpressionsKey = function () {
|
|
21
25
|
return this.prefix + ".impressions";
|
|
22
26
|
};
|
|
27
|
+
KeyBuilderSS.prototype.buildImpressionsCountKey = function () {
|
|
28
|
+
return this.prefix + ".impressions.count";
|
|
29
|
+
};
|
|
30
|
+
KeyBuilderSS.prototype.buildUniqueKeysKey = function () {
|
|
31
|
+
return this.prefix + ".uniquekeys";
|
|
32
|
+
};
|
|
23
33
|
KeyBuilderSS.prototype.buildEventsKey = function () {
|
|
24
34
|
return this.prefix + ".events";
|
|
25
35
|
};
|
|
@@ -28,17 +38,49 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
28
38
|
};
|
|
29
39
|
/* Telemetry keys */
|
|
30
40
|
KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
|
|
31
|
-
return this.
|
|
41
|
+
return this.latencyPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method] + "/" + bucket;
|
|
32
42
|
};
|
|
33
43
|
KeyBuilderSS.prototype.buildExceptionKey = function (method) {
|
|
34
|
-
return this.
|
|
44
|
+
return this.exceptionPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method];
|
|
35
45
|
};
|
|
36
46
|
KeyBuilderSS.prototype.buildInitKey = function () {
|
|
37
|
-
return this.
|
|
38
|
-
};
|
|
39
|
-
KeyBuilderSS.prototype.buildVersionablePrefix = function () {
|
|
40
|
-
return this.metadata.s + "/" + this.metadata.n + "/" + this.metadata.i;
|
|
47
|
+
return this.initPrefix + "::" + this.versionablePrefix;
|
|
41
48
|
};
|
|
42
49
|
return KeyBuilderSS;
|
|
43
50
|
}(KeyBuilder));
|
|
44
51
|
export { KeyBuilderSS };
|
|
52
|
+
// Used by consumer methods of TelemetryCacheInRedis and TelemetryCachePluggable
|
|
53
|
+
var REVERSE_METHOD_NAMES = Object.keys(METHOD_NAMES).reduce(function (acc, key) {
|
|
54
|
+
acc[METHOD_NAMES[key]] = key;
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
57
|
+
export function parseMetadata(field) {
|
|
58
|
+
var parts = field.split('/');
|
|
59
|
+
if (parts.length !== 3)
|
|
60
|
+
return "invalid subsection count. Expected 3, got: " + parts.length;
|
|
61
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */;
|
|
62
|
+
return [JSON.stringify({ s: s, n: n, i: i })];
|
|
63
|
+
}
|
|
64
|
+
export function parseExceptionField(field) {
|
|
65
|
+
var parts = field.split('/');
|
|
66
|
+
if (parts.length !== 4)
|
|
67
|
+
return "invalid subsection count. Expected 4, got: " + parts.length;
|
|
68
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3];
|
|
69
|
+
var method = REVERSE_METHOD_NAMES[m];
|
|
70
|
+
if (!method)
|
|
71
|
+
return "unknown method '" + m + "'";
|
|
72
|
+
return [JSON.stringify({ s: s, n: n, i: i }), method];
|
|
73
|
+
}
|
|
74
|
+
export function parseLatencyField(field) {
|
|
75
|
+
var parts = field.split('/');
|
|
76
|
+
if (parts.length !== 5)
|
|
77
|
+
return "invalid subsection count. Expected 5, got: " + parts.length;
|
|
78
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3], b = parts[4];
|
|
79
|
+
var method = REVERSE_METHOD_NAMES[m];
|
|
80
|
+
if (!method)
|
|
81
|
+
return "unknown method '" + m + "'";
|
|
82
|
+
var bucket = parseInt(b);
|
|
83
|
+
if (isNaN(bucket) || bucket >= MAX_LATENCY_BUCKET_COUNT)
|
|
84
|
+
return "invalid bucket. Expected a number between 0 and " + (MAX_LATENCY_BUCKET_COUNT - 1) + ", got: " + b;
|
|
85
|
+
return [JSON.stringify({ s: s, n: n, i: i }), method, bucket];
|
|
86
|
+
}
|
|
@@ -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
|
|
@@ -201,7 +200,6 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
201
200
|
};
|
|
202
201
|
/**
|
|
203
202
|
* Clean Splits cache if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
|
|
204
|
-
* Clean operation (clear) also updates `lastUpdated` timestamp with current time.
|
|
205
203
|
*
|
|
206
204
|
* @param {number | undefined} expirationTimestamp if the value is not a number, data will not be cleaned
|
|
207
205
|
*/
|
|
@@ -11,8 +11,9 @@ import { SplitsCacheInMemory } from '../inMemory/SplitsCacheInMemory';
|
|
|
11
11
|
import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../../utils/constants/browser';
|
|
12
12
|
import { InMemoryStorageCSFactory } from '../inMemory/InMemoryStorageCS';
|
|
13
13
|
import { LOG_PREFIX } from './constants';
|
|
14
|
-
import {
|
|
14
|
+
import { NONE, STORAGE_LOCALSTORAGE } from '../../utils/constants';
|
|
15
15
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from '../inMemory/TelemetryCacheInMemory';
|
|
16
|
+
import { UniqueKeysCacheInMemoryCS } from '../inMemory/UniqueKeysCacheInMemoryCS';
|
|
16
17
|
/**
|
|
17
18
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
18
19
|
*/
|
|
@@ -34,13 +35,16 @@ export function InLocalStorage(options) {
|
|
|
34
35
|
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
35
36
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
36
37
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
37
|
-
telemetry:
|
|
38
|
+
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory() : undefined,
|
|
39
|
+
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemoryCS() : undefined,
|
|
38
40
|
destroy: function () {
|
|
41
|
+
var _a;
|
|
39
42
|
this.splits = new SplitsCacheInMemory();
|
|
40
43
|
this.segments = new MySegmentsCacheInMemory();
|
|
41
44
|
this.impressions.clear();
|
|
42
45
|
this.impressionCounts && this.impressionCounts.clear();
|
|
43
46
|
this.events.clear();
|
|
47
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
44
48
|
},
|
|
45
49
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
|
|
46
50
|
shared: function (matchingKey) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { truncateTimeFrame } from '../../utils/time';
|
|
2
|
+
import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
|
|
2
3
|
var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
3
|
-
function ImpressionCountsCacheInMemory() {
|
|
4
|
+
function ImpressionCountsCacheInMemory(impressionCountsCacheSize) {
|
|
5
|
+
if (impressionCountsCacheSize === void 0) { impressionCountsCacheSize = DEFAULT_CACHE_SIZE; }
|
|
4
6
|
this.cache = {};
|
|
7
|
+
this.cacheSize = 0;
|
|
8
|
+
this.maxStorage = impressionCountsCacheSize;
|
|
5
9
|
}
|
|
6
10
|
/**
|
|
7
11
|
* Builds key to be stored in the cache with the featureName and the timeFrame truncated.
|
|
@@ -16,6 +20,13 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
|
16
20
|
var key = this._makeKey(featureName, timeFrame);
|
|
17
21
|
var currentAmount = this.cache[key];
|
|
18
22
|
this.cache[key] = currentAmount ? currentAmount + amount : amount;
|
|
23
|
+
if (this.onFullQueue) {
|
|
24
|
+
this.cacheSize = this.cacheSize + amount;
|
|
25
|
+
if (this.cacheSize >= this.maxStorage) {
|
|
26
|
+
this.onFullQueue();
|
|
27
|
+
this.cacheSize = 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
19
30
|
};
|
|
20
31
|
/**
|
|
21
32
|
* Pop the collected data, used as payload for posting.
|
|
@@ -3,8 +3,9 @@ import { SegmentsCacheInMemory } from './SegmentsCacheInMemory';
|
|
|
3
3
|
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
|
|
4
4
|
import { EventsCacheInMemory } from './EventsCacheInMemory';
|
|
5
5
|
import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
6
|
-
import {
|
|
7
|
-
import { TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
6
|
+
import { DEBUG, NONE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
|
+
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
|
+
import { UniqueKeysCacheInMemory } from './UniqueKeysCacheInMemory';
|
|
8
9
|
/**
|
|
9
10
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
10
11
|
*
|
|
@@ -15,16 +16,19 @@ export function InMemoryStorageFactory(params) {
|
|
|
15
16
|
splits: new SplitsCacheInMemory(),
|
|
16
17
|
segments: new SegmentsCacheInMemory(),
|
|
17
18
|
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
18
|
-
impressionCounts: params.
|
|
19
|
+
impressionCounts: params.impressionsMode !== DEBUG ? new ImpressionCountsCacheInMemory() : undefined,
|
|
19
20
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
20
|
-
telemetry: params
|
|
21
|
+
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory() : undefined,
|
|
22
|
+
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemory() : undefined,
|
|
21
23
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
22
24
|
destroy: function () {
|
|
25
|
+
var _a;
|
|
23
26
|
this.splits.clear();
|
|
24
27
|
this.segments.clear();
|
|
25
28
|
this.impressions.clear();
|
|
26
29
|
this.impressionCounts && this.impressionCounts.clear();
|
|
27
30
|
this.events.clear();
|
|
31
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
28
32
|
}
|
|
29
33
|
};
|
|
30
34
|
}
|
|
@@ -3,8 +3,9 @@ import { MySegmentsCacheInMemory } from './MySegmentsCacheInMemory';
|
|
|
3
3
|
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
|
|
4
4
|
import { EventsCacheInMemory } from './EventsCacheInMemory';
|
|
5
5
|
import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
6
|
-
import {
|
|
6
|
+
import { DEBUG, NONE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
|
+
import { UniqueKeysCacheInMemoryCS } from './UniqueKeysCacheInMemoryCS';
|
|
8
9
|
/**
|
|
9
10
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
10
11
|
*
|
|
@@ -15,16 +16,19 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
15
16
|
splits: new SplitsCacheInMemory(),
|
|
16
17
|
segments: new MySegmentsCacheInMemory(),
|
|
17
18
|
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
18
|
-
impressionCounts: params.
|
|
19
|
+
impressionCounts: params.impressionsMode !== DEBUG ? new ImpressionCountsCacheInMemory() : undefined,
|
|
19
20
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
20
|
-
telemetry:
|
|
21
|
+
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory() : undefined,
|
|
22
|
+
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemoryCS() : undefined,
|
|
21
23
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
22
24
|
destroy: function () {
|
|
25
|
+
var _a;
|
|
23
26
|
this.splits.clear();
|
|
24
27
|
this.segments.clear();
|
|
25
28
|
this.impressions.clear();
|
|
26
29
|
this.impressionCounts && this.impressionCounts.clear();
|
|
27
30
|
this.events.clear();
|
|
31
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
28
32
|
},
|
|
29
33
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are unique per key)
|
|
30
34
|
shared: function () {
|
|
@@ -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
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
import { LOCALHOST_MODE } from '../../utils/constants';
|
|
1
2
|
import { findLatencyIndex } from '../findLatencyIndex';
|
|
2
3
|
var MAX_STREAMING_EVENTS = 20;
|
|
3
4
|
var MAX_TAGS = 10;
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
export var MAX_LATENCY_BUCKET_COUNT = 23;
|
|
6
|
+
export function newBuckets() {
|
|
7
|
+
// MAX_LATENCY_BUCKET_COUNT (length) is 23
|
|
8
|
+
// Not using Array.fill for old browsers compatibility
|
|
6
9
|
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
7
10
|
}
|
|
8
11
|
var ACCEPTANCE_RANGE = 0.001;
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
13
|
+
* Record telemetry if mode is not localhost.
|
|
14
|
+
* All factory instances track telemetry on server-side, and 0.1% on client-side.
|
|
11
15
|
*/
|
|
12
|
-
export function shouldRecordTelemetry() {
|
|
13
|
-
return Math.random() <= ACCEPTANCE_RANGE;
|
|
16
|
+
export function shouldRecordTelemetry(params) {
|
|
17
|
+
return params.mode !== LOCALHOST_MODE && (params.matchingKey === undefined || Math.random() <= ACCEPTANCE_RANGE);
|
|
14
18
|
}
|
|
15
19
|
var TelemetryCacheInMemory = /** @class */ (function () {
|
|
16
20
|
function TelemetryCacheInMemory() {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { setToArray, _Set } from '../../utils/lang/sets';
|
|
2
|
+
import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
|
|
3
|
+
var UniqueKeysCacheInMemory = /** @class */ (function () {
|
|
4
|
+
function UniqueKeysCacheInMemory(uniqueKeysQueueSize) {
|
|
5
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = DEFAULT_CACHE_SIZE; }
|
|
6
|
+
this.uniqueTrackerSize = 0;
|
|
7
|
+
this.maxStorage = uniqueKeysQueueSize;
|
|
8
|
+
this.uniqueKeysTracker = {};
|
|
9
|
+
}
|
|
10
|
+
UniqueKeysCacheInMemory.prototype.setOnFullQueueCb = function (cb) {
|
|
11
|
+
this.onFullQueue = cb;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Store unique keys in sequential order
|
|
15
|
+
* key: string = feature name.
|
|
16
|
+
* value: Set<string> = set of unique keys.
|
|
17
|
+
*/
|
|
18
|
+
UniqueKeysCacheInMemory.prototype.track = function (key, featureName) {
|
|
19
|
+
if (!this.uniqueKeysTracker[featureName])
|
|
20
|
+
this.uniqueKeysTracker[featureName] = new _Set();
|
|
21
|
+
var tracker = this.uniqueKeysTracker[featureName];
|
|
22
|
+
if (!tracker.has(key)) {
|
|
23
|
+
tracker.add(key);
|
|
24
|
+
this.uniqueTrackerSize++;
|
|
25
|
+
}
|
|
26
|
+
if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
|
|
27
|
+
this.uniqueTrackerSize = 0;
|
|
28
|
+
this.onFullQueue();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Clear the data stored on the cache.
|
|
33
|
+
*/
|
|
34
|
+
UniqueKeysCacheInMemory.prototype.clear = function () {
|
|
35
|
+
this.uniqueKeysTracker = {};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Pop the collected data, used as payload for posting.
|
|
39
|
+
*/
|
|
40
|
+
UniqueKeysCacheInMemory.prototype.pop = function () {
|
|
41
|
+
var data = this.uniqueKeysTracker;
|
|
42
|
+
this.uniqueKeysTracker = {};
|
|
43
|
+
return this.fromUniqueKeysCollector(data);
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Check if the cache is empty.
|
|
47
|
+
*/
|
|
48
|
+
UniqueKeysCacheInMemory.prototype.isEmpty = function () {
|
|
49
|
+
return Object.keys(this.uniqueKeysTracker).length === 0;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Converts `uniqueKeys` data from cache into request payload for SS.
|
|
53
|
+
*/
|
|
54
|
+
UniqueKeysCacheInMemory.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
|
|
55
|
+
var payload = [];
|
|
56
|
+
var featureNames = Object.keys(uniqueKeys);
|
|
57
|
+
for (var i = 0; i < featureNames.length; i++) {
|
|
58
|
+
var featureName = featureNames[i];
|
|
59
|
+
var featureKeys = setToArray(uniqueKeys[featureName]);
|
|
60
|
+
var uniqueKeysPayload = {
|
|
61
|
+
f: featureName,
|
|
62
|
+
ks: featureKeys
|
|
63
|
+
};
|
|
64
|
+
payload.push(uniqueKeysPayload);
|
|
65
|
+
}
|
|
66
|
+
return { keys: payload };
|
|
67
|
+
};
|
|
68
|
+
return UniqueKeysCacheInMemory;
|
|
69
|
+
}());
|
|
70
|
+
export { UniqueKeysCacheInMemory };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { setToArray, _Set } from '../../utils/lang/sets';
|
|
2
|
+
import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
|
|
3
|
+
var UniqueKeysCacheInMemoryCS = /** @class */ (function () {
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param impressionsQueueSize number of queued impressions to call onFullQueueCb.
|
|
7
|
+
* Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
|
|
8
|
+
*/
|
|
9
|
+
function UniqueKeysCacheInMemoryCS(uniqueKeysQueueSize) {
|
|
10
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = DEFAULT_CACHE_SIZE; }
|
|
11
|
+
this.uniqueTrackerSize = 0;
|
|
12
|
+
this.maxStorage = uniqueKeysQueueSize;
|
|
13
|
+
this.uniqueKeysTracker = {};
|
|
14
|
+
}
|
|
15
|
+
UniqueKeysCacheInMemoryCS.prototype.setOnFullQueueCb = function (cb) {
|
|
16
|
+
this.onFullQueue = cb;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Store unique keys in sequential order
|
|
20
|
+
* key: string = key.
|
|
21
|
+
* value: HashSet<string> = set of split names.
|
|
22
|
+
*/
|
|
23
|
+
UniqueKeysCacheInMemoryCS.prototype.track = function (key, featureName) {
|
|
24
|
+
if (!this.uniqueKeysTracker[key])
|
|
25
|
+
this.uniqueKeysTracker[key] = new _Set();
|
|
26
|
+
var tracker = this.uniqueKeysTracker[key];
|
|
27
|
+
if (!tracker.has(featureName)) {
|
|
28
|
+
tracker.add(featureName);
|
|
29
|
+
this.uniqueTrackerSize++;
|
|
30
|
+
}
|
|
31
|
+
if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
|
|
32
|
+
this.uniqueTrackerSize = 0;
|
|
33
|
+
this.onFullQueue();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Clear the data stored on the cache.
|
|
38
|
+
*/
|
|
39
|
+
UniqueKeysCacheInMemoryCS.prototype.clear = function () {
|
|
40
|
+
this.uniqueKeysTracker = {};
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Pop the collected data, used as payload for posting.
|
|
44
|
+
*/
|
|
45
|
+
UniqueKeysCacheInMemoryCS.prototype.pop = function () {
|
|
46
|
+
var data = this.uniqueKeysTracker;
|
|
47
|
+
this.uniqueKeysTracker = {};
|
|
48
|
+
return this.fromUniqueKeysCollector(data);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Check if the cache is empty.
|
|
52
|
+
*/
|
|
53
|
+
UniqueKeysCacheInMemoryCS.prototype.isEmpty = function () {
|
|
54
|
+
return Object.keys(this.uniqueKeysTracker).length === 0;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Converts `uniqueKeys` data from cache into request payload.
|
|
58
|
+
*/
|
|
59
|
+
UniqueKeysCacheInMemoryCS.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
|
|
60
|
+
var payload = [];
|
|
61
|
+
var featureKeys = Object.keys(uniqueKeys);
|
|
62
|
+
for (var k = 0; k < featureKeys.length; k++) {
|
|
63
|
+
var featureKey = featureKeys[k];
|
|
64
|
+
var featureNames = setToArray(uniqueKeys[featureKey]);
|
|
65
|
+
var uniqueKeysPayload = {
|
|
66
|
+
k: featureKey,
|
|
67
|
+
fs: featureNames
|
|
68
|
+
};
|
|
69
|
+
payload.push(uniqueKeysPayload);
|
|
70
|
+
}
|
|
71
|
+
return { keys: payload };
|
|
72
|
+
};
|
|
73
|
+
return UniqueKeysCacheInMemoryCS;
|
|
74
|
+
}());
|
|
75
|
+
export { UniqueKeysCacheInMemoryCS };
|
|
@@ -39,7 +39,7 @@ var EventsCacheInRedis = /** @class */ (function () {
|
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
41
|
* Pop the given number of events from the storage.
|
|
42
|
-
* The returned promise rejects if the
|
|
42
|
+
* The returned promise rejects if the redis operation fails.
|
|
43
43
|
*
|
|
44
44
|
* NOTE: this method doesn't take into account MAX_EVENT_SIZE or MAX_QUEUE_BYTE_SIZE limits.
|
|
45
45
|
* It is the submitter responsability to handle that.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
|
|
3
|
+
import { LOG_PREFIX, REFRESH_RATE, TTL_REFRESH } from './constants';
|
|
4
|
+
var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
|
|
5
|
+
__extends(ImpressionCountsCacheInRedis, _super);
|
|
6
|
+
function ImpressionCountsCacheInRedis(log, key, redis, impressionCountsCacheSize, refreshRate) {
|
|
7
|
+
if (refreshRate === void 0) { refreshRate = REFRESH_RATE; }
|
|
8
|
+
var _this = _super.call(this, impressionCountsCacheSize) || this;
|
|
9
|
+
_this.log = log;
|
|
10
|
+
_this.key = key;
|
|
11
|
+
_this.redis = redis;
|
|
12
|
+
_this.refreshRate = refreshRate;
|
|
13
|
+
_this.onFullQueue = function () { _this.postImpressionCountsInRedis(); };
|
|
14
|
+
return _this;
|
|
15
|
+
}
|
|
16
|
+
ImpressionCountsCacheInRedis.prototype.postImpressionCountsInRedis = function () {
|
|
17
|
+
var _this = this;
|
|
18
|
+
var counts = this.pop();
|
|
19
|
+
var keys = Object.keys(counts);
|
|
20
|
+
if (!keys.length)
|
|
21
|
+
return Promise.resolve(false);
|
|
22
|
+
var pipeline = this.redis.pipeline();
|
|
23
|
+
keys.forEach(function (key) {
|
|
24
|
+
pipeline.hincrby(_this.key, key, counts[key]);
|
|
25
|
+
});
|
|
26
|
+
return pipeline.exec()
|
|
27
|
+
.then(function (data) {
|
|
28
|
+
// If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
|
|
29
|
+
if (data.length && data.length === keys.length) {
|
|
30
|
+
return _this.redis.expire(_this.key, TTL_REFRESH);
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
.catch(function (err) {
|
|
34
|
+
_this.log.error(LOG_PREFIX + "Error in impression counts pipeline: " + err + ".");
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
ImpressionCountsCacheInRedis.prototype.start = function () {
|
|
39
|
+
this.intervalId = setInterval(this.postImpressionCountsInRedis.bind(this), this.refreshRate);
|
|
40
|
+
};
|
|
41
|
+
ImpressionCountsCacheInRedis.prototype.stop = function () {
|
|
42
|
+
clearInterval(this.intervalId);
|
|
43
|
+
return this.postImpressionCountsInRedis();
|
|
44
|
+
};
|
|
45
|
+
return ImpressionCountsCacheInRedis;
|
|
46
|
+
}(ImpressionCountsCacheInMemory));
|
|
47
|
+
export { ImpressionCountsCacheInRedis };
|
|
@@ -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
|
})
|