@splitsoftware/splitio-commons 1.6.2-rc.8 → 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 +4 -1
- package/cjs/evaluator/index.js +5 -5
- package/cjs/listeners/browser.js +9 -11
- package/cjs/sdkClient/client.js +19 -7
- package/cjs/sdkFactory/index.js +7 -25
- package/cjs/services/splitApi.js +4 -4
- package/cjs/storages/AbstractSplitsCacheAsync.js +1 -1
- package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
- package/cjs/storages/KeyBuilderSS.js +9 -9
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -1
- package/cjs/storages/inLocalStorage/index.js +15 -11
- package/cjs/storages/inMemory/InMemoryStorage.js +11 -8
- package/cjs/storages/inMemory/InMemoryStorageCS.js +11 -8
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +65 -37
- package/cjs/storages/inMemory/{uniqueKeysCacheInMemory.js → UniqueKeysCacheInMemory.js} +24 -25
- package/cjs/storages/inMemory/{uniqueKeysCacheInMemoryCS.js → UniqueKeysCacheInMemoryCS.js} +10 -12
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +37 -2
- package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/cjs/storages/inRedis/{uniqueKeysCacheInRedis.js → UniqueKeysCacheInRedis.js} +16 -4
- package/cjs/storages/inRedis/index.js +6 -4
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +81 -0
- package/cjs/storages/pluggable/ImpressionsCachePluggable.js +2 -19
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +61 -0
- package/cjs/storages/pluggable/inMemoryWrapper.js +8 -6
- package/cjs/storages/pluggable/index.js +51 -18
- package/cjs/storages/utils.js +73 -0
- package/cjs/sync/submitters/submitterManager.js +1 -1
- package/cjs/sync/submitters/telemetrySubmitter.js +4 -37
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +4 -3
- package/cjs/trackers/impressionObserver/utils.js +1 -17
- package/cjs/trackers/uniqueKeysTracker.js +1 -1
- package/cjs/utils/lang/maps.js +15 -7
- package/cjs/utils/redis/RedisMock.js +31 -0
- package/cjs/utils/settingsValidation/index.js +7 -4
- package/esm/evaluator/index.js +5 -5
- package/esm/listeners/browser.js +9 -11
- package/esm/sdkClient/client.js +19 -7
- package/esm/sdkFactory/index.js +7 -25
- package/esm/services/splitApi.js +4 -4
- package/esm/storages/AbstractSplitsCacheAsync.js +1 -1
- package/esm/storages/AbstractSplitsCacheSync.js +1 -1
- package/esm/storages/KeyBuilderSS.js +8 -8
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -1
- package/esm/storages/inLocalStorage/index.js +16 -12
- package/esm/storages/inMemory/InMemoryStorage.js +13 -10
- package/esm/storages/inMemory/InMemoryStorageCS.js +12 -9
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +64 -37
- package/esm/storages/inMemory/{uniqueKeysCacheInMemory.js → UniqueKeysCacheInMemory.js} +22 -24
- package/esm/storages/inMemory/{uniqueKeysCacheInMemoryCS.js → UniqueKeysCacheInMemoryCS.js} +10 -12
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +37 -2
- package/esm/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/esm/storages/inRedis/{uniqueKeysCacheInRedis.js → UniqueKeysCacheInRedis.js} +15 -3
- package/esm/storages/inRedis/index.js +5 -3
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +78 -0
- package/esm/storages/pluggable/ImpressionsCachePluggable.js +2 -19
- package/esm/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +58 -0
- package/esm/storages/pluggable/inMemoryWrapper.js +8 -6
- package/esm/storages/pluggable/index.js +52 -19
- package/esm/storages/utils.js +65 -0
- package/esm/sync/submitters/submitterManager.js +1 -1
- package/esm/sync/submitters/telemetrySubmitter.js +4 -36
- package/esm/sync/submitters/uniqueKeysSubmitter.js +4 -3
- package/esm/trackers/impressionObserver/utils.js +1 -15
- package/esm/trackers/uniqueKeysTracker.js +1 -1
- package/esm/utils/lang/maps.js +15 -7
- package/esm/utils/redis/RedisMock.js +28 -0
- package/esm/utils/settingsValidation/index.js +7 -4
- package/package.json +2 -2
- package/src/consent/sdkUserConsent.ts +1 -1
- package/src/evaluator/index.ts +6 -6
- package/src/listeners/browser.ts +9 -13
- package/src/logger/.DS_Store +0 -0
- package/src/sdkClient/client.ts +21 -8
- package/src/sdkClient/sdkClient.ts +1 -1
- package/src/sdkFactory/index.ts +10 -33
- package/src/sdkFactory/types.ts +2 -2
- package/src/services/splitApi.ts +6 -6
- package/src/services/types.ts +2 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +1 -1
- package/src/storages/AbstractSplitsCacheSync.ts +1 -1
- package/src/storages/KeyBuilderSS.ts +13 -11
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +0 -1
- package/src/storages/inLocalStorage/index.ts +17 -12
- package/src/storages/inMemory/AttributesCacheInMemory.ts +7 -7
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +2 -2
- package/src/storages/inMemory/InMemoryStorage.ts +14 -10
- package/src/storages/inMemory/InMemoryStorageCS.ts +13 -10
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +72 -35
- package/src/storages/inMemory/{uniqueKeysCacheInMemory.ts → UniqueKeysCacheInMemory.ts} +26 -28
- package/src/storages/inMemory/{uniqueKeysCacheInMemoryCS.ts → UniqueKeysCacheInMemoryCS.ts} +15 -17
- package/src/storages/inRedis/EventsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +51 -8
- package/src/storages/inRedis/ImpressionsCacheInRedis.ts +2 -22
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +122 -1
- package/src/storages/inRedis/{uniqueKeysCacheInRedis.ts → UniqueKeysCacheInRedis.ts} +25 -12
- package/src/storages/inRedis/index.ts +6 -3
- package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +92 -0
- package/src/storages/pluggable/ImpressionsCachePluggable.ts +3 -23
- package/src/storages/pluggable/TelemetryCachePluggable.ts +147 -1
- package/src/storages/pluggable/UniqueKeysCachePluggable.ts +67 -0
- package/src/storages/pluggable/inMemoryWrapper.ts +6 -6
- package/src/storages/pluggable/index.ts +56 -20
- package/src/storages/types.ts +53 -70
- package/src/storages/utils.ts +78 -0
- package/src/sync/submitters/submitter.ts +2 -2
- package/src/sync/submitters/submitterManager.ts +1 -1
- package/src/sync/submitters/telemetrySubmitter.ts +9 -39
- package/src/sync/submitters/types.ts +33 -17
- package/src/sync/submitters/uniqueKeysSubmitter.ts +6 -5
- package/src/trackers/impressionObserver/utils.ts +1 -16
- package/src/trackers/impressionsTracker.ts +2 -2
- package/src/trackers/strategy/strategyDebug.ts +4 -4
- package/src/trackers/strategy/strategyNone.ts +9 -9
- package/src/trackers/strategy/strategyOptimized.ts +9 -9
- package/src/trackers/uniqueKeysTracker.ts +6 -6
- package/src/types.ts +0 -2
- package/src/utils/lang/maps.ts +20 -8
- package/src/utils/redis/RedisMock.ts +33 -0
- package/src/utils/settingsValidation/index.ts +5 -5
- package/types/services/types.d.ts +2 -2
- package/types/storages/AbstractSplitsCacheAsync.d.ts +1 -1
- package/types/storages/AbstractSplitsCacheSync.d.ts +1 -1
- package/types/storages/KeyBuilderSS.d.ts +5 -2
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +0 -1
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +23 -9
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +9 -9
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +2 -4
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +3 -1
- package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +0 -1
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +16 -1
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +8 -2
- package/types/storages/pluggable/ImpressionCountsCachePluggable.d.ts +16 -0
- package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +1 -2
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +17 -1
- package/types/storages/pluggable/UniqueKeysCachePluggable.d.ts +20 -0
- package/types/storages/types.d.ts +42 -49
- 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 -18
- package/types/trackers/impressionObserver/utils.d.ts +0 -8
- package/types/trackers/strategy/strategyNone.d.ts +2 -2
- package/types/trackers/strategy/strategyOptimized.d.ts +2 -2
- package/types/trackers/uniqueKeysTracker.d.ts +1 -1
- package/types/types.d.ts +0 -2
- 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/cjs/storages/metadataBuilder.js +0 -12
- package/esm/storages/metadataBuilder.js +0 -8
- package/src/storages/metadataBuilder.ts +0 -11
- 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/impressionCountsSubmitterInRedis.d.ts +0 -5
- 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/submitters/uniqueKeysSubmitterInRedis.d.ts +0 -5
- 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
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TelemetryCachePluggable = void 0;
|
|
4
4
|
var findLatencyIndex_1 = require("../findLatencyIndex");
|
|
5
|
+
var telemetrySubmitter_1 = require("../../sync/submitters/telemetrySubmitter");
|
|
6
|
+
var constants_1 = require("../../utils/constants");
|
|
7
|
+
var lang_1 = require("../../utils/lang");
|
|
8
|
+
var maps_1 = require("../../utils/lang/maps");
|
|
9
|
+
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
10
|
+
var utils_1 = require("../utils");
|
|
5
11
|
var TelemetryCachePluggable = /** @class */ (function () {
|
|
6
12
|
/**
|
|
7
13
|
* Create a Telemetry cache that uses a storage wrapper.
|
|
@@ -22,6 +28,126 @@ var TelemetryCachePluggable = /** @class */ (function () {
|
|
|
22
28
|
return this.wrapper.incr(this.keys.buildExceptionKey(method))
|
|
23
29
|
.catch(function () { });
|
|
24
30
|
};
|
|
31
|
+
TelemetryCachePluggable.prototype.recordConfig = function () {
|
|
32
|
+
var value = JSON.stringify((0, telemetrySubmitter_1.getTelemetryConfigStats)(constants_1.CONSUMER_MODE, constants_1.STORAGE_PLUGGABLE));
|
|
33
|
+
return this.wrapper.set(this.keys.buildInitKey(), value).catch(function () { });
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Pop telemetry latencies.
|
|
37
|
+
* The returned promise rejects if wrapper operations fail.
|
|
38
|
+
*/
|
|
39
|
+
TelemetryCachePluggable.prototype.popLatencies = function () {
|
|
40
|
+
var _this = this;
|
|
41
|
+
return this.wrapper.getKeysByPrefix(this.keys.latencyPrefix).then(function (latencyKeys) {
|
|
42
|
+
return latencyKeys.length ?
|
|
43
|
+
_this.wrapper.getMany(latencyKeys).then(function (latencies) {
|
|
44
|
+
var result = new maps_1._Map();
|
|
45
|
+
for (var i = 0; i < latencyKeys.length; i++) {
|
|
46
|
+
var field = latencyKeys[i].split('::')[1];
|
|
47
|
+
var parsedField = (0, utils_1.parseLatencyField)(field);
|
|
48
|
+
if ((0, lang_1.isString)(parsedField)) {
|
|
49
|
+
_this.log.error("Ignoring invalid latency field: " + field + ": " + parsedField);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
var count = parseInt(latencies[i]);
|
|
54
|
+
if ((0, lang_1.isNaNNumber)(count)) {
|
|
55
|
+
_this.log.error("Ignoring latency with invalid count: " + latencies[i]);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
var metadata = parsedField[0], method = parsedField[1], bucket = parsedField[2];
|
|
59
|
+
if (bucket >= TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT) {
|
|
60
|
+
_this.log.error("Ignoring latency with invalid bucket: " + bucket);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!result.has(metadata))
|
|
64
|
+
result.set(metadata, {
|
|
65
|
+
t: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
66
|
+
ts: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
67
|
+
tc: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
68
|
+
tcs: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
69
|
+
tr: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
70
|
+
});
|
|
71
|
+
result.get(metadata)[method][bucket] = count;
|
|
72
|
+
}
|
|
73
|
+
return Promise.all(latencyKeys.map(function (latencyKey) { return _this.wrapper.del(latencyKey); })).then(function () { return result; });
|
|
74
|
+
}) :
|
|
75
|
+
// If latencyKeys is empty, return an empty map.
|
|
76
|
+
new maps_1._Map();
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Pop telemetry exceptions.
|
|
81
|
+
* The returned promise rejects if wrapper operations fail.
|
|
82
|
+
*/
|
|
83
|
+
TelemetryCachePluggable.prototype.popExceptions = function () {
|
|
84
|
+
var _this = this;
|
|
85
|
+
return this.wrapper.getKeysByPrefix(this.keys.exceptionPrefix).then(function (exceptionKeys) {
|
|
86
|
+
return exceptionKeys.length ?
|
|
87
|
+
_this.wrapper.getMany(exceptionKeys).then(function (exceptions) {
|
|
88
|
+
var result = new maps_1._Map();
|
|
89
|
+
for (var i = 0; i < exceptionKeys.length; i++) {
|
|
90
|
+
var field = exceptionKeys[i].split('::')[1];
|
|
91
|
+
var parsedField = (0, utils_1.parseExceptionField)(field);
|
|
92
|
+
if ((0, lang_1.isString)(parsedField)) {
|
|
93
|
+
_this.log.error("Ignoring invalid exception field: " + field + ": " + parsedField);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
var count = parseInt(exceptions[i]);
|
|
98
|
+
if ((0, lang_1.isNaNNumber)(count)) {
|
|
99
|
+
_this.log.error("Ignoring exception with invalid count: " + exceptions[i]);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
var metadata = parsedField[0], method = parsedField[1];
|
|
103
|
+
if (!result.has(metadata))
|
|
104
|
+
result.set(metadata, {
|
|
105
|
+
t: 0,
|
|
106
|
+
ts: 0,
|
|
107
|
+
tc: 0,
|
|
108
|
+
tcs: 0,
|
|
109
|
+
tr: 0,
|
|
110
|
+
});
|
|
111
|
+
result.get(metadata)[method] = count;
|
|
112
|
+
}
|
|
113
|
+
return Promise.all(exceptionKeys.map(function (exceptionKey) { return _this.wrapper.del(exceptionKey); })).then(function () { return result; });
|
|
114
|
+
}) :
|
|
115
|
+
// If exceptionKeys is empty, return an empty map.
|
|
116
|
+
new maps_1._Map();
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Pop telemetry configs.
|
|
121
|
+
* The returned promise rejects if wrapper operations fail.
|
|
122
|
+
*/
|
|
123
|
+
TelemetryCachePluggable.prototype.popConfigs = function () {
|
|
124
|
+
var _this = this;
|
|
125
|
+
return this.wrapper.getKeysByPrefix(this.keys.initPrefix).then(function (configKeys) {
|
|
126
|
+
return configKeys.length ?
|
|
127
|
+
_this.wrapper.getMany(configKeys).then(function (configs) {
|
|
128
|
+
var result = new maps_1._Map();
|
|
129
|
+
for (var i = 0; i < configKeys.length; i++) {
|
|
130
|
+
var field = configKeys[i].split('::')[1];
|
|
131
|
+
var parsedField = (0, utils_1.parseMetadata)(field);
|
|
132
|
+
if ((0, lang_1.isString)(parsedField)) {
|
|
133
|
+
_this.log.error("Ignoring invalid config field: " + field + ": " + parsedField);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
var metadata = parsedField[0];
|
|
137
|
+
try { // @ts-ignore
|
|
138
|
+
var config = JSON.parse(configs[i]);
|
|
139
|
+
result.set(metadata, config);
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
_this.log.error("Ignoring invalid config: " + configs[i]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return Promise.all(configKeys.map(function (configKey) { return _this.wrapper.del(configKey); })).then(function () { return result; });
|
|
146
|
+
}) :
|
|
147
|
+
// If configKeys is empty, return an empty map.
|
|
148
|
+
new maps_1._Map();
|
|
149
|
+
});
|
|
150
|
+
};
|
|
25
151
|
return TelemetryCachePluggable;
|
|
26
152
|
}());
|
|
27
153
|
exports.TelemetryCachePluggable = TelemetryCachePluggable;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueKeysCachePluggable = 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("../inRedis/constants");
|
|
8
|
+
var constants_2 = require("./constants");
|
|
9
|
+
var UniqueKeysCachePluggable = /** @class */ (function (_super) {
|
|
10
|
+
(0, tslib_1.__extends)(UniqueKeysCachePluggable, _super);
|
|
11
|
+
function UniqueKeysCachePluggable(log, key, wrapper, 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.wrapper = wrapper;
|
|
18
|
+
_this.refreshRate = refreshRate;
|
|
19
|
+
_this.onFullQueue = function () { _this.storeUniqueKeys(); };
|
|
20
|
+
return _this;
|
|
21
|
+
}
|
|
22
|
+
UniqueKeysCachePluggable.prototype.storeUniqueKeys = function () {
|
|
23
|
+
var _this = this;
|
|
24
|
+
var featureNames = Object.keys(this.uniqueKeysTracker);
|
|
25
|
+
if (!featureNames.length)
|
|
26
|
+
return Promise.resolve(false);
|
|
27
|
+
var pipeline = featureNames.reduce(function (pipeline, featureName) {
|
|
28
|
+
var featureKeys = (0, sets_1.setToArray)(_this.uniqueKeysTracker[featureName]);
|
|
29
|
+
var uniqueKeysPayload = {
|
|
30
|
+
f: featureName,
|
|
31
|
+
ks: featureKeys
|
|
32
|
+
};
|
|
33
|
+
return pipeline.then(function () { return _this.wrapper.pushItems(_this.key, [JSON.stringify(uniqueKeysPayload)]); });
|
|
34
|
+
}, Promise.resolve());
|
|
35
|
+
this.clear();
|
|
36
|
+
return pipeline.catch(function (err) {
|
|
37
|
+
_this.log.error(constants_2.LOG_PREFIX + "Error in uniqueKeys pipeline: " + err + ".");
|
|
38
|
+
return false;
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
UniqueKeysCachePluggable.prototype.start = function () {
|
|
42
|
+
this.intervalId = setInterval(this.storeUniqueKeys.bind(this), this.refreshRate);
|
|
43
|
+
};
|
|
44
|
+
UniqueKeysCachePluggable.prototype.stop = function () {
|
|
45
|
+
clearInterval(this.intervalId);
|
|
46
|
+
return this.storeUniqueKeys();
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Async consumer API, used by synchronizer.
|
|
50
|
+
* @param count number of items to pop from the queue. If not provided or equal 0, all items will be popped.
|
|
51
|
+
*/
|
|
52
|
+
UniqueKeysCachePluggable.prototype.popNRaw = function (count) {
|
|
53
|
+
var _this = this;
|
|
54
|
+
if (count === void 0) { count = 0; }
|
|
55
|
+
return Promise.resolve(count || this.wrapper.getItemsCount(this.key))
|
|
56
|
+
.then(function (count) { return _this.wrapper.popItems(_this.key, count); })
|
|
57
|
+
.then(function (uniqueKeyItems) { return uniqueKeyItems.map(function (uniqueKeyItem) { return JSON.parse(uniqueKeyItem); }); });
|
|
58
|
+
};
|
|
59
|
+
return UniqueKeysCachePluggable;
|
|
60
|
+
}(UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory));
|
|
61
|
+
exports.UniqueKeysCachePluggable = UniqueKeysCachePluggable;
|
|
@@ -37,29 +37,31 @@ function inMemoryWrapperFactory(connDelay) {
|
|
|
37
37
|
getKeysByPrefix: function (prefix) {
|
|
38
38
|
return Promise.resolve(Object.keys(_cache).filter(function (key) { return (0, lang_1.startsWith)(key, prefix); }));
|
|
39
39
|
},
|
|
40
|
-
incr: function (key) {
|
|
40
|
+
incr: function (key, increment) {
|
|
41
|
+
if (increment === void 0) { increment = 1; }
|
|
41
42
|
if (key in _cache) {
|
|
42
|
-
var count = (0, lang_1.toNumber)(_cache[key]) +
|
|
43
|
+
var count = (0, lang_1.toNumber)(_cache[key]) + increment;
|
|
43
44
|
if (isNaN(count))
|
|
44
45
|
return Promise.reject('Given key is not a number');
|
|
45
46
|
_cache[key] = count + '';
|
|
46
47
|
return Promise.resolve(count);
|
|
47
48
|
}
|
|
48
49
|
else {
|
|
49
|
-
_cache[key] = '
|
|
50
|
+
_cache[key] = '' + increment;
|
|
50
51
|
return Promise.resolve(1);
|
|
51
52
|
}
|
|
52
53
|
},
|
|
53
|
-
decr: function (key) {
|
|
54
|
+
decr: function (key, decrement) {
|
|
55
|
+
if (decrement === void 0) { decrement = 1; }
|
|
54
56
|
if (key in _cache) {
|
|
55
|
-
var count = (0, lang_1.toNumber)(_cache[key]) -
|
|
57
|
+
var count = (0, lang_1.toNumber)(_cache[key]) - decrement;
|
|
56
58
|
if (isNaN(count))
|
|
57
59
|
return Promise.reject('Given key is not a number');
|
|
58
60
|
_cache[key] = count + '';
|
|
59
61
|
return Promise.resolve(count);
|
|
60
62
|
}
|
|
61
63
|
else {
|
|
62
|
-
_cache[key] = '-
|
|
64
|
+
_cache[key] = '-' + decrement;
|
|
63
65
|
return Promise.resolve(-1);
|
|
64
66
|
}
|
|
65
67
|
},
|
|
@@ -14,6 +14,13 @@ var constants_1 = require("../../utils/constants");
|
|
|
14
14
|
var ImpressionsCacheInMemory_1 = require("../inMemory/ImpressionsCacheInMemory");
|
|
15
15
|
var EventsCacheInMemory_1 = require("../inMemory/EventsCacheInMemory");
|
|
16
16
|
var ImpressionCountsCacheInMemory_1 = require("../inMemory/ImpressionCountsCacheInMemory");
|
|
17
|
+
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
18
|
+
var TelemetryCachePluggable_1 = require("./TelemetryCachePluggable");
|
|
19
|
+
var ImpressionCountsCachePluggable_1 = require("./ImpressionCountsCachePluggable");
|
|
20
|
+
var UniqueKeysCachePluggable_1 = require("./UniqueKeysCachePluggable");
|
|
21
|
+
var UniqueKeysCacheInMemory_1 = require("../inMemory/UniqueKeysCacheInMemory");
|
|
22
|
+
var UniqueKeysCacheInMemoryCS_1 = require("../inMemory/UniqueKeysCacheInMemoryCS");
|
|
23
|
+
var utils_1 = require("../utils");
|
|
17
24
|
var NO_VALID_WRAPPER = 'Expecting pluggable storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
18
25
|
var NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
19
26
|
/**
|
|
@@ -30,15 +37,6 @@ function validatePluggableStorageOptions(options) {
|
|
|
30
37
|
if (missingMethods.length)
|
|
31
38
|
throw new Error(NO_VALID_WRAPPER_INTERFACE + " The following methods are missing or invalid: " + missingMethods);
|
|
32
39
|
}
|
|
33
|
-
// subscription to wrapper connect event in order to emit SDK_READY event
|
|
34
|
-
function wrapperConnect(wrapper, onReadyCb) {
|
|
35
|
-
wrapper.connect().then(function () {
|
|
36
|
-
onReadyCb();
|
|
37
|
-
// At the moment, we don't synchronize config with pluggable storage
|
|
38
|
-
}).catch(function (e) {
|
|
39
|
-
onReadyCb(e || new Error('Error connecting wrapper'));
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
40
|
// Async return type in `client.track` method on consumer partial mode
|
|
43
41
|
// No need to promisify impressions cache
|
|
44
42
|
function promisifyEventsTrack(events) {
|
|
@@ -54,28 +52,63 @@ function promisifyEventsTrack(events) {
|
|
|
54
52
|
function PluggableStorage(options) {
|
|
55
53
|
validatePluggableStorageOptions(options);
|
|
56
54
|
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
57
|
-
function PluggableStorageFactory(
|
|
58
|
-
var
|
|
55
|
+
function PluggableStorageFactory(params) {
|
|
56
|
+
var onReadyCb = params.onReadyCb, settings = params.settings, _a = params.settings, log = _a.log, mode = _a.mode, impressionsMode = _a.sync.impressionsMode, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize;
|
|
57
|
+
var metadata = (0, utils_1.metadataBuilder)(settings);
|
|
59
58
|
var keys = new KeyBuilderSS_1.KeyBuilderSS(prefix, metadata);
|
|
60
59
|
var wrapper = (0, wrapperAdapter_1.wrapperAdapter)(log, options.wrapper);
|
|
60
|
+
var isSyncronizer = mode === undefined; // If mode is not defined, the synchronizer is running
|
|
61
61
|
var isPartialConsumer = mode === constants_1.CONSUMER_PARTIAL_MODE;
|
|
62
|
+
var telemetry = (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) || isSyncronizer ?
|
|
63
|
+
isPartialConsumer ?
|
|
64
|
+
new TelemetryCacheInMemory_1.TelemetryCacheInMemory() :
|
|
65
|
+
new TelemetryCachePluggable_1.TelemetryCachePluggable(log, keys, wrapper) :
|
|
66
|
+
undefined;
|
|
67
|
+
var impressionCountsCache = impressionsMode !== constants_1.DEBUG || isSyncronizer ?
|
|
68
|
+
isPartialConsumer ?
|
|
69
|
+
new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() :
|
|
70
|
+
new ImpressionCountsCachePluggable_1.ImpressionCountsCachePluggable(log, keys.buildImpressionsCountKey(), wrapper) :
|
|
71
|
+
undefined;
|
|
72
|
+
var uniqueKeysCache = impressionsMode === constants_1.NONE || isSyncronizer ?
|
|
73
|
+
isPartialConsumer ?
|
|
74
|
+
settings.core.key === undefined ? new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory() : new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() :
|
|
75
|
+
new UniqueKeysCachePluggable_1.UniqueKeysCachePluggable(log, keys.buildUniqueKeysKey(), wrapper) :
|
|
76
|
+
undefined;
|
|
62
77
|
// Connects to wrapper and emits SDK_READY event on main client
|
|
63
|
-
|
|
78
|
+
var connectPromise = wrapper.connect().then(function () {
|
|
79
|
+
onReadyCb();
|
|
80
|
+
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
81
|
+
if (!isSyncronizer) {
|
|
82
|
+
if (impressionCountsCache && impressionCountsCache.start)
|
|
83
|
+
impressionCountsCache.start();
|
|
84
|
+
if (uniqueKeysCache && uniqueKeysCache.start)
|
|
85
|
+
uniqueKeysCache.start();
|
|
86
|
+
if (telemetry && telemetry.recordConfig)
|
|
87
|
+
telemetry.recordConfig();
|
|
88
|
+
}
|
|
89
|
+
}).catch(function (e) {
|
|
90
|
+
e = e || new Error('Error connecting wrapper');
|
|
91
|
+
onReadyCb(e);
|
|
92
|
+
return e;
|
|
93
|
+
});
|
|
64
94
|
return {
|
|
65
95
|
splits: new SplitsCachePluggable_1.SplitsCachePluggable(log, keys, wrapper),
|
|
66
96
|
segments: new SegmentsCachePluggable_1.SegmentsCachePluggable(log, keys, wrapper),
|
|
67
97
|
impressions: isPartialConsumer ? new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable_1.ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
68
|
-
impressionCounts:
|
|
98
|
+
impressionCounts: impressionCountsCache,
|
|
69
99
|
events: isPartialConsumer ? promisifyEventsTrack(new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize)) : new EventsCachePluggable_1.EventsCachePluggable(log, keys.buildEventsKey(), wrapper, metadata),
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
//
|
|
100
|
+
telemetry: telemetry,
|
|
101
|
+
uniqueKeys: uniqueKeysCache,
|
|
102
|
+
// Stop periodic flush and disconnect the underlying storage
|
|
73
103
|
destroy: function () {
|
|
74
|
-
return
|
|
104
|
+
return Promise.all(isSyncronizer ? [] : [
|
|
105
|
+
impressionCountsCache && impressionCountsCache.stop && impressionCountsCache.stop(),
|
|
106
|
+
uniqueKeysCache && uniqueKeysCache.stop && uniqueKeysCache.stop(),
|
|
107
|
+
]).then(function () { return wrapper.disconnect(); });
|
|
75
108
|
},
|
|
76
109
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
77
110
|
shared: function (_, onReadyCb) {
|
|
78
|
-
|
|
111
|
+
connectPromise.then(onReadyCb);
|
|
79
112
|
return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, this), {
|
|
80
113
|
// no-op destroy, to disconnect the wrapper only when the main client is destroyed
|
|
81
114
|
destroy: function () { } });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Shared utils for Redis and Pluggable storage
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.parseLatencyField = exports.parseExceptionField = exports.parseMetadata = exports.impressionsToJSON = exports.metadataBuilder = void 0;
|
|
5
|
+
var constants_1 = require("../utils/constants");
|
|
6
|
+
var TelemetryCacheInMemory_1 = require("./inMemory/TelemetryCacheInMemory");
|
|
7
|
+
var KeyBuilderSS_1 = require("./KeyBuilderSS");
|
|
8
|
+
function metadataBuilder(settings) {
|
|
9
|
+
return {
|
|
10
|
+
s: settings.version,
|
|
11
|
+
i: settings.runtime.ip || constants_1.UNKNOWN,
|
|
12
|
+
n: settings.runtime.hostname || constants_1.UNKNOWN,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.metadataBuilder = metadataBuilder;
|
|
16
|
+
// Converts impressions to be stored in Redis or pluggable storage.
|
|
17
|
+
function impressionsToJSON(impressions, metadata) {
|
|
18
|
+
return impressions.map(function (impression) {
|
|
19
|
+
var impressionWithMetadata = {
|
|
20
|
+
m: metadata,
|
|
21
|
+
i: {
|
|
22
|
+
k: impression.keyName,
|
|
23
|
+
b: impression.bucketingKey,
|
|
24
|
+
f: impression.feature,
|
|
25
|
+
t: impression.treatment,
|
|
26
|
+
r: impression.label,
|
|
27
|
+
c: impression.changeNumber,
|
|
28
|
+
m: impression.time,
|
|
29
|
+
pt: impression.pt,
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return JSON.stringify(impressionWithMetadata);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.impressionsToJSON = impressionsToJSON;
|
|
36
|
+
// Utilities used by TelemetryCacheInRedis and TelemetryCachePluggable
|
|
37
|
+
var REVERSE_METHOD_NAMES = Object.keys(KeyBuilderSS_1.METHOD_NAMES).reduce(function (acc, key) {
|
|
38
|
+
acc[KeyBuilderSS_1.METHOD_NAMES[key]] = key;
|
|
39
|
+
return acc;
|
|
40
|
+
}, {});
|
|
41
|
+
function parseMetadata(field) {
|
|
42
|
+
var parts = field.split('/');
|
|
43
|
+
if (parts.length !== 3)
|
|
44
|
+
return "invalid subsection count. Expected 3, got: " + parts.length;
|
|
45
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */;
|
|
46
|
+
return [JSON.stringify({ s: s, n: n, i: i })];
|
|
47
|
+
}
|
|
48
|
+
exports.parseMetadata = parseMetadata;
|
|
49
|
+
function parseExceptionField(field) {
|
|
50
|
+
var parts = field.split('/');
|
|
51
|
+
if (parts.length !== 4)
|
|
52
|
+
return "invalid subsection count. Expected 4, got: " + parts.length;
|
|
53
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3];
|
|
54
|
+
var method = REVERSE_METHOD_NAMES[m];
|
|
55
|
+
if (!method)
|
|
56
|
+
return "unknown method '" + m + "'";
|
|
57
|
+
return [JSON.stringify({ s: s, n: n, i: i }), method];
|
|
58
|
+
}
|
|
59
|
+
exports.parseExceptionField = parseExceptionField;
|
|
60
|
+
function parseLatencyField(field) {
|
|
61
|
+
var parts = field.split('/');
|
|
62
|
+
if (parts.length !== 5)
|
|
63
|
+
return "invalid subsection count. Expected 5, got: " + parts.length;
|
|
64
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3], b = parts[4];
|
|
65
|
+
var method = REVERSE_METHOD_NAMES[m];
|
|
66
|
+
if (!method)
|
|
67
|
+
return "unknown method '" + m + "'";
|
|
68
|
+
var bucket = parseInt(b);
|
|
69
|
+
if (isNaN(bucket) || bucket >= TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT)
|
|
70
|
+
return "invalid bucket. Expected a number between 0 and " + (TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT - 1) + ", got: " + b;
|
|
71
|
+
return [JSON.stringify({ s: s, n: n, i: i }), method, bucket];
|
|
72
|
+
}
|
|
73
|
+
exports.parseLatencyField = parseLatencyField;
|
|
@@ -15,7 +15,7 @@ function submitterManagerFactory(params) {
|
|
|
15
15
|
if (impressionCountsSubmitter)
|
|
16
16
|
submitters.push(impressionCountsSubmitter);
|
|
17
17
|
var telemetrySubmitter = (0, telemetrySubmitter_1.telemetrySubmitterFactory)(params);
|
|
18
|
-
if (params.
|
|
18
|
+
if (params.storage.uniqueKeys)
|
|
19
19
|
submitters.push((0, uniqueKeysSubmitter_1.uniqueKeysSubmitterFactory)(params));
|
|
20
20
|
return {
|
|
21
21
|
// `onlyTelemetry` true if SDK is created with userConsent not GRANTED
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.telemetrySubmitterFactory = exports.telemetryCacheConfigAdapter = exports.getTelemetryConfigStats =
|
|
4
|
+
exports.telemetrySubmitterFactory = exports.telemetryCacheConfigAdapter = exports.getTelemetryConfigStats = void 0;
|
|
5
5
|
var submitter_1 = require("./submitter");
|
|
6
6
|
var constants_1 = require("../../utils/constants");
|
|
7
7
|
var constants_2 = require("../../readiness/constants");
|
|
@@ -9,39 +9,6 @@ var settingsValidation_1 = require("../../utils/settingsValidation");
|
|
|
9
9
|
var apiKey_1 = require("../../utils/inputValidation/apiKey");
|
|
10
10
|
var timer_1 = require("../../utils/timeTracker/timer");
|
|
11
11
|
var objectAssign_1 = require("../../utils/lang/objectAssign");
|
|
12
|
-
/**
|
|
13
|
-
* Converts data from telemetry cache into /metrics/usage request payload.
|
|
14
|
-
*/
|
|
15
|
-
function telemetryCacheStatsAdapter(telemetry, splits, segments) {
|
|
16
|
-
return {
|
|
17
|
-
isEmpty: function () { return false; },
|
|
18
|
-
clear: function () { },
|
|
19
|
-
// @TODO consider moving inside telemetry cache for code size reduction
|
|
20
|
-
pop: function () {
|
|
21
|
-
return {
|
|
22
|
-
lS: telemetry.getLastSynchronization(),
|
|
23
|
-
mL: telemetry.popLatencies(),
|
|
24
|
-
mE: telemetry.popExceptions(),
|
|
25
|
-
hE: telemetry.popHttpErrors(),
|
|
26
|
-
hL: telemetry.popHttpLatencies(),
|
|
27
|
-
tR: telemetry.popTokenRefreshes(),
|
|
28
|
-
aR: telemetry.popAuthRejections(),
|
|
29
|
-
iQ: telemetry.getImpressionStats(constants_1.QUEUED),
|
|
30
|
-
iDe: telemetry.getImpressionStats(constants_1.DEDUPED),
|
|
31
|
-
iDr: telemetry.getImpressionStats(constants_1.DROPPED),
|
|
32
|
-
spC: splits.getSplitNames().length,
|
|
33
|
-
seC: segments.getRegisteredSegments().length,
|
|
34
|
-
skC: segments.getKeysCount(),
|
|
35
|
-
sL: telemetry.getSessionLength(),
|
|
36
|
-
eQ: telemetry.getEventStats(constants_1.QUEUED),
|
|
37
|
-
eD: telemetry.getEventStats(constants_1.DROPPED),
|
|
38
|
-
sE: telemetry.popStreamingEvents(),
|
|
39
|
-
t: telemetry.popTags(),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
exports.telemetryCacheStatsAdapter = telemetryCacheStatsAdapter;
|
|
45
12
|
var OPERATION_MODE_MAP = (_a = {},
|
|
46
13
|
_a[constants_1.STANDALONE_MODE] = constants_1.STANDALONE_ENUM,
|
|
47
14
|
_a[constants_1.CONSUMER_MODE] = constants_1.CONSUMER_ENUM,
|
|
@@ -121,12 +88,12 @@ exports.telemetryCacheConfigAdapter = telemetryCacheConfigAdapter;
|
|
|
121
88
|
* Submitter that periodically posts telemetry data
|
|
122
89
|
*/
|
|
123
90
|
function telemetrySubmitterFactory(params) {
|
|
124
|
-
var
|
|
91
|
+
var telemetry = params.storage.telemetry, now = params.platform.now;
|
|
125
92
|
if (!telemetry || !now)
|
|
126
93
|
return; // No submitter created if telemetry cache is not defined
|
|
127
|
-
var settings = params.settings,
|
|
94
|
+
var settings = params.settings, _a = params.settings, log = _a.log, telemetryRefreshRate = _a.scheduler.telemetryRefreshRate, splitApi = params.splitApi, readiness = params.readiness, sdkReadinessManager = params.sdkReadinessManager;
|
|
128
95
|
var startTime = (0, timer_1.timer)(now);
|
|
129
|
-
var submitter = (0, submitter_1.firstPushWindowDecorator)((0, submitter_1.submitterFactory)(log, splitApi.postMetricsUsage,
|
|
96
|
+
var submitter = (0, submitter_1.firstPushWindowDecorator)((0, submitter_1.submitterFactory)(log, splitApi.postMetricsUsage, telemetry, telemetryRefreshRate, 'telemetry stats', undefined, 0, true), telemetryRefreshRate);
|
|
130
97
|
readiness.gate.once(constants_2.SDK_READY_FROM_CACHE, function () {
|
|
131
98
|
telemetry.recordTimeUntilReadyFromCache(startTime());
|
|
132
99
|
});
|
|
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.uniqueKeysSubmitterFactory = void 0;
|
|
4
4
|
var constants_1 = require("../../logger/constants");
|
|
5
5
|
var submitter_1 = require("./submitter");
|
|
6
|
-
var DATA_NAME = '
|
|
6
|
+
var DATA_NAME = 'unique keys';
|
|
7
|
+
var UNIQUE_KEYS_RATE = 900000; // 15 minutes
|
|
7
8
|
/**
|
|
8
9
|
* Submitter that periodically posts impression counts
|
|
9
10
|
*/
|
|
10
11
|
function uniqueKeysSubmitterFactory(params) {
|
|
11
|
-
var _a = params.settings, log = _a.log,
|
|
12
|
+
var _a = params.settings, log = _a.log, key = _a.core.key, _b = params.splitApi, postUniqueKeysBulkCs = _b.postUniqueKeysBulkCs, postUniqueKeysBulkSs = _b.postUniqueKeysBulkSs, uniqueKeys = params.storage.uniqueKeys;
|
|
12
13
|
var isClientSide = key !== undefined;
|
|
13
14
|
var postUniqueKeysBulk = isClientSide ? postUniqueKeysBulkCs : postUniqueKeysBulkSs;
|
|
14
|
-
var syncTask = (0, submitter_1.submitterFactory)(log, postUniqueKeysBulk, uniqueKeys,
|
|
15
|
+
var syncTask = (0, submitter_1.submitterFactory)(log, postUniqueKeysBulk, uniqueKeys, UNIQUE_KEYS_RATE, DATA_NAME);
|
|
15
16
|
// register unique keys submitter to be executed when uniqueKeys cache is full
|
|
16
17
|
uniqueKeys.setOnFullQueueCb(function () {
|
|
17
18
|
if (syncTask.isRunning()) {
|
|
@@ -1,23 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isStorageSync =
|
|
3
|
+
exports.isStorageSync = void 0;
|
|
4
4
|
var constants_1 = require("../../utils/constants");
|
|
5
|
-
/**
|
|
6
|
-
* Checks if impressions previous time should be added or not.
|
|
7
|
-
*/
|
|
8
|
-
function shouldAddPt(settings) {
|
|
9
|
-
return [constants_1.PRODUCER_MODE, constants_1.STANDALONE_MODE, constants_1.CONSUMER_PARTIAL_MODE].indexOf(settings.mode) > -1 ? true : false;
|
|
10
|
-
}
|
|
11
|
-
exports.shouldAddPt = shouldAddPt;
|
|
12
|
-
/**
|
|
13
|
-
* Checks if it should dedupe impressions or not.
|
|
14
|
-
*/
|
|
15
|
-
function shouldBeOptimized(settings) {
|
|
16
|
-
if (!shouldAddPt(settings))
|
|
17
|
-
return false;
|
|
18
|
-
return settings.sync.impressionsMode === constants_1.OPTIMIZED ? true : false;
|
|
19
|
-
}
|
|
20
|
-
exports.shouldBeOptimized = shouldBeOptimized;
|
|
21
5
|
/**
|
|
22
6
|
* Storage is async if mode is consumer or partial consumer
|
|
23
7
|
*/
|
|
@@ -10,7 +10,7 @@ var noopFilterAdapter = {
|
|
|
10
10
|
/**
|
|
11
11
|
* Trackes uniques keys
|
|
12
12
|
* Unique Keys Tracker will be in charge of checking if the MTK was already sent to the BE in the last period
|
|
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
16
|
* @param uniqueKeysCache cache to save unique keys
|
package/cjs/utils/lang/maps.js
CHANGED
|
@@ -40,13 +40,6 @@ var MapPoly = /** @class */ (function () {
|
|
|
40
40
|
this.__mapKeysData__.length = 0;
|
|
41
41
|
this.__mapValuesData__.length = 0;
|
|
42
42
|
};
|
|
43
|
-
MapPoly.prototype.set = function (key, value) {
|
|
44
|
-
var index = this.__mapKeysData__.indexOf(key);
|
|
45
|
-
if (index === -1)
|
|
46
|
-
index = this.__mapKeysData__.push(key) - 1;
|
|
47
|
-
this.__mapValuesData__[index] = value;
|
|
48
|
-
return this;
|
|
49
|
-
};
|
|
50
43
|
MapPoly.prototype.delete = function (key) {
|
|
51
44
|
var index = this.__mapKeysData__.indexOf(key);
|
|
52
45
|
if (index === -1)
|
|
@@ -55,12 +48,27 @@ var MapPoly = /** @class */ (function () {
|
|
|
55
48
|
this.__mapValuesData__.splice(index, 1);
|
|
56
49
|
return true;
|
|
57
50
|
};
|
|
51
|
+
MapPoly.prototype.forEach = function (callbackfn, thisArg) {
|
|
52
|
+
for (var i = 0; i < this.__mapKeysData__.length; i++) {
|
|
53
|
+
callbackfn.call(thisArg, this.__mapValuesData__[i], this.__mapKeysData__[i], this);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
58
56
|
MapPoly.prototype.get = function (key) {
|
|
59
57
|
var index = this.__mapKeysData__.indexOf(key);
|
|
60
58
|
if (index === -1)
|
|
61
59
|
return;
|
|
62
60
|
return this.__mapValuesData__[index];
|
|
63
61
|
};
|
|
62
|
+
MapPoly.prototype.has = function (key) {
|
|
63
|
+
return this.__mapKeysData__.indexOf(key) !== -1;
|
|
64
|
+
};
|
|
65
|
+
MapPoly.prototype.set = function (key, value) {
|
|
66
|
+
var index = this.__mapKeysData__.indexOf(key);
|
|
67
|
+
if (index === -1)
|
|
68
|
+
index = this.__mapKeysData__.push(key) - 1;
|
|
69
|
+
this.__mapValuesData__[index] = value;
|
|
70
|
+
return this;
|
|
71
|
+
};
|
|
64
72
|
Object.defineProperty(MapPoly.prototype, "size", {
|
|
65
73
|
get: function () {
|
|
66
74
|
return this.__mapKeysData__.length;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisMock = void 0;
|
|
4
|
+
//@ts-nocheck
|
|
5
|
+
function identityFunction(data) {
|
|
6
|
+
return data;
|
|
7
|
+
}
|
|
8
|
+
function asyncFunction(data) {
|
|
9
|
+
return Promise.resolve(data);
|
|
10
|
+
}
|
|
11
|
+
var IDENTITY_METHODS = [];
|
|
12
|
+
var ASYNC_METHODS = ['rpush', 'hincrby'];
|
|
13
|
+
var PIPELINE_METHODS = ['rpush', 'hincrby'];
|
|
14
|
+
var RedisMock = /** @class */ (function () {
|
|
15
|
+
function RedisMock() {
|
|
16
|
+
var _this = this;
|
|
17
|
+
this.pipelineMethods = { exec: jest.fn(asyncFunction) };
|
|
18
|
+
IDENTITY_METHODS.forEach(function (method) {
|
|
19
|
+
_this[method] = jest.fn(identityFunction);
|
|
20
|
+
});
|
|
21
|
+
ASYNC_METHODS.forEach(function (method) {
|
|
22
|
+
_this[method] = jest.fn(asyncFunction);
|
|
23
|
+
});
|
|
24
|
+
PIPELINE_METHODS.forEach(function (method) {
|
|
25
|
+
_this.pipelineMethods[method] = _this[method];
|
|
26
|
+
});
|
|
27
|
+
this.pipeline = jest.fn(function () { return _this.pipelineMethods; });
|
|
28
|
+
}
|
|
29
|
+
return RedisMock;
|
|
30
|
+
}());
|
|
31
|
+
exports.RedisMock = RedisMock;
|