@splitsoftware/splitio-commons 1.6.2-rc.9 → 1.7.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 +3 -1
- package/cjs/consent/sdkUserConsent.js +2 -2
- package/cjs/listeners/browser.js +11 -12
- package/cjs/logger/constants.js +2 -1
- package/cjs/sdkClient/sdkClient.js +3 -1
- package/cjs/sdkFactory/index.js +26 -26
- package/cjs/services/splitApi.js +20 -0
- package/cjs/storages/AbstractSplitsCacheAsync.js +1 -1
- package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
- package/cjs/storages/KeyBuilderSS.js +10 -43
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -1
- package/cjs/storages/inLocalStorage/index.js +17 -9
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +13 -6
- package/cjs/storages/inMemory/InMemoryStorageCS.js +13 -6
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +60 -35
- package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +72 -0
- package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +76 -0
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +85 -0
- package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +4 -4
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +71 -0
- package/cjs/storages/inRedis/constants.js +4 -1
- package/cjs/storages/inRedis/index.js +20 -3
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +81 -0
- package/cjs/storages/pluggable/ImpressionsCachePluggable.js +2 -19
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +4 -4
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +61 -0
- package/cjs/storages/pluggable/inMemoryWrapper.js +8 -6
- package/cjs/storages/pluggable/index.js +38 -9
- package/cjs/storages/utils.js +73 -0
- package/cjs/sync/submitters/submitterManager.js +3 -0
- package/cjs/sync/submitters/telemetrySubmitter.js +5 -40
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +27 -0
- package/cjs/trackers/impressionObserver/utils.js +1 -17
- package/cjs/trackers/impressionsTracker.js +22 -41
- package/cjs/trackers/strategy/strategyDebug.js +25 -0
- package/cjs/trackers/strategy/strategyNone.js +29 -0
- package/cjs/trackers/strategy/strategyOptimized.js +35 -0
- package/cjs/trackers/uniqueKeysTracker.js +38 -0
- package/cjs/utils/constants/index.js +4 -2
- package/cjs/utils/redis/RedisMock.js +31 -0
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/cjs/utils/settingsValidation/index.js +7 -1
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/listeners/browser.js +12 -13
- package/esm/logger/constants.js +1 -0
- package/esm/sdkClient/sdkClient.js +3 -1
- package/esm/sdkFactory/index.js +26 -26
- package/esm/services/splitApi.js +20 -0
- package/esm/storages/AbstractSplitsCacheAsync.js +1 -1
- package/esm/storages/AbstractSplitsCacheSync.js +1 -1
- package/esm/storages/KeyBuilderSS.js +7 -37
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -1
- package/esm/storages/inLocalStorage/index.js +18 -10
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/esm/storages/inMemory/InMemoryStorage.js +14 -7
- package/esm/storages/inMemory/InMemoryStorageCS.js +14 -7
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +61 -36
- package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +68 -0
- package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +73 -0
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +82 -0
- package/esm/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +1 -1
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +68 -0
- package/esm/storages/inRedis/constants.js +3 -0
- package/esm/storages/inRedis/index.js +21 -4
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +78 -0
- package/esm/storages/pluggable/ImpressionsCachePluggable.js +2 -19
- package/esm/storages/pluggable/TelemetryCachePluggable.js +1 -1
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +58 -0
- package/esm/storages/pluggable/inMemoryWrapper.js +8 -6
- package/esm/storages/pluggable/index.js +39 -10
- package/esm/storages/utils.js +65 -0
- package/esm/sync/submitters/submitterManager.js +3 -0
- package/esm/sync/submitters/telemetrySubmitter.js +5 -39
- package/esm/sync/submitters/uniqueKeysSubmitter.js +23 -0
- package/esm/trackers/impressionObserver/utils.js +1 -15
- package/esm/trackers/impressionsTracker.js +22 -41
- package/esm/trackers/strategy/strategyDebug.js +21 -0
- package/esm/trackers/strategy/strategyNone.js +25 -0
- package/esm/trackers/strategy/strategyOptimized.js +31 -0
- package/esm/trackers/uniqueKeysTracker.js +34 -0
- package/esm/utils/constants/index.js +2 -0
- package/esm/utils/redis/RedisMock.js +28 -0
- package/esm/utils/settingsValidation/impressionsMode.js +3 -3
- package/esm/utils/settingsValidation/index.js +7 -1
- package/package.json +1 -2
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/listeners/browser.ts +12 -15
- package/src/logger/constants.ts +1 -0
- package/src/sdkClient/sdkClient.ts +3 -1
- package/src/sdkFactory/index.ts +29 -31
- package/src/sdkFactory/types.ts +7 -4
- package/src/services/splitApi.ts +22 -0
- package/src/services/types.ts +6 -0
- package/src/storages/AbstractSplitsCacheAsync.ts +1 -1
- package/src/storages/AbstractSplitsCacheSync.ts +1 -1
- package/src/storages/KeyBuilderSS.ts +9 -43
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +0 -1
- package/src/storages/inLocalStorage/index.ts +18 -10
- package/src/storages/inMemory/AttributesCacheInMemory.ts +7 -7
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +16 -1
- package/src/storages/inMemory/InMemoryStorage.ts +14 -7
- package/src/storages/inMemory/InMemoryStorageCS.ts +14 -7
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +69 -34
- package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +80 -0
- package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +86 -0
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +95 -0
- package/src/storages/inRedis/ImpressionsCacheInRedis.ts +2 -22
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +3 -2
- package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +77 -0
- package/src/storages/inRedis/constants.ts +3 -0
- package/src/storages/inRedis/index.ts +18 -5
- package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +92 -0
- package/src/storages/pluggable/ImpressionsCachePluggable.ts +3 -23
- package/src/storages/pluggable/TelemetryCachePluggable.ts +3 -2
- package/src/storages/pluggable/UniqueKeysCachePluggable.ts +67 -0
- package/src/storages/pluggable/inMemoryWrapper.ts +6 -6
- package/src/storages/pluggable/index.ts +41 -9
- package/src/storages/types.ts +56 -55
- package/src/storages/utils.ts +78 -0
- package/src/sync/submitters/submitter.ts +2 -2
- package/src/sync/submitters/submitterManager.ts +2 -0
- package/src/sync/submitters/telemetrySubmitter.ts +8 -43
- package/src/sync/submitters/types.ts +29 -27
- package/src/sync/submitters/uniqueKeysSubmitter.ts +36 -0
- package/src/trackers/impressionObserver/utils.ts +1 -16
- package/src/trackers/impressionsTracker.ts +25 -46
- package/src/trackers/strategy/strategyDebug.ts +28 -0
- package/src/trackers/strategy/strategyNone.ts +34 -0
- package/src/trackers/strategy/strategyOptimized.ts +42 -0
- package/src/trackers/types.ts +28 -0
- package/src/trackers/uniqueKeysTracker.ts +48 -0
- package/src/types.ts +1 -1
- package/src/utils/constants/index.ts +2 -0
- package/src/utils/redis/RedisMock.ts +33 -0
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +5 -1
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkFactory/types.d.ts +4 -2
- package/types/services/types.d.ts +4 -0
- package/types/storages/AbstractSplitsCacheAsync.d.ts +1 -1
- package/types/storages/AbstractSplitsCacheSync.d.ts +1 -1
- package/types/storages/KeyBuilderSS.d.ts +3 -3
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +0 -1
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +5 -1
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +20 -9
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +35 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +35 -0
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +16 -0
- package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +0 -1
- package/types/storages/inRedis/constants.d.ts +3 -0
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +21 -0
- package/types/storages/pluggable/ImpressionCountsCachePluggable.d.ts +16 -0
- package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +1 -2
- package/types/storages/pluggable/UniqueKeysCachePluggable.d.ts +20 -0
- package/types/storages/types.d.ts +39 -38
- package/types/storages/utils.d.ts +8 -0
- package/types/sync/submitters/submitter.d.ts +2 -2
- package/types/sync/submitters/telemetrySubmitter.d.ts +2 -10
- package/types/sync/submitters/types.d.ts +27 -7
- package/types/sync/submitters/uniqueKeysSubmitter.d.ts +5 -0
- package/types/trackers/impressionObserver/utils.d.ts +0 -8
- package/types/trackers/impressionsTracker.d.ts +4 -6
- package/types/trackers/strategy/strategyDebug.d.ts +9 -0
- package/types/trackers/strategy/strategyNone.d.ts +10 -0
- package/types/trackers/strategy/strategyOptimized.d.ts +11 -0
- package/types/trackers/types.d.ts +23 -0
- package/types/trackers/uniqueKeysTracker.d.ts +13 -0
- package/types/types.d.ts +1 -1
- package/types/utils/constants/index.d.ts +2 -0
- package/types/utils/redis/RedisMock.d.ts +4 -0
- package/cjs/storages/metadataBuilder.js +0 -12
- package/esm/storages/metadataBuilder.js +0 -8
- package/src/storages/metadataBuilder.ts +0 -11
|
@@ -7,7 +7,9 @@ var MAX_STREAMING_EVENTS = 20;
|
|
|
7
7
|
var MAX_TAGS = 10;
|
|
8
8
|
exports.MAX_LATENCY_BUCKET_COUNT = 23;
|
|
9
9
|
function newBuckets() {
|
|
10
|
-
|
|
10
|
+
// MAX_LATENCY_BUCKET_COUNT (length) is 23
|
|
11
|
+
// Not using Array.fill for old browsers compatibility
|
|
12
|
+
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
11
13
|
}
|
|
12
14
|
exports.newBuckets = newBuckets;
|
|
13
15
|
var ACCEPTANCE_RANGE = 0.001;
|
|
@@ -15,30 +17,56 @@ var ACCEPTANCE_RANGE = 0.001;
|
|
|
15
17
|
* Record telemetry if mode is not localhost.
|
|
16
18
|
* All factory instances track telemetry on server-side, and 0.1% on client-side.
|
|
17
19
|
*/
|
|
18
|
-
function shouldRecordTelemetry(
|
|
19
|
-
|
|
20
|
+
function shouldRecordTelemetry(_a) {
|
|
21
|
+
var settings = _a.settings;
|
|
22
|
+
return settings.mode !== constants_1.LOCALHOST_MODE && (settings.core.key === undefined || Math.random() <= ACCEPTANCE_RANGE);
|
|
20
23
|
}
|
|
21
24
|
exports.shouldRecordTelemetry = shouldRecordTelemetry;
|
|
22
25
|
var TelemetryCacheInMemory = /** @class */ (function () {
|
|
23
|
-
function TelemetryCacheInMemory() {
|
|
26
|
+
function TelemetryCacheInMemory(splits, segments) {
|
|
27
|
+
this.splits = splits;
|
|
28
|
+
this.segments = segments;
|
|
29
|
+
// isEmpty flag
|
|
30
|
+
this.e = true;
|
|
24
31
|
this.notReadyUsage = 0;
|
|
32
|
+
/** Usage stats */
|
|
25
33
|
this.impressionStats = [0, 0, 0];
|
|
26
34
|
this.eventStats = [0, 0];
|
|
27
|
-
// @ts-expect-error
|
|
28
35
|
this.lastSync = {};
|
|
29
|
-
// @ts-expect-error
|
|
30
36
|
this.httpErrors = {};
|
|
31
|
-
// @ts-expect-error
|
|
32
37
|
this.httpLatencies = {};
|
|
33
38
|
this.authRejections = 0;
|
|
34
39
|
this.tokenRefreshes = 0;
|
|
35
40
|
this.streamingEvents = [];
|
|
36
41
|
this.tags = [];
|
|
37
|
-
// @ts-expect-error
|
|
38
42
|
this.exceptions = {};
|
|
39
|
-
// @ts-expect-error
|
|
40
43
|
this.latencies = {};
|
|
41
44
|
}
|
|
45
|
+
TelemetryCacheInMemory.prototype.isEmpty = function () { return this.e; };
|
|
46
|
+
TelemetryCacheInMemory.prototype.clear = function () { };
|
|
47
|
+
TelemetryCacheInMemory.prototype.pop = function () {
|
|
48
|
+
this.e = true;
|
|
49
|
+
return {
|
|
50
|
+
lS: this.getLastSynchronization(),
|
|
51
|
+
mL: this.popLatencies(),
|
|
52
|
+
mE: this.popExceptions(),
|
|
53
|
+
hE: this.popHttpErrors(),
|
|
54
|
+
hL: this.popHttpLatencies(),
|
|
55
|
+
tR: this.popTokenRefreshes(),
|
|
56
|
+
aR: this.popAuthRejections(),
|
|
57
|
+
iQ: this.getImpressionStats(constants_1.QUEUED),
|
|
58
|
+
iDe: this.getImpressionStats(constants_1.DEDUPED),
|
|
59
|
+
iDr: this.getImpressionStats(constants_1.DROPPED),
|
|
60
|
+
spC: this.splits && this.splits.getSplitNames().length,
|
|
61
|
+
seC: this.segments && this.segments.getRegisteredSegments().length,
|
|
62
|
+
skC: this.segments && this.segments.getKeysCount(),
|
|
63
|
+
sL: this.getSessionLength(),
|
|
64
|
+
eQ: this.getEventStats(constants_1.QUEUED),
|
|
65
|
+
eD: this.getEventStats(constants_1.DROPPED),
|
|
66
|
+
sE: this.popStreamingEvents(),
|
|
67
|
+
t: this.popTags(),
|
|
68
|
+
};
|
|
69
|
+
};
|
|
42
70
|
TelemetryCacheInMemory.prototype.getTimeUntilReady = function () {
|
|
43
71
|
return this.timeUntilReady;
|
|
44
72
|
};
|
|
@@ -62,44 +90,41 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
62
90
|
};
|
|
63
91
|
TelemetryCacheInMemory.prototype.recordImpressionStats = function (type, count) {
|
|
64
92
|
this.impressionStats[type] += count;
|
|
93
|
+
this.e = false;
|
|
65
94
|
};
|
|
66
95
|
TelemetryCacheInMemory.prototype.getEventStats = function (type) {
|
|
67
96
|
return this.eventStats[type];
|
|
68
97
|
};
|
|
69
98
|
TelemetryCacheInMemory.prototype.recordEventStats = function (type, count) {
|
|
70
99
|
this.eventStats[type] += count;
|
|
100
|
+
this.e = false;
|
|
71
101
|
};
|
|
72
102
|
TelemetryCacheInMemory.prototype.getLastSynchronization = function () {
|
|
73
103
|
return this.lastSync;
|
|
74
104
|
};
|
|
75
105
|
TelemetryCacheInMemory.prototype.recordSuccessfulSync = function (resource, timeMs) {
|
|
76
106
|
this.lastSync[resource] = timeMs;
|
|
107
|
+
this.e = false;
|
|
77
108
|
};
|
|
78
109
|
TelemetryCacheInMemory.prototype.popHttpErrors = function () {
|
|
79
|
-
var result = this.httpErrors;
|
|
110
|
+
var result = this.httpErrors;
|
|
80
111
|
this.httpErrors = {};
|
|
81
112
|
return result;
|
|
82
113
|
};
|
|
83
114
|
TelemetryCacheInMemory.prototype.recordHttpError = function (resource, status) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this.httpErrors[resource][status] = 1;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
this.httpErrors[resource][status]++;
|
|
91
|
-
}
|
|
115
|
+
var statusErrors = (this.httpErrors[resource] = this.httpErrors[resource] || {});
|
|
116
|
+
statusErrors[status] = (statusErrors[status] || 0) + 1;
|
|
117
|
+
this.e = false;
|
|
92
118
|
};
|
|
93
119
|
TelemetryCacheInMemory.prototype.popHttpLatencies = function () {
|
|
94
|
-
var result = this.httpLatencies;
|
|
120
|
+
var result = this.httpLatencies;
|
|
95
121
|
this.httpLatencies = {};
|
|
96
122
|
return result;
|
|
97
123
|
};
|
|
98
124
|
TelemetryCacheInMemory.prototype.recordHttpLatency = function (resource, latencyMs) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this.httpLatencies[resource][(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
|
|
125
|
+
var latencyBuckets = (this.httpLatencies[resource] = this.httpLatencies[resource] || newBuckets());
|
|
126
|
+
latencyBuckets[(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
|
|
127
|
+
this.e = false;
|
|
103
128
|
};
|
|
104
129
|
TelemetryCacheInMemory.prototype.popAuthRejections = function () {
|
|
105
130
|
var result = this.authRejections;
|
|
@@ -108,6 +133,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
108
133
|
};
|
|
109
134
|
TelemetryCacheInMemory.prototype.recordAuthRejections = function () {
|
|
110
135
|
this.authRejections++;
|
|
136
|
+
this.e = false;
|
|
111
137
|
};
|
|
112
138
|
TelemetryCacheInMemory.prototype.popTokenRefreshes = function () {
|
|
113
139
|
var result = this.tokenRefreshes;
|
|
@@ -116,6 +142,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
116
142
|
};
|
|
117
143
|
TelemetryCacheInMemory.prototype.recordTokenRefreshes = function () {
|
|
118
144
|
this.tokenRefreshes++;
|
|
145
|
+
this.e = false;
|
|
119
146
|
};
|
|
120
147
|
TelemetryCacheInMemory.prototype.popStreamingEvents = function () {
|
|
121
148
|
return this.streamingEvents.splice(0);
|
|
@@ -124,6 +151,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
124
151
|
if (this.streamingEvents.length < MAX_STREAMING_EVENTS) {
|
|
125
152
|
this.streamingEvents.push(streamingEvent);
|
|
126
153
|
}
|
|
154
|
+
this.e = false;
|
|
127
155
|
};
|
|
128
156
|
TelemetryCacheInMemory.prototype.popTags = function () {
|
|
129
157
|
return this.tags.splice(0);
|
|
@@ -132,36 +160,33 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
132
160
|
if (this.tags.length < MAX_TAGS) {
|
|
133
161
|
this.tags.push(tag);
|
|
134
162
|
}
|
|
163
|
+
this.e = false;
|
|
135
164
|
};
|
|
136
165
|
TelemetryCacheInMemory.prototype.getSessionLength = function () {
|
|
137
166
|
return this.sessionLength;
|
|
138
167
|
};
|
|
139
168
|
TelemetryCacheInMemory.prototype.recordSessionLength = function (ms) {
|
|
140
169
|
this.sessionLength = ms;
|
|
170
|
+
this.e = false;
|
|
141
171
|
};
|
|
142
172
|
TelemetryCacheInMemory.prototype.popExceptions = function () {
|
|
143
|
-
var result = this.exceptions;
|
|
173
|
+
var result = this.exceptions;
|
|
144
174
|
this.exceptions = {};
|
|
145
175
|
return result;
|
|
146
176
|
};
|
|
147
177
|
TelemetryCacheInMemory.prototype.recordException = function (method) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
this.exceptions[method]++;
|
|
153
|
-
}
|
|
178
|
+
this.exceptions[method] = (this.exceptions[method] || 0) + 1;
|
|
179
|
+
this.e = false;
|
|
154
180
|
};
|
|
155
181
|
TelemetryCacheInMemory.prototype.popLatencies = function () {
|
|
156
|
-
var result = this.latencies;
|
|
182
|
+
var result = this.latencies;
|
|
157
183
|
this.latencies = {};
|
|
158
184
|
return result;
|
|
159
185
|
};
|
|
160
186
|
TelemetryCacheInMemory.prototype.recordLatency = function (method, latencyMs) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.latencies[method][(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
|
|
187
|
+
var latencyBuckets = (this.latencies[method] = this.latencies[method] || newBuckets());
|
|
188
|
+
latencyBuckets[(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
|
|
189
|
+
this.e = false;
|
|
165
190
|
};
|
|
166
191
|
return TelemetryCacheInMemory;
|
|
167
192
|
}());
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueKeysCacheInMemory = exports.fromUniqueKeysCollector = void 0;
|
|
4
|
+
var sets_1 = require("../../utils/lang/sets");
|
|
5
|
+
var constants_1 = require("../inRedis/constants");
|
|
6
|
+
/**
|
|
7
|
+
* Converts `uniqueKeys` data from cache into request payload for SS.
|
|
8
|
+
*/
|
|
9
|
+
function fromUniqueKeysCollector(uniqueKeys) {
|
|
10
|
+
var payload = [];
|
|
11
|
+
var featureNames = Object.keys(uniqueKeys);
|
|
12
|
+
for (var i = 0; i < featureNames.length; i++) {
|
|
13
|
+
var featureName = featureNames[i];
|
|
14
|
+
var userKeys = (0, sets_1.setToArray)(uniqueKeys[featureName]);
|
|
15
|
+
var uniqueKeysPayload = {
|
|
16
|
+
f: featureName,
|
|
17
|
+
ks: userKeys
|
|
18
|
+
};
|
|
19
|
+
payload.push(uniqueKeysPayload);
|
|
20
|
+
}
|
|
21
|
+
return { keys: payload };
|
|
22
|
+
}
|
|
23
|
+
exports.fromUniqueKeysCollector = fromUniqueKeysCollector;
|
|
24
|
+
var UniqueKeysCacheInMemory = /** @class */ (function () {
|
|
25
|
+
function UniqueKeysCacheInMemory(uniqueKeysQueueSize) {
|
|
26
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
|
|
27
|
+
this.uniqueTrackerSize = 0;
|
|
28
|
+
this.maxStorage = uniqueKeysQueueSize;
|
|
29
|
+
this.uniqueKeysTracker = {};
|
|
30
|
+
}
|
|
31
|
+
UniqueKeysCacheInMemory.prototype.setOnFullQueueCb = function (cb) {
|
|
32
|
+
this.onFullQueue = cb;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Store unique keys per feature.
|
|
36
|
+
*/
|
|
37
|
+
UniqueKeysCacheInMemory.prototype.track = function (userKey, featureName) {
|
|
38
|
+
if (!this.uniqueKeysTracker[featureName])
|
|
39
|
+
this.uniqueKeysTracker[featureName] = new sets_1._Set();
|
|
40
|
+
var tracker = this.uniqueKeysTracker[featureName];
|
|
41
|
+
if (!tracker.has(userKey)) {
|
|
42
|
+
tracker.add(userKey);
|
|
43
|
+
this.uniqueTrackerSize++;
|
|
44
|
+
}
|
|
45
|
+
if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
|
|
46
|
+
this.uniqueTrackerSize = 0;
|
|
47
|
+
this.onFullQueue();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Clear the data stored on the cache.
|
|
52
|
+
*/
|
|
53
|
+
UniqueKeysCacheInMemory.prototype.clear = function () {
|
|
54
|
+
this.uniqueKeysTracker = {};
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Pop the collected data, used as payload for posting.
|
|
58
|
+
*/
|
|
59
|
+
UniqueKeysCacheInMemory.prototype.pop = function () {
|
|
60
|
+
var data = this.uniqueKeysTracker;
|
|
61
|
+
this.uniqueKeysTracker = {};
|
|
62
|
+
return fromUniqueKeysCollector(data);
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Check if the cache is empty.
|
|
66
|
+
*/
|
|
67
|
+
UniqueKeysCacheInMemory.prototype.isEmpty = function () {
|
|
68
|
+
return Object.keys(this.uniqueKeysTracker).length === 0;
|
|
69
|
+
};
|
|
70
|
+
return UniqueKeysCacheInMemory;
|
|
71
|
+
}());
|
|
72
|
+
exports.UniqueKeysCacheInMemory = UniqueKeysCacheInMemory;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueKeysCacheInMemoryCS = void 0;
|
|
4
|
+
var sets_1 = require("../../utils/lang/sets");
|
|
5
|
+
var constants_1 = require("../inRedis/constants");
|
|
6
|
+
var UniqueKeysCacheInMemoryCS = /** @class */ (function () {
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param impressionsQueueSize number of queued impressions to call onFullQueueCb.
|
|
10
|
+
* Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
|
|
11
|
+
*/
|
|
12
|
+
function UniqueKeysCacheInMemoryCS(uniqueKeysQueueSize) {
|
|
13
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
|
|
14
|
+
this.uniqueTrackerSize = 0;
|
|
15
|
+
this.maxStorage = uniqueKeysQueueSize;
|
|
16
|
+
this.uniqueKeysTracker = {};
|
|
17
|
+
}
|
|
18
|
+
UniqueKeysCacheInMemoryCS.prototype.setOnFullQueueCb = function (cb) {
|
|
19
|
+
this.onFullQueue = cb;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Store unique keys per feature.
|
|
23
|
+
*/
|
|
24
|
+
UniqueKeysCacheInMemoryCS.prototype.track = function (userKey, featureName) {
|
|
25
|
+
if (!this.uniqueKeysTracker[userKey])
|
|
26
|
+
this.uniqueKeysTracker[userKey] = new sets_1._Set();
|
|
27
|
+
var tracker = this.uniqueKeysTracker[userKey];
|
|
28
|
+
if (!tracker.has(featureName)) {
|
|
29
|
+
tracker.add(featureName);
|
|
30
|
+
this.uniqueTrackerSize++;
|
|
31
|
+
}
|
|
32
|
+
if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
|
|
33
|
+
this.uniqueTrackerSize = 0;
|
|
34
|
+
this.onFullQueue();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Clear the data stored on the cache.
|
|
39
|
+
*/
|
|
40
|
+
UniqueKeysCacheInMemoryCS.prototype.clear = function () {
|
|
41
|
+
this.uniqueKeysTracker = {};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Pop the collected data, used as payload for posting.
|
|
45
|
+
*/
|
|
46
|
+
UniqueKeysCacheInMemoryCS.prototype.pop = function () {
|
|
47
|
+
var data = this.uniqueKeysTracker;
|
|
48
|
+
this.uniqueKeysTracker = {};
|
|
49
|
+
return this.fromUniqueKeysCollector(data);
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Check if the cache is empty.
|
|
53
|
+
*/
|
|
54
|
+
UniqueKeysCacheInMemoryCS.prototype.isEmpty = function () {
|
|
55
|
+
return Object.keys(this.uniqueKeysTracker).length === 0;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Converts `uniqueKeys` data from cache into request payload.
|
|
59
|
+
*/
|
|
60
|
+
UniqueKeysCacheInMemoryCS.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
|
|
61
|
+
var payload = [];
|
|
62
|
+
var userKeys = Object.keys(uniqueKeys);
|
|
63
|
+
for (var k = 0; k < userKeys.length; k++) {
|
|
64
|
+
var userKey = userKeys[k];
|
|
65
|
+
var featureNames = (0, sets_1.setToArray)(uniqueKeys[userKey]);
|
|
66
|
+
var uniqueKeysPayload = {
|
|
67
|
+
k: userKey,
|
|
68
|
+
fs: featureNames
|
|
69
|
+
};
|
|
70
|
+
payload.push(uniqueKeysPayload);
|
|
71
|
+
}
|
|
72
|
+
return { keys: payload };
|
|
73
|
+
};
|
|
74
|
+
return UniqueKeysCacheInMemoryCS;
|
|
75
|
+
}());
|
|
76
|
+
exports.UniqueKeysCacheInMemoryCS = UniqueKeysCacheInMemoryCS;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImpressionCountsCacheInRedis = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var lang_1 = require("../../utils/lang");
|
|
6
|
+
var ImpressionCountsCacheInMemory_1 = require("../inMemory/ImpressionCountsCacheInMemory");
|
|
7
|
+
var constants_1 = require("./constants");
|
|
8
|
+
var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
|
|
9
|
+
(0, tslib_1.__extends)(ImpressionCountsCacheInRedis, _super);
|
|
10
|
+
function ImpressionCountsCacheInRedis(log, key, redis, impressionCountsCacheSize, refreshRate) {
|
|
11
|
+
if (refreshRate === void 0) { refreshRate = constants_1.REFRESH_RATE; }
|
|
12
|
+
var _this = _super.call(this, impressionCountsCacheSize) || this;
|
|
13
|
+
_this.log = log;
|
|
14
|
+
_this.key = key;
|
|
15
|
+
_this.redis = redis;
|
|
16
|
+
_this.refreshRate = refreshRate;
|
|
17
|
+
_this.onFullQueue = function () { _this.postImpressionCountsInRedis(); };
|
|
18
|
+
return _this;
|
|
19
|
+
}
|
|
20
|
+
ImpressionCountsCacheInRedis.prototype.postImpressionCountsInRedis = function () {
|
|
21
|
+
var _this = this;
|
|
22
|
+
var counts = this.pop();
|
|
23
|
+
var keys = Object.keys(counts);
|
|
24
|
+
if (!keys.length)
|
|
25
|
+
return Promise.resolve(false);
|
|
26
|
+
var pipeline = this.redis.pipeline();
|
|
27
|
+
keys.forEach(function (key) {
|
|
28
|
+
pipeline.hincrby(_this.key, key, counts[key]);
|
|
29
|
+
});
|
|
30
|
+
return pipeline.exec()
|
|
31
|
+
.then(function (data) {
|
|
32
|
+
// If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
|
|
33
|
+
if (data.length && data.length === keys.length) {
|
|
34
|
+
return _this.redis.expire(_this.key, constants_1.TTL_REFRESH);
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
.catch(function (err) {
|
|
38
|
+
_this.log.error(constants_1.LOG_PREFIX + "Error in impression counts pipeline: " + err + ".");
|
|
39
|
+
return false;
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
ImpressionCountsCacheInRedis.prototype.start = function () {
|
|
43
|
+
this.intervalId = setInterval(this.postImpressionCountsInRedis.bind(this), this.refreshRate);
|
|
44
|
+
};
|
|
45
|
+
ImpressionCountsCacheInRedis.prototype.stop = function () {
|
|
46
|
+
clearInterval(this.intervalId);
|
|
47
|
+
return this.postImpressionCountsInRedis();
|
|
48
|
+
};
|
|
49
|
+
// Async consumer API, used by synchronizer
|
|
50
|
+
ImpressionCountsCacheInRedis.prototype.getImpressionsCount = function () {
|
|
51
|
+
var _this = this;
|
|
52
|
+
return this.redis.hgetall(this.key)
|
|
53
|
+
.then(function (counts) {
|
|
54
|
+
if (!Object.keys(counts).length)
|
|
55
|
+
return undefined;
|
|
56
|
+
_this.redis.del(_this.key).catch(function () { });
|
|
57
|
+
var pf = [];
|
|
58
|
+
(0, lang_1.forOwn)(counts, function (count, key) {
|
|
59
|
+
var nameAndTime = key.split('::');
|
|
60
|
+
if (nameAndTime.length !== 2) {
|
|
61
|
+
_this.log.error(constants_1.LOG_PREFIX + "Error spliting key " + key);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var timeFrame = parseInt(nameAndTime[1]);
|
|
65
|
+
if (isNaN(timeFrame)) {
|
|
66
|
+
_this.log.error(constants_1.LOG_PREFIX + "Error parsing time frame " + nameAndTime[1]);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var rawCount = parseInt(count);
|
|
70
|
+
if (isNaN(rawCount)) {
|
|
71
|
+
_this.log.error(constants_1.LOG_PREFIX + "Error parsing raw count " + count);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
pf.push({
|
|
75
|
+
f: nameAndTime[0],
|
|
76
|
+
m: timeFrame,
|
|
77
|
+
rc: rawCount,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
return { pf: pf };
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
return ImpressionCountsCacheInRedis;
|
|
84
|
+
}(ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory));
|
|
85
|
+
exports.ImpressionCountsCacheInRedis = ImpressionCountsCacheInRedis;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImpressionsCacheInRedis = void 0;
|
|
4
|
+
var utils_1 = require("../utils");
|
|
4
5
|
var IMPRESSIONS_TTL_REFRESH = 3600; // 1 hr
|
|
5
6
|
var ImpressionsCacheInRedis = /** @class */ (function () {
|
|
6
7
|
function ImpressionsCacheInRedis(log, key, redis, metadata) {
|
|
@@ -11,31 +12,13 @@ var ImpressionsCacheInRedis = /** @class */ (function () {
|
|
|
11
12
|
}
|
|
12
13
|
ImpressionsCacheInRedis.prototype.track = function (impressions) {
|
|
13
14
|
var _this = this;
|
|
14
|
-
return this.redis.rpush(this.key,
|
|
15
|
+
return this.redis.rpush(this.key, (0, utils_1.impressionsToJSON)(impressions, this.metadata)).then(function (queuedCount) {
|
|
15
16
|
// If this is the creation of the key on Redis, set the expiration for it in 1hr.
|
|
16
17
|
if (queuedCount === impressions.length) {
|
|
17
18
|
return _this.redis.expire(_this.key, IMPRESSIONS_TTL_REFRESH);
|
|
18
19
|
}
|
|
19
20
|
});
|
|
20
21
|
};
|
|
21
|
-
ImpressionsCacheInRedis.prototype._toJSON = function (impressions) {
|
|
22
|
-
var _this = this;
|
|
23
|
-
return impressions.map(function (impression) {
|
|
24
|
-
var keyName = impression.keyName, bucketingKey = impression.bucketingKey, feature = impression.feature, treatment = impression.treatment, label = impression.label, time = impression.time, changeNumber = impression.changeNumber;
|
|
25
|
-
return JSON.stringify({
|
|
26
|
-
m: _this.metadata,
|
|
27
|
-
i: {
|
|
28
|
-
k: keyName,
|
|
29
|
-
b: bucketingKey,
|
|
30
|
-
f: feature,
|
|
31
|
-
t: treatment,
|
|
32
|
-
r: label,
|
|
33
|
-
c: changeNumber,
|
|
34
|
-
m: time
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
22
|
ImpressionsCacheInRedis.prototype.count = function () {
|
|
40
23
|
return this.redis.llen(this.key).catch(function () { return 0; });
|
|
41
24
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TelemetryCacheInRedis = void 0;
|
|
4
|
-
var KeyBuilderSS_1 = require("../KeyBuilderSS");
|
|
5
4
|
var findLatencyIndex_1 = require("../findLatencyIndex");
|
|
6
5
|
var telemetrySubmitter_1 = require("../../sync/submitters/telemetrySubmitter");
|
|
7
6
|
var constants_1 = require("../../utils/constants");
|
|
8
7
|
var lang_1 = require("../../utils/lang");
|
|
9
8
|
var maps_1 = require("../../utils/lang/maps");
|
|
10
9
|
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
10
|
+
var utils_1 = require("../utils");
|
|
11
11
|
var TelemetryCacheInRedis = /** @class */ (function () {
|
|
12
12
|
/**
|
|
13
13
|
* Create a Telemetry cache that uses Redis as storage.
|
|
@@ -44,7 +44,7 @@ var TelemetryCacheInRedis = /** @class */ (function () {
|
|
|
44
44
|
return this.redis.hgetall(this.keys.latencyPrefix).then(function (latencies) {
|
|
45
45
|
var result = new maps_1._Map();
|
|
46
46
|
Object.keys(latencies).forEach(function (field) {
|
|
47
|
-
var parsedField = (0,
|
|
47
|
+
var parsedField = (0, utils_1.parseLatencyField)(field);
|
|
48
48
|
if ((0, lang_1.isString)(parsedField)) {
|
|
49
49
|
_this.log.error("Ignoring invalid latency field: " + field + ": " + parsedField);
|
|
50
50
|
return;
|
|
@@ -81,7 +81,7 @@ var TelemetryCacheInRedis = /** @class */ (function () {
|
|
|
81
81
|
return this.redis.hgetall(this.keys.exceptionPrefix).then(function (exceptions) {
|
|
82
82
|
var result = new maps_1._Map();
|
|
83
83
|
Object.keys(exceptions).forEach(function (field) {
|
|
84
|
-
var parsedField = (0,
|
|
84
|
+
var parsedField = (0, utils_1.parseExceptionField)(field);
|
|
85
85
|
if ((0, lang_1.isString)(parsedField)) {
|
|
86
86
|
_this.log.error("Ignoring invalid exception field: " + field + ": " + parsedField);
|
|
87
87
|
return;
|
|
@@ -114,7 +114,7 @@ var TelemetryCacheInRedis = /** @class */ (function () {
|
|
|
114
114
|
return this.redis.hgetall(this.keys.initPrefix).then(function (configs) {
|
|
115
115
|
var result = new maps_1._Map();
|
|
116
116
|
Object.keys(configs).forEach(function (field) {
|
|
117
|
-
var parsedField = (0,
|
|
117
|
+
var parsedField = (0, utils_1.parseMetadata)(field);
|
|
118
118
|
if ((0, lang_1.isString)(parsedField)) {
|
|
119
119
|
_this.log.error("Ignoring invalid config field: " + field + ": " + parsedField);
|
|
120
120
|
return;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueKeysCacheInRedis = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var UniqueKeysCacheInMemory_1 = require("../inMemory/UniqueKeysCacheInMemory");
|
|
6
|
+
var sets_1 = require("../../utils/lang/sets");
|
|
7
|
+
var constants_1 = require("./constants");
|
|
8
|
+
var constants_2 = require("./constants");
|
|
9
|
+
var UniqueKeysCacheInRedis = /** @class */ (function (_super) {
|
|
10
|
+
(0, tslib_1.__extends)(UniqueKeysCacheInRedis, _super);
|
|
11
|
+
function UniqueKeysCacheInRedis(log, key, redis, uniqueKeysQueueSize, refreshRate) {
|
|
12
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
|
|
13
|
+
if (refreshRate === void 0) { refreshRate = constants_1.REFRESH_RATE; }
|
|
14
|
+
var _this = _super.call(this, uniqueKeysQueueSize) || this;
|
|
15
|
+
_this.log = log;
|
|
16
|
+
_this.key = key;
|
|
17
|
+
_this.redis = redis;
|
|
18
|
+
_this.refreshRate = refreshRate;
|
|
19
|
+
_this.onFullQueue = function () { _this.postUniqueKeysInRedis(); };
|
|
20
|
+
return _this;
|
|
21
|
+
}
|
|
22
|
+
UniqueKeysCacheInRedis.prototype.postUniqueKeysInRedis = function () {
|
|
23
|
+
var _this = this;
|
|
24
|
+
var featureNames = Object.keys(this.uniqueKeysTracker);
|
|
25
|
+
if (!featureNames.length)
|
|
26
|
+
return Promise.resolve(false);
|
|
27
|
+
var pipeline = this.redis.pipeline();
|
|
28
|
+
for (var i = 0; i < featureNames.length; i++) {
|
|
29
|
+
var featureName = featureNames[i];
|
|
30
|
+
var featureKeys = (0, sets_1.setToArray)(this.uniqueKeysTracker[featureName]);
|
|
31
|
+
var uniqueKeysPayload = {
|
|
32
|
+
f: featureName,
|
|
33
|
+
ks: featureKeys
|
|
34
|
+
};
|
|
35
|
+
pipeline.rpush(this.key, JSON.stringify(uniqueKeysPayload));
|
|
36
|
+
}
|
|
37
|
+
this.clear();
|
|
38
|
+
return pipeline.exec()
|
|
39
|
+
.then(function (data) {
|
|
40
|
+
// If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
|
|
41
|
+
if (data.length && data.length === featureNames.length) {
|
|
42
|
+
return _this.redis.expire(_this.key, constants_1.TTL_REFRESH);
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
.catch(function (err) {
|
|
46
|
+
_this.log.error(constants_2.LOG_PREFIX + "Error in uniqueKeys pipeline: " + err + ".");
|
|
47
|
+
return false;
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
UniqueKeysCacheInRedis.prototype.start = function () {
|
|
51
|
+
this.intervalId = setInterval(this.postUniqueKeysInRedis.bind(this), this.refreshRate);
|
|
52
|
+
};
|
|
53
|
+
UniqueKeysCacheInRedis.prototype.stop = function () {
|
|
54
|
+
clearInterval(this.intervalId);
|
|
55
|
+
return this.postUniqueKeysInRedis();
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Async consumer API, used by synchronizer.
|
|
59
|
+
* @param count number of items to pop from the queue. If not provided or equal 0, all items will be popped.
|
|
60
|
+
*/
|
|
61
|
+
UniqueKeysCacheInRedis.prototype.popNRaw = function (count) {
|
|
62
|
+
var _this = this;
|
|
63
|
+
if (count === void 0) { count = 0; }
|
|
64
|
+
return this.redis.lrange(this.key, 0, count - 1).then(function (uniqueKeyItems) {
|
|
65
|
+
return _this.redis.ltrim(_this.key, uniqueKeyItems.length, -1)
|
|
66
|
+
.then(function () { return uniqueKeyItems.map(function (uniqueKeyItem) { return JSON.parse(uniqueKeyItem); }); });
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
return UniqueKeysCacheInRedis;
|
|
70
|
+
}(UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory));
|
|
71
|
+
exports.UniqueKeysCacheInRedis = UniqueKeysCacheInRedis;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LOG_PREFIX = void 0;
|
|
3
|
+
exports.TTL_REFRESH = exports.REFRESH_RATE = exports.DEFAULT_CACHE_SIZE = exports.LOG_PREFIX = void 0;
|
|
4
4
|
exports.LOG_PREFIX = 'storage:redis: ';
|
|
5
|
+
exports.DEFAULT_CACHE_SIZE = 30000;
|
|
6
|
+
exports.REFRESH_RATE = 300000; // 300.000 ms = start after 5 mins
|
|
7
|
+
exports.TTL_REFRESH = 3600; // 1hr
|
|
@@ -10,6 +10,9 @@ var ImpressionsCacheInRedis_1 = require("./ImpressionsCacheInRedis");
|
|
|
10
10
|
var EventsCacheInRedis_1 = require("./EventsCacheInRedis");
|
|
11
11
|
var constants_1 = require("../../utils/constants");
|
|
12
12
|
var TelemetryCacheInRedis_1 = require("./TelemetryCacheInRedis");
|
|
13
|
+
var UniqueKeysCacheInRedis_1 = require("./UniqueKeysCacheInRedis");
|
|
14
|
+
var ImpressionCountsCacheInRedis_1 = require("./ImpressionCountsCacheInRedis");
|
|
15
|
+
var utils_1 = require("../utils");
|
|
13
16
|
/**
|
|
14
17
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
15
18
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
@@ -17,14 +20,21 @@ var TelemetryCacheInRedis_1 = require("./TelemetryCacheInRedis");
|
|
|
17
20
|
function InRedisStorage(options) {
|
|
18
21
|
if (options === void 0) { options = {}; }
|
|
19
22
|
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
20
|
-
function InRedisStorageFactory(
|
|
21
|
-
var
|
|
23
|
+
function InRedisStorageFactory(params) {
|
|
24
|
+
var onReadyCb = params.onReadyCb, settings = params.settings, _a = params.settings, log = _a.log, impressionsMode = _a.sync.impressionsMode;
|
|
25
|
+
var metadata = (0, utils_1.metadataBuilder)(settings);
|
|
22
26
|
var keys = new KeyBuilderSS_1.KeyBuilderSS(prefix, metadata);
|
|
23
27
|
var redisClient = new RedisAdapter_1.RedisAdapter(log, options.options || {});
|
|
24
28
|
var telemetry = new TelemetryCacheInRedis_1.TelemetryCacheInRedis(log, keys, redisClient);
|
|
29
|
+
var impressionCountsCache = impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInRedis_1.ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient) : undefined;
|
|
30
|
+
var uniqueKeysCache = impressionsMode === constants_1.NONE ? new UniqueKeysCacheInRedis_1.UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient) : undefined;
|
|
25
31
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
26
32
|
redisClient.on('connect', function () {
|
|
27
33
|
onReadyCb();
|
|
34
|
+
if (impressionCountsCache)
|
|
35
|
+
impressionCountsCache.start();
|
|
36
|
+
if (uniqueKeysCache)
|
|
37
|
+
uniqueKeysCache.start();
|
|
28
38
|
// Synchronize config
|
|
29
39
|
telemetry.recordConfig();
|
|
30
40
|
});
|
|
@@ -32,12 +42,19 @@ function InRedisStorage(options) {
|
|
|
32
42
|
splits: new SplitsCacheInRedis_1.SplitsCacheInRedis(log, keys, redisClient),
|
|
33
43
|
segments: new SegmentsCacheInRedis_1.SegmentsCacheInRedis(log, keys, redisClient),
|
|
34
44
|
impressions: new ImpressionsCacheInRedis_1.ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
45
|
+
impressionCounts: impressionCountsCache,
|
|
35
46
|
events: new EventsCacheInRedis_1.EventsCacheInRedis(log, keys.buildEventsKey(), redisClient, metadata),
|
|
36
47
|
telemetry: telemetry,
|
|
48
|
+
uniqueKeys: uniqueKeysCache,
|
|
37
49
|
// When using REDIS we should:
|
|
38
50
|
// 1- Disconnect from the storage
|
|
39
51
|
destroy: function () {
|
|
40
|
-
|
|
52
|
+
var promises = [];
|
|
53
|
+
if (impressionCountsCache)
|
|
54
|
+
promises.push(impressionCountsCache.stop());
|
|
55
|
+
if (uniqueKeysCache)
|
|
56
|
+
promises.push(uniqueKeysCache.stop());
|
|
57
|
+
return Promise.all(promises).then(function () { redisClient.disconnect(); });
|
|
41
58
|
// @TODO check that caches works as expected when redisClient is disconnected
|
|
42
59
|
}
|
|
43
60
|
};
|