@splitsoftware/splitio-commons 1.6.2-rc.12 → 1.6.2-rc.14
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/cjs/listeners/browser.js +9 -11
- package/cjs/sdkFactory/index.js +7 -24
- package/cjs/storages/KeyBuilderSS.js +4 -43
- package/cjs/storages/inLocalStorage/index.js +14 -10
- package/cjs/storages/inMemory/InMemoryStorage.js +10 -7
- package/cjs/storages/inMemory/InMemoryStorageCS.js +10 -7
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +57 -34
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +3 -3
- package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +4 -4
- package/cjs/storages/inRedis/index.js +4 -2
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +3 -3
- package/cjs/storages/pluggable/ImpressionsCachePluggable.js +2 -19
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +4 -4
- package/cjs/storages/pluggable/inMemoryWrapper.js +8 -6
- package/cjs/storages/pluggable/index.js +4 -2
- package/cjs/storages/utils.js +73 -0
- package/cjs/sync/submitters/submitterManager.js +1 -1
- package/cjs/sync/submitters/telemetrySubmitter.js +4 -40
- package/cjs/trackers/impressionObserver/utils.js +1 -17
- package/cjs/trackers/uniqueKeysTracker.js +1 -1
- package/cjs/utils/settingsValidation/index.js +7 -1
- package/esm/listeners/browser.js +9 -11
- package/esm/sdkFactory/index.js +7 -24
- package/esm/storages/KeyBuilderSS.js +1 -37
- package/esm/storages/inLocalStorage/index.js +15 -11
- package/esm/storages/inMemory/InMemoryStorage.js +10 -7
- package/esm/storages/inMemory/InMemoryStorageCS.js +10 -7
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +58 -35
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +3 -3
- package/esm/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +1 -1
- package/esm/storages/inRedis/index.js +4 -2
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +3 -3
- package/esm/storages/pluggable/ImpressionsCachePluggable.js +2 -19
- package/esm/storages/pluggable/TelemetryCachePluggable.js +1 -1
- package/esm/storages/pluggable/inMemoryWrapper.js +8 -6
- package/esm/storages/pluggable/index.js +4 -2
- package/esm/storages/utils.js +65 -0
- package/esm/sync/submitters/submitterManager.js +1 -1
- package/esm/sync/submitters/telemetrySubmitter.js +4 -39
- package/esm/trackers/impressionObserver/utils.js +1 -15
- package/esm/trackers/uniqueKeysTracker.js +1 -1
- package/esm/utils/settingsValidation/index.js +7 -1
- package/package.json +2 -1
- package/src/listeners/browser.ts +9 -13
- package/src/sdkClient/sdkClient.ts +1 -1
- package/src/sdkFactory/index.ts +7 -29
- package/src/sdkFactory/types.ts +2 -2
- package/src/services/splitApi.ts +2 -2
- package/src/storages/KeyBuilderSS.ts +2 -44
- package/src/storages/inLocalStorage/index.ts +16 -11
- package/src/storages/inMemory/AttributesCacheInMemory.ts +7 -7
- package/src/storages/inMemory/InMemoryStorage.ts +11 -7
- package/src/storages/inMemory/InMemoryStorageCS.ts +11 -7
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +66 -33
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +3 -3
- package/src/storages/inRedis/ImpressionsCacheInRedis.ts +2 -22
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +3 -2
- package/src/storages/inRedis/index.ts +4 -1
- package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +3 -3
- package/src/storages/pluggable/ImpressionsCachePluggable.ts +3 -23
- package/src/storages/pluggable/TelemetryCachePluggable.ts +3 -2
- package/src/storages/pluggable/inMemoryWrapper.ts +6 -6
- package/src/storages/pluggable/index.ts +4 -2
- package/src/storages/types.ts +45 -64
- 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 +5 -41
- package/src/sync/submitters/types.ts +7 -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/utils/redis/RedisMock.ts +5 -5
- package/src/utils/settingsValidation/index.ts +5 -1
- package/types/storages/KeyBuilderSS.d.ts +1 -3
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +19 -8
- package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +0 -1
- package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +1 -2
- package/types/storages/types.d.ts +35 -45
- 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 +8 -6
- 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/cjs/storages/metadataBuilder.js +0 -12
- package/esm/storages/metadataBuilder.js +0 -8
- package/src/storages/metadataBuilder.ts +0 -11
package/cjs/listeners/browser.js
CHANGED
|
@@ -7,7 +7,6 @@ var constants_1 = require("../utils/constants");
|
|
|
7
7
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
8
8
|
var constants_2 = require("../logger/constants");
|
|
9
9
|
var consent_1 = require("../consent");
|
|
10
|
-
var telemetrySubmitter_1 = require("../sync/submitters/telemetrySubmitter");
|
|
11
10
|
var VISIBILITYCHANGE_EVENT = 'visibilitychange';
|
|
12
11
|
var PAGEHIDE_EVENT = 'pagehide';
|
|
13
12
|
var UNLOAD_EVENT = 'unload';
|
|
@@ -71,25 +70,25 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
71
70
|
BrowserSignalListener.prototype.flushData = function () {
|
|
72
71
|
if (!this.syncManager)
|
|
73
72
|
return; // In consumer mode there is not sync manager and data to flush
|
|
73
|
+
var _a = this.settings.urls, events = _a.events, telemetry = _a.telemetry;
|
|
74
74
|
// Flush impressions & events data if there is user consent
|
|
75
75
|
if ((0, consent_1.isConsentGranted)(this.settings)) {
|
|
76
|
-
var eventsUrl = this.settings.urls.events;
|
|
77
76
|
var sim = this.settings.sync.impressionsMode;
|
|
78
77
|
var extraMetadata = {
|
|
79
78
|
// sim stands for Sync/Split Impressions Mode
|
|
80
79
|
sim: sim === constants_1.OPTIMIZED ? constants_1.OPTIMIZED : sim === constants_1.DEBUG ? constants_1.DEBUG : constants_1.NONE
|
|
81
80
|
};
|
|
82
|
-
this._flushData(
|
|
83
|
-
this._flushData(
|
|
81
|
+
this._flushData(events + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
|
|
82
|
+
this._flushData(events + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
|
|
84
83
|
if (this.storage.impressionCounts)
|
|
85
|
-
this._flushData(
|
|
84
|
+
this._flushData(events + '/testImpressions/count/beacon', this.storage.impressionCounts, this.serviceApi.postTestImpressionsCount, impressionCountsSubmitter_1.fromImpressionCountsCollector);
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
if (this.storage.uniqueKeys)
|
|
87
|
+
this._flushData(telemetry + '/v1/keys/cs/beacon', this.storage.uniqueKeys, this.serviceApi.postUniqueKeysBulkCs);
|
|
86
88
|
}
|
|
87
89
|
// Flush telemetry data
|
|
88
|
-
if (this.storage.telemetry)
|
|
89
|
-
|
|
90
|
-
var telemetryCacheAdapter = (0, telemetrySubmitter_1.telemetryCacheStatsAdapter)(this.storage.telemetry, this.storage.splits, this.storage.segments);
|
|
91
|
-
this._flushData(telemetryUrl + '/v1/metrics/usage/beacon', telemetryCacheAdapter, this.serviceApi.postMetricsUsage);
|
|
92
|
-
}
|
|
90
|
+
if (this.storage.telemetry)
|
|
91
|
+
this._flushData(telemetry + '/v1/metrics/usage/beacon', this.storage.telemetry, this.serviceApi.postMetricsUsage);
|
|
93
92
|
};
|
|
94
93
|
BrowserSignalListener.prototype.flushDataIfHidden = function () {
|
|
95
94
|
// Precondition: document defined
|
|
@@ -103,7 +102,6 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
103
102
|
if (!this._sendBeacon(url, dataPayload, extraMetadata)) {
|
|
104
103
|
postService(JSON.stringify(dataPayload)).catch(function () { }); // no-op just to catch a possible exception
|
|
105
104
|
}
|
|
106
|
-
cache.clear();
|
|
107
105
|
}
|
|
108
106
|
};
|
|
109
107
|
/**
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -5,12 +5,9 @@ var sdkReadinessManager_1 = require("../readiness/sdkReadinessManager");
|
|
|
5
5
|
var impressionsTracker_1 = require("../trackers/impressionsTracker");
|
|
6
6
|
var eventTracker_1 = require("../trackers/eventTracker");
|
|
7
7
|
var telemetryTracker_1 = require("../trackers/telemetryTracker");
|
|
8
|
-
var key_1 = require("../utils/key");
|
|
9
|
-
var utils_1 = require("../trackers/impressionObserver/utils");
|
|
10
8
|
var apiKey_1 = require("../utils/inputValidation/apiKey");
|
|
11
9
|
var sdkLogger_1 = require("../logger/sdkLogger");
|
|
12
10
|
var constants_1 = require("../logger/constants");
|
|
13
|
-
var metadataBuilder_1 = require("../storages/metadataBuilder");
|
|
14
11
|
var constants_2 = require("../readiness/constants");
|
|
15
12
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
16
13
|
var strategyDebug_1 = require("../trackers/strategy/strategyDebug");
|
|
@@ -23,43 +20,29 @@ var constants_3 = require("../utils/constants");
|
|
|
23
20
|
*/
|
|
24
21
|
function sdkFactory(params) {
|
|
25
22
|
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory, filterAdapterFactory = params.filterAdapterFactory;
|
|
26
|
-
var log = settings.log;
|
|
23
|
+
var log = settings.log, impressionsMode = settings.sync.impressionsMode;
|
|
27
24
|
// @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid API Key, etc.
|
|
28
25
|
// On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
|
|
29
26
|
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
30
27
|
(0, apiKey_1.validateAndTrackApiKey)(log, settings.core.authorizationKey);
|
|
31
28
|
var sdkReadinessManager = (0, sdkReadinessManager_1.sdkReadinessManagerFactory)(log, platform.EventEmitter, settings.startup.readyTimeout);
|
|
32
29
|
var readiness = sdkReadinessManager.readinessManager;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
impressionsQueueSize: settings.scheduler.impressionsQueueSize,
|
|
36
|
-
eventsQueueSize: settings.scheduler.eventsQueueSize,
|
|
37
|
-
optimize: (0, utils_1.shouldBeOptimized)(settings),
|
|
38
|
-
// ATM, only used by InLocalStorage
|
|
39
|
-
matchingKey: (0, key_1.getMatching)(settings.core.key),
|
|
40
|
-
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
41
|
-
// ATM, only used by PluggableStorage
|
|
42
|
-
mode: settings.mode,
|
|
43
|
-
impressionsMode: settings.sync.impressionsMode,
|
|
44
|
-
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
|
|
45
|
-
// or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
|
|
30
|
+
var storage = storageFactory({
|
|
31
|
+
settings: settings,
|
|
46
32
|
onReadyCb: function (error) {
|
|
47
33
|
if (error)
|
|
48
34
|
return; // Don't emit SDK_READY if storage failed to connect. Error message is logged by wrapperAdapter
|
|
49
35
|
readiness.splits.emit(constants_2.SDK_SPLITS_ARRIVED);
|
|
50
36
|
readiness.segments.emit(constants_2.SDK_SEGMENTS_ARRIVED);
|
|
51
37
|
},
|
|
52
|
-
|
|
53
|
-
log: log
|
|
54
|
-
};
|
|
55
|
-
var storage = storageFactory(storageFactoryParams);
|
|
38
|
+
});
|
|
56
39
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
57
40
|
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
58
41
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
59
42
|
var observer = impressionsObserverFactory();
|
|
60
|
-
var uniqueKeysTracker =
|
|
43
|
+
var uniqueKeysTracker = impressionsMode === constants_3.NONE ? (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
61
44
|
var strategy;
|
|
62
|
-
switch (
|
|
45
|
+
switch (impressionsMode) {
|
|
63
46
|
case constants_3.OPTIMIZED:
|
|
64
47
|
strategy = (0, strategyOptimized_1.strategyOptimizedFactory)(observer, storage.impressionCounts);
|
|
65
48
|
break;
|
|
@@ -94,7 +77,7 @@ function sdkFactory(params) {
|
|
|
94
77
|
return managerInstance;
|
|
95
78
|
},
|
|
96
79
|
// Logger wrapper API
|
|
97
|
-
Logger: (0, sdkLogger_1.createLoggerAPI)(
|
|
80
|
+
Logger: (0, sdkLogger_1.createLoggerAPI)(log),
|
|
98
81
|
settings: settings,
|
|
99
82
|
}, extraProps && extraProps(ctx));
|
|
100
83
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.KeyBuilderSS = exports.METHOD_NAMES = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var KeyBuilder_1 = require("./KeyBuilder");
|
|
6
|
-
|
|
7
|
-
var METHOD_NAMES = {
|
|
6
|
+
exports.METHOD_NAMES = {
|
|
8
7
|
t: 'treatment',
|
|
9
8
|
ts: 'treatments',
|
|
10
9
|
tc: 'treatmentWithConfig',
|
|
@@ -41,10 +40,10 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
41
40
|
};
|
|
42
41
|
/* Telemetry keys */
|
|
43
42
|
KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
|
|
44
|
-
return this.latencyPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method] + "/" + bucket;
|
|
43
|
+
return this.latencyPrefix + "::" + this.versionablePrefix + "/" + exports.METHOD_NAMES[method] + "/" + bucket;
|
|
45
44
|
};
|
|
46
45
|
KeyBuilderSS.prototype.buildExceptionKey = function (method) {
|
|
47
|
-
return this.exceptionPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method];
|
|
46
|
+
return this.exceptionPrefix + "::" + this.versionablePrefix + "/" + exports.METHOD_NAMES[method];
|
|
48
47
|
};
|
|
49
48
|
KeyBuilderSS.prototype.buildInitKey = function () {
|
|
50
49
|
return this.initPrefix + "::" + this.versionablePrefix;
|
|
@@ -52,41 +51,3 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
52
51
|
return KeyBuilderSS;
|
|
53
52
|
}(KeyBuilder_1.KeyBuilder));
|
|
54
53
|
exports.KeyBuilderSS = KeyBuilderSS;
|
|
55
|
-
// Used by consumer methods of TelemetryCacheInRedis and TelemetryCachePluggable
|
|
56
|
-
var REVERSE_METHOD_NAMES = Object.keys(METHOD_NAMES).reduce(function (acc, key) {
|
|
57
|
-
acc[METHOD_NAMES[key]] = key;
|
|
58
|
-
return acc;
|
|
59
|
-
}, {});
|
|
60
|
-
function parseMetadata(field) {
|
|
61
|
-
var parts = field.split('/');
|
|
62
|
-
if (parts.length !== 3)
|
|
63
|
-
return "invalid subsection count. Expected 3, got: " + parts.length;
|
|
64
|
-
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */;
|
|
65
|
-
return [JSON.stringify({ s: s, n: n, i: i })];
|
|
66
|
-
}
|
|
67
|
-
exports.parseMetadata = parseMetadata;
|
|
68
|
-
function parseExceptionField(field) {
|
|
69
|
-
var parts = field.split('/');
|
|
70
|
-
if (parts.length !== 4)
|
|
71
|
-
return "invalid subsection count. Expected 4, got: " + parts.length;
|
|
72
|
-
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3];
|
|
73
|
-
var method = REVERSE_METHOD_NAMES[m];
|
|
74
|
-
if (!method)
|
|
75
|
-
return "unknown method '" + m + "'";
|
|
76
|
-
return [JSON.stringify({ s: s, n: n, i: i }), method];
|
|
77
|
-
}
|
|
78
|
-
exports.parseExceptionField = parseExceptionField;
|
|
79
|
-
function parseLatencyField(field) {
|
|
80
|
-
var parts = field.split('/');
|
|
81
|
-
if (parts.length !== 5)
|
|
82
|
-
return "invalid subsection count. Expected 5, got: " + parts.length;
|
|
83
|
-
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3], b = parts[4];
|
|
84
|
-
var method = REVERSE_METHOD_NAMES[m];
|
|
85
|
-
if (!method)
|
|
86
|
-
return "unknown method '" + m + "'";
|
|
87
|
-
var bucket = parseInt(b);
|
|
88
|
-
if (isNaN(bucket) || bucket >= TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT)
|
|
89
|
-
return "invalid bucket. Expected a number between 0 and " + (TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT - 1) + ", got: " + b;
|
|
90
|
-
return [JSON.stringify({ s: s, n: n, i: i }), method, bucket];
|
|
91
|
-
}
|
|
92
|
-
exports.parseLatencyField = parseLatencyField;
|
|
@@ -17,6 +17,7 @@ var constants_1 = require("./constants");
|
|
|
17
17
|
var constants_2 = require("../../utils/constants");
|
|
18
18
|
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
19
19
|
var UniqueKeysCacheInMemoryCS_1 = require("../inMemory/UniqueKeysCacheInMemoryCS");
|
|
20
|
+
var key_1 = require("../../utils/key");
|
|
20
21
|
/**
|
|
21
22
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
22
23
|
*/
|
|
@@ -26,20 +27,23 @@ function InLocalStorage(options) {
|
|
|
26
27
|
function InLocalStorageCSFactory(params) {
|
|
27
28
|
// Fallback to InMemoryStorage if LocalStorage API is not available
|
|
28
29
|
if (!(0, isLocalStorageAvailable_1.isLocalStorageAvailable)()) {
|
|
29
|
-
params.log.warn(constants_1.LOG_PREFIX + 'LocalStorage API is unavailable. Falling back to default MEMORY storage');
|
|
30
|
+
params.settings.log.warn(constants_1.LOG_PREFIX + 'LocalStorage API is unavailable. Falling back to default MEMORY storage');
|
|
30
31
|
return (0, InMemoryStorageCS_1.InMemoryStorageCSFactory)(params);
|
|
31
32
|
}
|
|
32
|
-
var
|
|
33
|
-
var
|
|
33
|
+
var settings = params.settings, _a = params.settings, log = _a.log, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
|
|
34
|
+
var matchingKey = (0, key_1.getMatching)(settings.core.key);
|
|
35
|
+
var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
|
|
34
36
|
var expirationTimestamp = Date.now() - browser_1.DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
37
|
+
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(log, keys, expirationTimestamp, __splitFiltersValidation);
|
|
38
|
+
var segments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys);
|
|
35
39
|
return {
|
|
36
|
-
splits:
|
|
37
|
-
segments:
|
|
38
|
-
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(
|
|
39
|
-
impressionCounts:
|
|
40
|
-
events: new EventsCacheInMemory_1.EventsCacheInMemory(
|
|
41
|
-
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
42
|
-
uniqueKeys:
|
|
40
|
+
splits: splits,
|
|
41
|
+
segments: segments,
|
|
42
|
+
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
43
|
+
impressionCounts: impressionsMode !== constants_2.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
44
|
+
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
45
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
46
|
+
uniqueKeys: impressionsMode === constants_2.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
43
47
|
destroy: function () {
|
|
44
48
|
var _a;
|
|
45
49
|
this.splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
|
|
@@ -15,14 +15,17 @@ var UniqueKeysCacheInMemory_1 = require("./UniqueKeysCacheInMemory");
|
|
|
15
15
|
* @param params parameters required by EventsCacheSync
|
|
16
16
|
*/
|
|
17
17
|
function InMemoryStorageFactory(params) {
|
|
18
|
+
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, impressionsMode = _a.sync.impressionsMode;
|
|
19
|
+
var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
|
|
20
|
+
var segments = new SegmentsCacheInMemory_1.SegmentsCacheInMemory();
|
|
18
21
|
return {
|
|
19
|
-
splits:
|
|
20
|
-
segments:
|
|
21
|
-
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(
|
|
22
|
-
impressionCounts:
|
|
23
|
-
events: new EventsCacheInMemory_1.EventsCacheInMemory(
|
|
24
|
-
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
25
|
-
uniqueKeys:
|
|
22
|
+
splits: splits,
|
|
23
|
+
segments: segments,
|
|
24
|
+
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
25
|
+
impressionCounts: impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
26
|
+
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
27
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
28
|
+
uniqueKeys: impressionsMode === constants_1.NONE ? new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory() : undefined,
|
|
26
29
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
27
30
|
destroy: function () {
|
|
28
31
|
var _a;
|
|
@@ -15,14 +15,17 @@ var UniqueKeysCacheInMemoryCS_1 = require("./UniqueKeysCacheInMemoryCS");
|
|
|
15
15
|
* @param params parameters required by EventsCacheSync
|
|
16
16
|
*/
|
|
17
17
|
function InMemoryStorageCSFactory(params) {
|
|
18
|
+
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, impressionsMode = _a.sync.impressionsMode;
|
|
19
|
+
var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
|
|
20
|
+
var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
18
21
|
return {
|
|
19
|
-
splits:
|
|
20
|
-
segments:
|
|
21
|
-
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(
|
|
22
|
-
impressionCounts:
|
|
23
|
-
events: new EventsCacheInMemory_1.EventsCacheInMemory(
|
|
24
|
-
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
25
|
-
uniqueKeys:
|
|
22
|
+
splits: splits,
|
|
23
|
+
segments: segments,
|
|
24
|
+
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
25
|
+
impressionCounts: impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
26
|
+
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
27
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
28
|
+
uniqueKeys: impressionsMode === constants_1.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
26
29
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
27
30
|
destroy: function () {
|
|
28
31
|
var _a;
|
|
@@ -17,30 +17,56 @@ var ACCEPTANCE_RANGE = 0.001;
|
|
|
17
17
|
* Record telemetry if mode is not localhost.
|
|
18
18
|
* All factory instances track telemetry on server-side, and 0.1% on client-side.
|
|
19
19
|
*/
|
|
20
|
-
function shouldRecordTelemetry(
|
|
21
|
-
|
|
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);
|
|
22
23
|
}
|
|
23
24
|
exports.shouldRecordTelemetry = shouldRecordTelemetry;
|
|
24
25
|
var TelemetryCacheInMemory = /** @class */ (function () {
|
|
25
|
-
function TelemetryCacheInMemory() {
|
|
26
|
+
function TelemetryCacheInMemory(splits, segments) {
|
|
27
|
+
this.splits = splits;
|
|
28
|
+
this.segments = segments;
|
|
29
|
+
// isEmpty flag
|
|
30
|
+
this.e = true;
|
|
26
31
|
this.notReadyUsage = 0;
|
|
32
|
+
/** Usage stats */
|
|
27
33
|
this.impressionStats = [0, 0, 0];
|
|
28
34
|
this.eventStats = [0, 0];
|
|
29
|
-
// @ts-expect-error
|
|
30
35
|
this.lastSync = {};
|
|
31
|
-
// @ts-expect-error
|
|
32
36
|
this.httpErrors = {};
|
|
33
|
-
// @ts-expect-error
|
|
34
37
|
this.httpLatencies = {};
|
|
35
38
|
this.authRejections = 0;
|
|
36
39
|
this.tokenRefreshes = 0;
|
|
37
40
|
this.streamingEvents = [];
|
|
38
41
|
this.tags = [];
|
|
39
|
-
// @ts-expect-error
|
|
40
42
|
this.exceptions = {};
|
|
41
|
-
// @ts-expect-error
|
|
42
43
|
this.latencies = {};
|
|
43
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
|
+
};
|
|
44
70
|
TelemetryCacheInMemory.prototype.getTimeUntilReady = function () {
|
|
45
71
|
return this.timeUntilReady;
|
|
46
72
|
};
|
|
@@ -64,44 +90,41 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
64
90
|
};
|
|
65
91
|
TelemetryCacheInMemory.prototype.recordImpressionStats = function (type, count) {
|
|
66
92
|
this.impressionStats[type] += count;
|
|
93
|
+
this.e = false;
|
|
67
94
|
};
|
|
68
95
|
TelemetryCacheInMemory.prototype.getEventStats = function (type) {
|
|
69
96
|
return this.eventStats[type];
|
|
70
97
|
};
|
|
71
98
|
TelemetryCacheInMemory.prototype.recordEventStats = function (type, count) {
|
|
72
99
|
this.eventStats[type] += count;
|
|
100
|
+
this.e = false;
|
|
73
101
|
};
|
|
74
102
|
TelemetryCacheInMemory.prototype.getLastSynchronization = function () {
|
|
75
103
|
return this.lastSync;
|
|
76
104
|
};
|
|
77
105
|
TelemetryCacheInMemory.prototype.recordSuccessfulSync = function (resource, timeMs) {
|
|
78
106
|
this.lastSync[resource] = timeMs;
|
|
107
|
+
this.e = false;
|
|
79
108
|
};
|
|
80
109
|
TelemetryCacheInMemory.prototype.popHttpErrors = function () {
|
|
81
|
-
var result = this.httpErrors;
|
|
110
|
+
var result = this.httpErrors;
|
|
82
111
|
this.httpErrors = {};
|
|
83
112
|
return result;
|
|
84
113
|
};
|
|
85
114
|
TelemetryCacheInMemory.prototype.recordHttpError = function (resource, status) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.httpErrors[resource][status] = 1;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
this.httpErrors[resource][status]++;
|
|
93
|
-
}
|
|
115
|
+
var statusErrors = (this.httpErrors[resource] = this.httpErrors[resource] || {});
|
|
116
|
+
statusErrors[status] = (statusErrors[status] || 0) + 1;
|
|
117
|
+
this.e = false;
|
|
94
118
|
};
|
|
95
119
|
TelemetryCacheInMemory.prototype.popHttpLatencies = function () {
|
|
96
|
-
var result = this.httpLatencies;
|
|
120
|
+
var result = this.httpLatencies;
|
|
97
121
|
this.httpLatencies = {};
|
|
98
122
|
return result;
|
|
99
123
|
};
|
|
100
124
|
TelemetryCacheInMemory.prototype.recordHttpLatency = function (resource, latencyMs) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
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;
|
|
105
128
|
};
|
|
106
129
|
TelemetryCacheInMemory.prototype.popAuthRejections = function () {
|
|
107
130
|
var result = this.authRejections;
|
|
@@ -110,6 +133,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
110
133
|
};
|
|
111
134
|
TelemetryCacheInMemory.prototype.recordAuthRejections = function () {
|
|
112
135
|
this.authRejections++;
|
|
136
|
+
this.e = false;
|
|
113
137
|
};
|
|
114
138
|
TelemetryCacheInMemory.prototype.popTokenRefreshes = function () {
|
|
115
139
|
var result = this.tokenRefreshes;
|
|
@@ -118,6 +142,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
118
142
|
};
|
|
119
143
|
TelemetryCacheInMemory.prototype.recordTokenRefreshes = function () {
|
|
120
144
|
this.tokenRefreshes++;
|
|
145
|
+
this.e = false;
|
|
121
146
|
};
|
|
122
147
|
TelemetryCacheInMemory.prototype.popStreamingEvents = function () {
|
|
123
148
|
return this.streamingEvents.splice(0);
|
|
@@ -126,6 +151,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
126
151
|
if (this.streamingEvents.length < MAX_STREAMING_EVENTS) {
|
|
127
152
|
this.streamingEvents.push(streamingEvent);
|
|
128
153
|
}
|
|
154
|
+
this.e = false;
|
|
129
155
|
};
|
|
130
156
|
TelemetryCacheInMemory.prototype.popTags = function () {
|
|
131
157
|
return this.tags.splice(0);
|
|
@@ -134,36 +160,33 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
134
160
|
if (this.tags.length < MAX_TAGS) {
|
|
135
161
|
this.tags.push(tag);
|
|
136
162
|
}
|
|
163
|
+
this.e = false;
|
|
137
164
|
};
|
|
138
165
|
TelemetryCacheInMemory.prototype.getSessionLength = function () {
|
|
139
166
|
return this.sessionLength;
|
|
140
167
|
};
|
|
141
168
|
TelemetryCacheInMemory.prototype.recordSessionLength = function (ms) {
|
|
142
169
|
this.sessionLength = ms;
|
|
170
|
+
this.e = false;
|
|
143
171
|
};
|
|
144
172
|
TelemetryCacheInMemory.prototype.popExceptions = function () {
|
|
145
|
-
var result = this.exceptions;
|
|
173
|
+
var result = this.exceptions;
|
|
146
174
|
this.exceptions = {};
|
|
147
175
|
return result;
|
|
148
176
|
};
|
|
149
177
|
TelemetryCacheInMemory.prototype.recordException = function (method) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
this.exceptions[method]++;
|
|
155
|
-
}
|
|
178
|
+
this.exceptions[method] = (this.exceptions[method] || 0) + 1;
|
|
179
|
+
this.e = false;
|
|
156
180
|
};
|
|
157
181
|
TelemetryCacheInMemory.prototype.popLatencies = function () {
|
|
158
|
-
var result = this.latencies;
|
|
182
|
+
var result = this.latencies;
|
|
159
183
|
this.latencies = {};
|
|
160
184
|
return result;
|
|
161
185
|
};
|
|
162
186
|
TelemetryCacheInMemory.prototype.recordLatency = function (method, latencyMs) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
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;
|
|
167
190
|
};
|
|
168
191
|
return TelemetryCacheInMemory;
|
|
169
192
|
}());
|
|
@@ -54,7 +54,7 @@ var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
|
|
|
54
54
|
if (!Object.keys(counts).length)
|
|
55
55
|
return undefined;
|
|
56
56
|
_this.redis.del(_this.key).catch(function () { });
|
|
57
|
-
var
|
|
57
|
+
var pf = [];
|
|
58
58
|
(0, lang_1.forOwn)(counts, function (count, key) {
|
|
59
59
|
var nameAndTime = key.split('::');
|
|
60
60
|
if (nameAndTime.length !== 2) {
|
|
@@ -71,13 +71,13 @@ var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
|
|
|
71
71
|
_this.log.error(constants_1.LOG_PREFIX + "Error parsing raw count " + count);
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
pf.push({
|
|
75
75
|
f: nameAndTime[0],
|
|
76
76
|
m: timeFrame,
|
|
77
77
|
rc: rawCount,
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
|
-
return
|
|
80
|
+
return { pf: pf };
|
|
81
81
|
});
|
|
82
82
|
};
|
|
83
83
|
return 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;
|
|
@@ -12,6 +12,7 @@ var constants_1 = require("../../utils/constants");
|
|
|
12
12
|
var TelemetryCacheInRedis_1 = require("./TelemetryCacheInRedis");
|
|
13
13
|
var UniqueKeysCacheInRedis_1 = require("./UniqueKeysCacheInRedis");
|
|
14
14
|
var ImpressionCountsCacheInRedis_1 = require("./ImpressionCountsCacheInRedis");
|
|
15
|
+
var utils_1 = require("../utils");
|
|
15
16
|
/**
|
|
16
17
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
17
18
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
@@ -19,8 +20,9 @@ var ImpressionCountsCacheInRedis_1 = require("./ImpressionCountsCacheInRedis");
|
|
|
19
20
|
function InRedisStorage(options) {
|
|
20
21
|
if (options === void 0) { options = {}; }
|
|
21
22
|
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
22
|
-
function InRedisStorageFactory(
|
|
23
|
-
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);
|
|
24
26
|
var keys = new KeyBuilderSS_1.KeyBuilderSS(prefix, metadata);
|
|
25
27
|
var redisClient = new RedisAdapter_1.RedisAdapter(log, options.options || {});
|
|
26
28
|
var telemetry = new TelemetryCacheInRedis_1.TelemetryCacheInRedis(log, keys, redisClient);
|
|
@@ -46,7 +46,7 @@ var ImpressionCountsCachePluggable = /** @class */ (function (_super) {
|
|
|
46
46
|
return keys.length ? Promise.all(keys.map(function (key) { return _this.wrapper.get(key); }))
|
|
47
47
|
.then(function (counts) {
|
|
48
48
|
keys.forEach(function (key) { return _this.wrapper.del(key).catch(function () { }); });
|
|
49
|
-
var
|
|
49
|
+
var pf = [];
|
|
50
50
|
for (var i = 0; i < keys.length; i++) {
|
|
51
51
|
var key = keys[i];
|
|
52
52
|
var count = counts[i];
|
|
@@ -66,13 +66,13 @@ var ImpressionCountsCachePluggable = /** @class */ (function (_super) {
|
|
|
66
66
|
_this.log.error(constants_2.LOG_PREFIX + "Error parsing raw count " + count);
|
|
67
67
|
continue;
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
pf.push({
|
|
70
70
|
f: keyFeatureNameAndTime[1],
|
|
71
71
|
m: timeFrame,
|
|
72
72
|
rc: rawCount,
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
-
return
|
|
75
|
+
return { pf: pf };
|
|
76
76
|
}) : undefined;
|
|
77
77
|
});
|
|
78
78
|
};
|