@splitsoftware/splitio-commons 1.6.2-rc.7 → 1.6.2-rc.9
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 +2 -1
- package/cjs/consent/sdkUserConsent.js +2 -2
- package/cjs/evaluator/index.js +5 -5
- package/cjs/listeners/browser.js +1 -2
- package/cjs/logger/constants.js +1 -2
- package/cjs/sdkClient/client.js +19 -7
- package/cjs/sdkClient/sdkClient.js +1 -3
- package/cjs/sdkFactory/index.js +5 -26
- package/cjs/services/splitApi.js +4 -24
- package/cjs/storages/KeyBuilderSS.js +48 -15
- package/cjs/storages/inLocalStorage/index.js +1 -5
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -12
- package/cjs/storages/inMemory/InMemoryStorage.js +2 -6
- package/cjs/storages/inMemory/InMemoryStorageCS.js +2 -6
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +9 -6
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/cjs/storages/inRedis/constants.js +1 -4
- package/cjs/storages/inRedis/index.js +1 -15
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/cjs/storages/pluggable/index.js +19 -15
- package/cjs/sync/submitters/submitterManager.js +0 -3
- package/cjs/sync/submitters/telemetrySubmitter.js +7 -5
- package/cjs/trackers/impressionsTracker.js +41 -22
- package/cjs/utils/constants/index.js +2 -4
- package/cjs/utils/lang/maps.js +15 -7
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/cjs/utils/settingsValidation/index.js +0 -4
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/evaluator/index.js +5 -5
- package/esm/listeners/browser.js +2 -3
- package/esm/logger/constants.js +0 -1
- package/esm/sdkClient/client.js +19 -7
- package/esm/sdkClient/sdkClient.js +1 -3
- package/esm/sdkFactory/index.js +5 -26
- package/esm/services/splitApi.js +4 -24
- package/esm/storages/KeyBuilderSS.js +44 -14
- package/esm/storages/inLocalStorage/index.js +2 -6
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -12
- package/esm/storages/inMemory/InMemoryStorage.js +4 -8
- package/esm/storages/inMemory/InMemoryStorageCS.js +3 -7
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +8 -6
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/esm/storages/inRedis/constants.js +0 -3
- package/esm/storages/inRedis/index.js +2 -16
- package/esm/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/esm/storages/pluggable/index.js +19 -15
- package/esm/sync/submitters/submitterManager.js +0 -3
- package/esm/sync/submitters/telemetrySubmitter.js +8 -6
- package/esm/trackers/impressionsTracker.js +41 -22
- package/esm/utils/constants/index.js +0 -2
- package/esm/utils/lang/maps.js +15 -7
- package/esm/utils/settingsValidation/impressionsMode.js +3 -3
- package/esm/utils/settingsValidation/index.js +0 -4
- package/package.json +2 -1
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/evaluator/index.ts +6 -6
- package/src/listeners/browser.ts +2 -3
- package/src/logger/.DS_Store +0 -0
- package/src/logger/constants.ts +0 -1
- package/src/sdkClient/client.ts +21 -8
- package/src/sdkClient/sdkClient.ts +1 -3
- package/src/sdkFactory/index.ts +5 -29
- package/src/sdkFactory/types.ts +4 -7
- package/src/services/splitApi.ts +4 -26
- package/src/services/types.ts +2 -8
- package/src/storages/KeyBuilderSS.ts +53 -17
- package/src/storages/inLocalStorage/index.ts +2 -5
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +1 -16
- package/src/storages/inMemory/InMemoryStorage.ts +4 -7
- package/src/storages/inMemory/InMemoryStorageCS.ts +3 -7
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +9 -7
- package/src/storages/inRedis/EventsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +122 -2
- package/src/storages/inRedis/constants.ts +0 -3
- package/src/storages/inRedis/index.ts +3 -12
- package/src/storages/pluggable/TelemetryCachePluggable.ts +147 -2
- package/src/storages/pluggable/index.ts +20 -16
- package/src/storages/types.ts +13 -34
- package/src/sync/submitters/submitterManager.ts +0 -2
- package/src/sync/submitters/telemetrySubmitter.ts +14 -9
- package/src/sync/submitters/types.ts +40 -26
- package/src/trackers/impressionsTracker.ts +48 -27
- package/src/trackers/types.ts +0 -28
- package/src/types.ts +1 -5
- package/src/utils/constants/index.ts +0 -2
- package/src/utils/lang/maps.ts +20 -8
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +0 -5
- package/types/logger/constants.d.ts +0 -1
- package/types/sdkFactory/types.d.ts +2 -4
- package/types/services/types.d.ts +2 -6
- package/types/storages/KeyBuilderSS.d.ts +7 -4
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +1 -5
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -3
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +16 -1
- package/types/storages/inRedis/constants.d.ts +0 -3
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +17 -1
- package/types/storages/types.d.ts +10 -21
- package/types/sync/submitters/telemetrySubmitter.d.ts +1 -1
- package/types/sync/submitters/types.d.ts +13 -24
- package/types/trackers/impressionsTracker.d.ts +6 -4
- package/types/trackers/types.d.ts +0 -23
- package/types/types.d.ts +1 -5
- package/types/utils/constants/index.d.ts +0 -2
- package/types/utils/lang/maps.d.ts +6 -2
- package/types/utils/settingsValidation/index.d.ts +0 -1
- package/cjs/storages/inMemory/uniqueKeysCacheInMemory.js +0 -73
- package/cjs/storages/inMemory/uniqueKeysCacheInMemoryCS.js +0 -78
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +0 -49
- package/cjs/storages/inRedis/uniqueKeysCacheInRedis.js +0 -56
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +0 -26
- package/cjs/trackers/strategy/strategyDebug.js +0 -25
- package/cjs/trackers/strategy/strategyNone.js +0 -29
- package/cjs/trackers/strategy/strategyOptimized.js +0 -35
- package/cjs/trackers/uniqueKeysTracker.js +0 -38
- package/esm/storages/inMemory/uniqueKeysCacheInMemory.js +0 -70
- package/esm/storages/inMemory/uniqueKeysCacheInMemoryCS.js +0 -75
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +0 -46
- package/esm/storages/inRedis/uniqueKeysCacheInRedis.js +0 -53
- package/esm/sync/submitters/uniqueKeysSubmitter.js +0 -22
- package/esm/trackers/strategy/strategyDebug.js +0 -21
- package/esm/trackers/strategy/strategyNone.js +0 -25
- package/esm/trackers/strategy/strategyOptimized.js +0 -31
- package/esm/trackers/uniqueKeysTracker.js +0 -34
- package/src/storages/inMemory/uniqueKeysCacheInMemory.ts +0 -82
- package/src/storages/inMemory/uniqueKeysCacheInMemoryCS.ts +0 -88
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +0 -51
- package/src/storages/inRedis/uniqueKeysCacheInRedis.ts +0 -63
- package/src/sync/submitters/uniqueKeysSubmitter.ts +0 -35
- package/src/trackers/strategy/strategyDebug.ts +0 -28
- package/src/trackers/strategy/strategyNone.ts +0 -34
- package/src/trackers/strategy/strategyOptimized.ts +0 -42
- package/src/trackers/uniqueKeysTracker.ts +0 -48
- 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/inMemory/uniqueKeysCacheInMemory.d.ts +0 -35
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +0 -37
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +0 -14
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +0 -15
- 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/uniqueKeysSubmitter.d.ts +0 -5
- 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/trackers/strategy/strategyDebug.d.ts +0 -9
- package/types/trackers/strategy/strategyNone.d.ts +0 -10
- package/types/trackers/strategy/strategyOptimized.d.ts +0 -11
- package/types/trackers/uniqueKeysTracker.d.ts +0 -13
- package/types/utils/timeTracker/index.d.ts +0 -70
package/CHANGES.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.7.0 (September XXX, 2022)
|
|
2
|
+
- Updated SDK telemetry to support pluggable storage, partial consumer mode, and synchronizer.
|
|
2
3
|
- Updated storage implementations to improve the performance of split evaluations (i.e., `getTreatment(s)` method calls) when using the default storage in memory.
|
|
3
4
|
|
|
4
5
|
1.6.1 (July 22, 2022)
|
|
@@ -39,8 +39,8 @@ function createUserConsentAPI(params) {
|
|
|
39
39
|
if (events.clear)
|
|
40
40
|
events.clear(); // @ts-ignore
|
|
41
41
|
if (impressions.clear)
|
|
42
|
-
impressions.clear();
|
|
43
|
-
if (impressionCounts
|
|
42
|
+
impressions.clear();
|
|
43
|
+
if (impressionCounts)
|
|
44
44
|
impressionCounts.clear();
|
|
45
45
|
}
|
|
46
46
|
}
|
package/cjs/evaluator/index.js
CHANGED
|
@@ -19,21 +19,21 @@ function treatmentsException(splitNames) {
|
|
|
19
19
|
return evaluations;
|
|
20
20
|
}
|
|
21
21
|
function evaluateFeature(log, key, splitName, attributes, storage) {
|
|
22
|
-
var
|
|
22
|
+
var parsedSplit;
|
|
23
23
|
try {
|
|
24
|
-
|
|
24
|
+
parsedSplit = storage.splits.getSplit(splitName);
|
|
25
25
|
}
|
|
26
26
|
catch (e) {
|
|
27
27
|
// Exception on sync `getSplit` storage. Not possible ATM with InMemory and InLocal storages.
|
|
28
28
|
return treatmentException;
|
|
29
29
|
}
|
|
30
|
-
if ((0, thenable_1.thenable)(
|
|
31
|
-
return
|
|
30
|
+
if ((0, thenable_1.thenable)(parsedSplit)) {
|
|
31
|
+
return parsedSplit.then(function (split) { return getEvaluation(log, split, key, attributes, storage); }).catch(
|
|
32
32
|
// Exception on async `getSplit` storage. For example, when the storage is redis or
|
|
33
33
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
34
34
|
function () { return treatmentException; });
|
|
35
35
|
}
|
|
36
|
-
return getEvaluation(log,
|
|
36
|
+
return getEvaluation(log, parsedSplit, key, attributes, storage);
|
|
37
37
|
}
|
|
38
38
|
exports.evaluateFeature = evaluateFeature;
|
|
39
39
|
function evaluateFeatures(log, key, splitNames, attributes, storage) {
|
package/cjs/listeners/browser.js
CHANGED
|
@@ -74,10 +74,9 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
74
74
|
// Flush impressions & events data if there is user consent
|
|
75
75
|
if ((0, consent_1.isConsentGranted)(this.settings)) {
|
|
76
76
|
var eventsUrl = this.settings.urls.events;
|
|
77
|
-
var sim = this.settings.sync.impressionsMode;
|
|
78
77
|
var extraMetadata = {
|
|
79
78
|
// sim stands for Sync/Split Impressions Mode
|
|
80
|
-
sim:
|
|
79
|
+
sim: this.settings.sync.impressionsMode === constants_1.OPTIMIZED ? constants_1.OPTIMIZED : constants_1.DEBUG
|
|
81
80
|
};
|
|
82
81
|
this._flushData(eventsUrl + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
|
|
83
82
|
this._flushData(eventsUrl + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
|
package/cjs/logger/constants.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SYNC_SPLITS_FETCH_RETRY = exports.POLLING_STOP = exports.POLLING_START = exports.POLLING_SMART_PAUSING = exports.NEW_FACTORY = exports.NEW_SHARED_CLIENT = exports.IMPRESSION_QUEUEING = exports.IMPRESSION = exports.CLIENT_READY = exports.CLIENT_READY_FROM_CACHE = exports.SETTINGS_SPLITS_FILTER = exports.SYNC_TASK_STOP = exports.SYNC_TASK_EXECUTE = exports.SYNC_TASK_START = exports.STREAMING_NEW_MESSAGE = exports.SYNC_SPLITS_SEGMENTS = exports.SYNC_SPLITS_REMOVED = exports.SYNC_SPLITS_NEW = exports.SYNC_SPLITS_FETCH = exports.SYNC_OFFLINE_DATA = exports.RETRIEVE_MANAGER = exports.RETRIEVE_CLIENT_EXISTING = exports.RETRIEVE_CLIENT_DEFAULT = exports.CLEANUP_DEREGISTERING = exports.CLEANUP_REGISTERING = exports.ENGINE_SANITIZE = exports.ENGINE_VALUE = exports.ENGINE_MATCHER_WHITELIST = exports.ENGINE_MATCHER_STARTS_WITH = exports.ENGINE_MATCHER_STRING_INVALID = exports.ENGINE_MATCHER_STRING = exports.ENGINE_MATCHER_SEGMENT = exports.ENGINE_MATCHER_PART_OF = exports.ENGINE_MATCHER_LESS = exports.ENGINE_MATCHER_GREATER = exports.ENGINE_MATCHER_ENDS_WITH = exports.ENGINE_MATCHER_EQUAL_TO_SET = exports.ENGINE_MATCHER_EQUAL = exports.ENGINE_MATCHER_DEPENDENCY_PRE = exports.ENGINE_MATCHER_DEPENDENCY = exports.ENGINE_MATCHER_CONTAINS_STRING = exports.ENGINE_MATCHER_CONTAINS_ANY = exports.ENGINE_MATCHER_CONTAINS_ALL = exports.ENGINE_MATCHER_BOOLEAN = exports.ENGINE_MATCHER_BETWEEN = exports.ENGINE_MATCHER_ALL = exports.ENGINE_BUCKET = exports.ENGINE_COMBINER_IFELSEIF_NO_TREATMENT = exports.ENGINE_COMBINER_IFELSEIF = exports.ENGINE_COMBINER_AND = void 0;
|
|
4
4
|
exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = exports.WARN_API_KEY = exports.WARN_SPLITS_FILTER_EMPTY = exports.WARN_SPLITS_FILTER_INVALID = exports.WARN_SPLITS_FILTER_IGNORED = exports.WARN_INTEGRATION_INVALID = exports.WARN_NOT_EXISTENT_TT = exports.WARN_LOWERCASE_TRAFFIC_TYPE = exports.WARN_NOT_EXISTENT_SPLIT = exports.WARN_TRIMMING = exports.WARN_CONVERTING = exports.WARN_TRIMMING_PROPERTIES = exports.WARN_SETTING_NULL = exports.SUBMITTERS_PUSH_RETRY = exports.SUBMITTERS_PUSH_FAILS = exports.STREAMING_FALLBACK = exports.STREAMING_PARSING_MESSAGE_FAILS = exports.STREAMING_PARSING_ERROR_FAILS = exports.SYNC_SPLITS_FETCH_FAILS = exports.SYNC_MYSEGMENTS_FETCH_RETRY = exports.CLIENT_NOT_READY = exports.CLIENT_NO_LISTENER = exports.ENGINE_VALUE_NO_ATTRIBUTES = exports.ENGINE_VALUE_INVALID = exports.USER_CONSENT_INITIAL = exports.USER_CONSENT_NOT_UPDATED = exports.USER_CONSENT_UPDATED = exports.IMPRESSIONS_TRACKER_SUCCESS = exports.EVENTS_TRACKER_SUCCESS = exports.SYNC_STOP_POLLING = exports.SYNC_CONTINUE_POLLING = exports.SYNC_START_POLLING = exports.SUBMITTERS_PUSH = exports.SUBMITTERS_PUSH_FULL_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = void 0;
|
|
5
|
-
exports.LOG_PREFIX_CLEANUP = exports.
|
|
5
|
+
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = exports.ERROR_INVALID_CONFIG_PARAM = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = void 0;
|
|
6
6
|
/**
|
|
7
7
|
* Message codes used to trim string log messages from commons and client-side API modules,
|
|
8
8
|
* in order to reduce the minimal SDK size for Browser and eventually other client-side environments.
|
|
@@ -144,5 +144,4 @@ exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC + ':polling-manager: '
|
|
|
144
144
|
exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC + ':submitter: ';
|
|
145
145
|
exports.LOG_PREFIX_IMPRESSIONS_TRACKER = 'impressions-tracker: ';
|
|
146
146
|
exports.LOG_PREFIX_EVENTS_TRACKER = 'events-tracker: ';
|
|
147
|
-
exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = 'unique-keys-tracker: ';
|
|
148
147
|
exports.LOG_PREFIX_CLEANUP = 'cleanup: ';
|
package/cjs/sdkClient/client.js
CHANGED
|
@@ -9,6 +9,15 @@ var trafficTypeExistance_1 = require("../utils/inputValidation/trafficTypeExista
|
|
|
9
9
|
var labels_1 = require("../utils/labels");
|
|
10
10
|
var constants_1 = require("../utils/constants");
|
|
11
11
|
var constants_2 = require("../logger/constants");
|
|
12
|
+
var utils_1 = require("../trackers/impressionObserver/utils");
|
|
13
|
+
var treatmentNotReady = { treatment: constants_1.CONTROL, label: labels_1.SDK_NOT_READY };
|
|
14
|
+
function treatmentsNotReady(splitNames) {
|
|
15
|
+
var evaluations = {};
|
|
16
|
+
splitNames.forEach(function (splitName) {
|
|
17
|
+
evaluations[splitName] = treatmentNotReady;
|
|
18
|
+
});
|
|
19
|
+
return evaluations;
|
|
20
|
+
}
|
|
12
21
|
/**
|
|
13
22
|
* Creator of base client with getTreatments and track methods.
|
|
14
23
|
*/
|
|
@@ -25,7 +34,11 @@ function clientFactory(params) {
|
|
|
25
34
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
26
35
|
return treatment;
|
|
27
36
|
};
|
|
28
|
-
var evaluation = (
|
|
37
|
+
var evaluation = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
38
|
+
(0, evaluator_1.evaluateFeature)(log, key, splitName, attributes, storage) :
|
|
39
|
+
(0, utils_1.isStorageSync)(settings) ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
40
|
+
treatmentNotReady :
|
|
41
|
+
Promise.resolve(treatmentNotReady); // Promisify if async
|
|
29
42
|
return (0, thenable_1.thenable)(evaluation) ? evaluation.then(function (res) { return wrapUp(res); }) : wrapUp(evaluation);
|
|
30
43
|
}
|
|
31
44
|
function getTreatmentWithConfig(key, splitName, attributes) {
|
|
@@ -44,7 +57,11 @@ function clientFactory(params) {
|
|
|
44
57
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
45
58
|
return treatments;
|
|
46
59
|
};
|
|
47
|
-
var evaluations = (
|
|
60
|
+
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
61
|
+
(0, evaluator_1.evaluateFeatures)(log, key, splitNames, attributes, storage) :
|
|
62
|
+
(0, utils_1.isStorageSync)(settings) ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
63
|
+
treatmentsNotReady(splitNames) :
|
|
64
|
+
Promise.resolve(treatmentsNotReady(splitNames)); // Promisify if async
|
|
48
65
|
return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
49
66
|
}
|
|
50
67
|
function getTreatmentsWithConfig(key, splitNames, attributes) {
|
|
@@ -52,13 +69,8 @@ function clientFactory(params) {
|
|
|
52
69
|
}
|
|
53
70
|
// Internal function
|
|
54
71
|
function processEvaluation(evaluation, splitName, key, attributes, withConfig, invokingMethodName, queue) {
|
|
55
|
-
var isSdkReady = readinessManager.isReady() || readinessManager.isReadyFromCache();
|
|
56
72
|
var matchingKey = (0, key_1.getMatching)(key);
|
|
57
73
|
var bucketingKey = (0, key_1.getBucketing)(key);
|
|
58
|
-
// If the SDK was not ready, treatment may be incorrect due to having Splits but not segments data.
|
|
59
|
-
if (!isSdkReady) {
|
|
60
|
-
evaluation = { treatment: constants_1.CONTROL, label: labels_1.SDK_NOT_READY };
|
|
61
|
-
}
|
|
62
74
|
var treatment = evaluation.treatment, label = evaluation.label, changeNumber = evaluation.changeNumber, _a = evaluation.config, config = _a === void 0 ? null : _a;
|
|
63
75
|
log.info(constants_2.IMPRESSION, [splitName, matchingKey, treatment, label]);
|
|
64
76
|
if ((0, splitExistance_1.validateSplitExistance)(log, readinessManager, splitName, label, invokingMethodName)) {
|
|
@@ -9,7 +9,7 @@ var clientInputValidation_1 = require("./clientInputValidation");
|
|
|
9
9
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
10
10
|
*/
|
|
11
11
|
function sdkClientFactory(params, isSharedClient) {
|
|
12
|
-
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker
|
|
12
|
+
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker;
|
|
13
13
|
return (0, objectAssign_1.objectAssign)(
|
|
14
14
|
// Proto-linkage of the readiness Event Emitter
|
|
15
15
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
@@ -31,8 +31,6 @@ function sdkClientFactory(params, isSharedClient) {
|
|
|
31
31
|
// Release the API Key if it is the main client
|
|
32
32
|
if (!isSharedClient)
|
|
33
33
|
(0, apiKey_1.releaseApiKey)(settings.core.authorizationKey);
|
|
34
|
-
if (uniqueKeysTracker)
|
|
35
|
-
uniqueKeysTracker.stop();
|
|
36
34
|
// Cleanup storage
|
|
37
35
|
return storage.destroy();
|
|
38
36
|
});
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -13,16 +13,11 @@ var constants_1 = require("../logger/constants");
|
|
|
13
13
|
var metadataBuilder_1 = require("../storages/metadataBuilder");
|
|
14
14
|
var constants_2 = require("../readiness/constants");
|
|
15
15
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
16
|
-
var strategyDebug_1 = require("../trackers/strategy/strategyDebug");
|
|
17
|
-
var strategyOptimized_1 = require("../trackers/strategy/strategyOptimized");
|
|
18
|
-
var strategyNone_1 = require("../trackers/strategy/strategyNone");
|
|
19
|
-
var uniqueKeysTracker_1 = require("../trackers/uniqueKeysTracker");
|
|
20
|
-
var constants_3 = require("../utils/constants");
|
|
21
16
|
/**
|
|
22
17
|
* Modular SDK factory
|
|
23
18
|
*/
|
|
24
19
|
function sdkFactory(params) {
|
|
25
|
-
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
|
|
20
|
+
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;
|
|
26
21
|
var log = settings.log;
|
|
27
22
|
// @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid API Key, etc.
|
|
28
23
|
// On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
|
|
@@ -34,17 +29,12 @@ function sdkFactory(params) {
|
|
|
34
29
|
var storageFactoryParams = {
|
|
35
30
|
impressionsQueueSize: settings.scheduler.impressionsQueueSize,
|
|
36
31
|
eventsQueueSize: settings.scheduler.eventsQueueSize,
|
|
37
|
-
uniqueKeysCacheSize: settings.scheduler.uniqueKeysCacheSize,
|
|
38
|
-
impressionCountsQueueSize: settings.scheduler.impressionCountsQueueSize,
|
|
39
|
-
impressionCountsRefreshRate: settings.scheduler.impressionCountsRefreshRate,
|
|
40
|
-
uniqueKeysRefreshRate: settings.scheduler.uniqueKeysRefreshRate,
|
|
41
32
|
optimize: (0, utils_1.shouldBeOptimized)(settings),
|
|
42
33
|
// ATM, only used by InLocalStorage
|
|
43
34
|
matchingKey: (0, key_1.getMatching)(settings.core.key),
|
|
44
35
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
45
36
|
// ATM, only used by PluggableStorage
|
|
46
37
|
mode: settings.mode,
|
|
47
|
-
impressionsMode: settings.sync.impressionsMode,
|
|
48
38
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
|
|
49
39
|
// or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
|
|
50
40
|
onReadyCb: function (error) {
|
|
@@ -60,24 +50,13 @@ function sdkFactory(params) {
|
|
|
60
50
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
61
51
|
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
62
52
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
63
|
-
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
switch (storageFactoryParams.impressionsMode) {
|
|
67
|
-
case constants_3.OPTIMIZED:
|
|
68
|
-
strategy = (0, strategyOptimized_1.strategyOptimizedFactory)(observer, storage.impressionCounts);
|
|
69
|
-
break;
|
|
70
|
-
case constants_3.NONE:
|
|
71
|
-
strategy = (0, strategyNone_1.strategyNoneFactory)(storage.impressionCounts, uniqueKeysTracker);
|
|
72
|
-
break;
|
|
73
|
-
default:
|
|
74
|
-
strategy = (0, strategyDebug_1.strategyDebugFactory)(observer);
|
|
75
|
-
}
|
|
76
|
-
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
|
|
53
|
+
// trackers
|
|
54
|
+
var observer = impressionsObserverFactory && impressionsObserverFactory();
|
|
55
|
+
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, integrationsManager, observer, storage.impressionCounts, storage.telemetry);
|
|
77
56
|
var eventTracker = (0, eventTracker_1.eventTrackerFactory)(settings, storage.events, integrationsManager, storage.telemetry);
|
|
78
57
|
// splitApi is used by SyncManager and Browser signal listener
|
|
79
58
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
80
|
-
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker,
|
|
59
|
+
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
81
60
|
var syncManager = syncManagerFactory && syncManagerFactory(ctx);
|
|
82
61
|
ctx.syncManager = syncManager;
|
|
83
62
|
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
package/cjs/services/splitApi.js
CHANGED
|
@@ -90,33 +90,13 @@ function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
90
90
|
var url = urls.events + "/testImpressions/count";
|
|
91
91
|
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.IMPRESSIONS_COUNT));
|
|
92
92
|
},
|
|
93
|
-
|
|
94
|
-
* Post unique keys for client side.
|
|
95
|
-
*
|
|
96
|
-
* @param body unique keys payload
|
|
97
|
-
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
98
|
-
*/
|
|
99
|
-
postUniqueKeysBulkCs: function (body, headers) {
|
|
100
|
-
var url = urls.telemetry + "/v1/keys/cs";
|
|
101
|
-
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
|
|
102
|
-
},
|
|
103
|
-
/**
|
|
104
|
-
* Post unique keys for server side.
|
|
105
|
-
*
|
|
106
|
-
* @param body unique keys payload
|
|
107
|
-
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
108
|
-
*/
|
|
109
|
-
postUniqueKeysBulkSs: function (body, headers) {
|
|
110
|
-
var url = urls.telemetry + "/v1/keys/ss";
|
|
111
|
-
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
|
|
112
|
-
},
|
|
113
|
-
postMetricsConfig: function (body) {
|
|
93
|
+
postMetricsConfig: function (body, headers) {
|
|
114
94
|
var url = urls.telemetry + "/v1/metrics/config";
|
|
115
|
-
return splitHttpClient(url, { method: 'POST', body: body }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
|
|
95
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
|
|
116
96
|
},
|
|
117
|
-
postMetricsUsage: function (body) {
|
|
97
|
+
postMetricsUsage: function (body, headers) {
|
|
118
98
|
var url = urls.telemetry + "/v1/metrics/usage";
|
|
119
|
-
return splitHttpClient(url, { method: 'POST', body: body }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
|
|
99
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
|
|
120
100
|
}
|
|
121
101
|
};
|
|
122
102
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeyBuilderSS = void 0;
|
|
3
|
+
exports.parseLatencyField = exports.parseExceptionField = exports.parseMetadata = exports.KeyBuilderSS = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var KeyBuilder_1 = require("./KeyBuilder");
|
|
6
|
-
var
|
|
6
|
+
var TelemetryCacheInMemory_1 = require("./inMemory/TelemetryCacheInMemory");
|
|
7
|
+
var METHOD_NAMES = {
|
|
7
8
|
t: 'treatment',
|
|
8
9
|
ts: 'treatments',
|
|
9
10
|
tc: 'treatmentWithConfig',
|
|
@@ -14,7 +15,10 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
14
15
|
(0, tslib_1.__extends)(KeyBuilderSS, _super);
|
|
15
16
|
function KeyBuilderSS(prefix, metadata) {
|
|
16
17
|
var _this = _super.call(this, prefix) || this;
|
|
17
|
-
_this.
|
|
18
|
+
_this.latencyPrefix = _this.prefix + ".telemetry.latencies";
|
|
19
|
+
_this.exceptionPrefix = _this.prefix + ".telemetry.exceptions";
|
|
20
|
+
_this.initPrefix = _this.prefix + ".telemetry.init";
|
|
21
|
+
_this.versionablePrefix = metadata.s + "/" + metadata.n + "/" + metadata.i;
|
|
18
22
|
return _this;
|
|
19
23
|
}
|
|
20
24
|
KeyBuilderSS.prototype.buildRegisteredSegmentsKey = function () {
|
|
@@ -23,12 +27,6 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
23
27
|
KeyBuilderSS.prototype.buildImpressionsKey = function () {
|
|
24
28
|
return this.prefix + ".impressions";
|
|
25
29
|
};
|
|
26
|
-
KeyBuilderSS.prototype.buildImpressionsCountKey = function () {
|
|
27
|
-
return this.prefix + ".impressions.count";
|
|
28
|
-
};
|
|
29
|
-
KeyBuilderSS.prototype.buildUniqueKeysKey = function () {
|
|
30
|
-
return this.prefix + ".uniquekeys";
|
|
31
|
-
};
|
|
32
30
|
KeyBuilderSS.prototype.buildEventsKey = function () {
|
|
33
31
|
return this.prefix + ".events";
|
|
34
32
|
};
|
|
@@ -37,17 +35,52 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
37
35
|
};
|
|
38
36
|
/* Telemetry keys */
|
|
39
37
|
KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
|
|
40
|
-
return this.
|
|
38
|
+
return this.latencyPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method] + "/" + bucket;
|
|
41
39
|
};
|
|
42
40
|
KeyBuilderSS.prototype.buildExceptionKey = function (method) {
|
|
43
|
-
return this.
|
|
41
|
+
return this.exceptionPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method];
|
|
44
42
|
};
|
|
45
43
|
KeyBuilderSS.prototype.buildInitKey = function () {
|
|
46
|
-
return this.
|
|
47
|
-
};
|
|
48
|
-
KeyBuilderSS.prototype.buildVersionablePrefix = function () {
|
|
49
|
-
return this.metadata.s + "/" + this.metadata.n + "/" + this.metadata.i;
|
|
44
|
+
return this.initPrefix + "::" + this.versionablePrefix;
|
|
50
45
|
};
|
|
51
46
|
return KeyBuilderSS;
|
|
52
47
|
}(KeyBuilder_1.KeyBuilder));
|
|
53
48
|
exports.KeyBuilderSS = KeyBuilderSS;
|
|
49
|
+
// Used by consumer methods of TelemetryCacheInRedis and TelemetryCachePluggable
|
|
50
|
+
var REVERSE_METHOD_NAMES = Object.keys(METHOD_NAMES).reduce(function (acc, key) {
|
|
51
|
+
acc[METHOD_NAMES[key]] = key;
|
|
52
|
+
return acc;
|
|
53
|
+
}, {});
|
|
54
|
+
function parseMetadata(field) {
|
|
55
|
+
var parts = field.split('/');
|
|
56
|
+
if (parts.length !== 3)
|
|
57
|
+
return "invalid subsection count. Expected 4, got: " + parts.length;
|
|
58
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */;
|
|
59
|
+
return [JSON.stringify({ s: s, n: n, i: i })];
|
|
60
|
+
}
|
|
61
|
+
exports.parseMetadata = parseMetadata;
|
|
62
|
+
function parseExceptionField(field) {
|
|
63
|
+
var parts = field.split('/');
|
|
64
|
+
if (parts.length !== 4)
|
|
65
|
+
return "invalid subsection count. Expected 4, got: " + parts.length;
|
|
66
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3];
|
|
67
|
+
var method = REVERSE_METHOD_NAMES[m];
|
|
68
|
+
if (!method)
|
|
69
|
+
return "unknown method '" + m + "'";
|
|
70
|
+
return [JSON.stringify({ s: s, n: n, i: i }), method];
|
|
71
|
+
}
|
|
72
|
+
exports.parseExceptionField = parseExceptionField;
|
|
73
|
+
function parseLatencyField(field) {
|
|
74
|
+
var parts = field.split('/');
|
|
75
|
+
if (parts.length !== 5)
|
|
76
|
+
return "invalid subsection count. Expected 5, got: " + parts.length;
|
|
77
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3], b = parts[4];
|
|
78
|
+
var method = REVERSE_METHOD_NAMES[m];
|
|
79
|
+
if (!method)
|
|
80
|
+
return "unknown method '" + m + "'";
|
|
81
|
+
var bucket = parseInt(b);
|
|
82
|
+
if (isNaN(bucket) || bucket >= TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT)
|
|
83
|
+
return "invalid bucket. Expected a number between 0 and 22, got: " + b;
|
|
84
|
+
return [JSON.stringify({ s: s, n: n, i: i }), method, bucket];
|
|
85
|
+
}
|
|
86
|
+
exports.parseLatencyField = parseLatencyField;
|
|
@@ -16,7 +16,6 @@ var InMemoryStorageCS_1 = require("../inMemory/InMemoryStorageCS");
|
|
|
16
16
|
var constants_1 = require("./constants");
|
|
17
17
|
var constants_2 = require("../../utils/constants");
|
|
18
18
|
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
19
|
-
var uniqueKeysCacheInMemoryCS_1 = require("../inMemory/uniqueKeysCacheInMemoryCS");
|
|
20
19
|
/**
|
|
21
20
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
22
21
|
*/
|
|
@@ -38,16 +37,13 @@ function InLocalStorage(options) {
|
|
|
38
37
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
39
38
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
40
39
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
41
|
-
telemetry:
|
|
42
|
-
uniqueKeys: params.impressionsMode === constants_2.NONE ? new uniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
40
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
43
41
|
destroy: function () {
|
|
44
|
-
var _a;
|
|
45
42
|
this.splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
|
|
46
43
|
this.segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
47
44
|
this.impressions.clear();
|
|
48
45
|
this.impressionCounts && this.impressionCounts.clear();
|
|
49
46
|
this.events.clear();
|
|
50
|
-
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
51
47
|
},
|
|
52
48
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
|
|
53
49
|
shared: function (matchingKey) {
|
|
@@ -2,13 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImpressionCountsCacheInMemory = void 0;
|
|
4
4
|
var time_1 = require("../../utils/time");
|
|
5
|
-
var constants_1 = require("../inRedis/constants");
|
|
6
5
|
var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
7
|
-
function ImpressionCountsCacheInMemory(
|
|
8
|
-
if (impressionCountsCacheSize === void 0) { impressionCountsCacheSize = constants_1.DEFAULT_CACHE_SIZE; }
|
|
6
|
+
function ImpressionCountsCacheInMemory() {
|
|
9
7
|
this.cache = {};
|
|
10
|
-
this.cacheSize = 0;
|
|
11
|
-
this.maxStorage = impressionCountsCacheSize;
|
|
12
8
|
}
|
|
13
9
|
/**
|
|
14
10
|
* Builds key to be stored in the cache with the featureName and the timeFrame truncated.
|
|
@@ -23,13 +19,6 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
|
23
19
|
var key = this._makeKey(featureName, timeFrame);
|
|
24
20
|
var currentAmount = this.cache[key];
|
|
25
21
|
this.cache[key] = currentAmount ? currentAmount + amount : amount;
|
|
26
|
-
if (this.onFullQueue) {
|
|
27
|
-
this.cacheSize = this.cacheSize + amount;
|
|
28
|
-
if (this.cacheSize >= this.maxStorage) {
|
|
29
|
-
this.onFullQueue();
|
|
30
|
-
this.cacheSize = 0;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
22
|
};
|
|
34
23
|
/**
|
|
35
24
|
* Pop the collected data, used as payload for posting.
|
|
@@ -8,7 +8,6 @@ var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
|
|
|
8
8
|
var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory");
|
|
9
9
|
var constants_1 = require("../../utils/constants");
|
|
10
10
|
var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
|
|
11
|
-
var uniqueKeysCacheInMemory_1 = require("./uniqueKeysCacheInMemory");
|
|
12
11
|
/**
|
|
13
12
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
14
13
|
*
|
|
@@ -19,19 +18,16 @@ function InMemoryStorageFactory(params) {
|
|
|
19
18
|
splits: new SplitsCacheInMemory_1.SplitsCacheInMemory(),
|
|
20
19
|
segments: new SegmentsCacheInMemory_1.SegmentsCacheInMemory(),
|
|
21
20
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
22
|
-
impressionCounts: params.
|
|
21
|
+
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
23
22
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
24
|
-
telemetry:
|
|
25
|
-
uniqueKeys: params.impressionsMode === constants_1.NONE ? new uniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory(params.uniqueKeysCacheSize) : undefined,
|
|
23
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
26
24
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
27
25
|
destroy: function () {
|
|
28
|
-
var _a;
|
|
29
26
|
this.splits.clear();
|
|
30
27
|
this.segments.clear();
|
|
31
28
|
this.impressions.clear();
|
|
32
29
|
this.impressionCounts && this.impressionCounts.clear();
|
|
33
30
|
this.events.clear();
|
|
34
|
-
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
35
31
|
}
|
|
36
32
|
};
|
|
37
33
|
}
|
|
@@ -8,7 +8,6 @@ var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
|
|
|
8
8
|
var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory");
|
|
9
9
|
var constants_1 = require("../../utils/constants");
|
|
10
10
|
var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
|
|
11
|
-
var uniqueKeysCacheInMemoryCS_1 = require("./uniqueKeysCacheInMemoryCS");
|
|
12
11
|
/**
|
|
13
12
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
14
13
|
*
|
|
@@ -19,19 +18,16 @@ function InMemoryStorageCSFactory(params) {
|
|
|
19
18
|
splits: new SplitsCacheInMemory_1.SplitsCacheInMemory(),
|
|
20
19
|
segments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
|
|
21
20
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
22
|
-
impressionCounts: params.
|
|
21
|
+
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
23
22
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
24
|
-
telemetry:
|
|
25
|
-
uniqueKeys: params.impressionsMode === constants_1.NONE ? new uniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(params.uniqueKeysCacheSize) : undefined,
|
|
23
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
26
24
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
27
25
|
destroy: function () {
|
|
28
|
-
var _a;
|
|
29
26
|
this.splits.clear();
|
|
30
27
|
this.segments.clear();
|
|
31
28
|
this.impressions.clear();
|
|
32
29
|
this.impressionCounts && this.impressionCounts.clear();
|
|
33
30
|
this.events.clear();
|
|
34
|
-
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
35
31
|
},
|
|
36
32
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are unique per key)
|
|
37
33
|
shared: function () {
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TelemetryCacheInMemory = exports.shouldRecordTelemetry = void 0;
|
|
3
|
+
exports.TelemetryCacheInMemory = exports.shouldRecordTelemetry = exports.newBuckets = exports.MAX_LATENCY_BUCKET_COUNT = void 0;
|
|
4
|
+
var constants_1 = require("../../utils/constants");
|
|
4
5
|
var findLatencyIndex_1 = require("../findLatencyIndex");
|
|
5
6
|
var MAX_STREAMING_EVENTS = 20;
|
|
6
7
|
var MAX_TAGS = 10;
|
|
8
|
+
exports.MAX_LATENCY_BUCKET_COUNT = 23;
|
|
7
9
|
function newBuckets() {
|
|
8
|
-
|
|
9
|
-
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
10
|
+
return new Array(exports.MAX_LATENCY_BUCKET_COUNT).fill(0);
|
|
10
11
|
}
|
|
12
|
+
exports.newBuckets = newBuckets;
|
|
11
13
|
var ACCEPTANCE_RANGE = 0.001;
|
|
12
14
|
/**
|
|
13
|
-
*
|
|
15
|
+
* Record telemetry if mode is not localhost.
|
|
16
|
+
* All factory instances track telemetry on server-side, and 0.1% on client-side.
|
|
14
17
|
*/
|
|
15
|
-
function shouldRecordTelemetry() {
|
|
16
|
-
return Math.random() <= ACCEPTANCE_RANGE;
|
|
18
|
+
function shouldRecordTelemetry(params) {
|
|
19
|
+
return params.mode !== constants_1.LOCALHOST_MODE && (params.matchingKey === undefined || Math.random() <= ACCEPTANCE_RANGE);
|
|
17
20
|
}
|
|
18
21
|
exports.shouldRecordTelemetry = shouldRecordTelemetry;
|
|
19
22
|
var TelemetryCacheInMemory = /** @class */ (function () {
|
|
@@ -42,7 +42,7 @@ var EventsCacheInRedis = /** @class */ (function () {
|
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
44
|
* Pop the given number of events from the storage.
|
|
45
|
-
* The returned promise rejects if the
|
|
45
|
+
* The returned promise rejects if the redis operation fails.
|
|
46
46
|
*
|
|
47
47
|
* NOTE: this method doesn't take into account MAX_EVENT_SIZE or MAX_QUEUE_BYTE_SIZE limits.
|
|
48
48
|
* It is the submitter responsability to handle that.
|
|
@@ -1,9 +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");
|
|
4
5
|
var findLatencyIndex_1 = require("../findLatencyIndex");
|
|
5
6
|
var telemetrySubmitter_1 = require("../../sync/submitters/telemetrySubmitter");
|
|
6
7
|
var constants_1 = require("../../utils/constants");
|
|
8
|
+
var lang_1 = require("../../utils/lang");
|
|
9
|
+
var maps_1 = require("../../utils/lang/maps");
|
|
10
|
+
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
7
11
|
var TelemetryCacheInRedis = /** @class */ (function () {
|
|
8
12
|
/**
|
|
9
13
|
* Create a Telemetry cache that uses Redis as storage.
|
|
@@ -31,6 +35,102 @@ var TelemetryCacheInRedis = /** @class */ (function () {
|
|
|
31
35
|
var value = JSON.stringify((0, telemetrySubmitter_1.getTelemetryConfigStats)(constants_1.CONSUMER_MODE, constants_1.STORAGE_REDIS));
|
|
32
36
|
return this.redis.hset(key, field, value).catch(function () { });
|
|
33
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Pop telemetry latencies.
|
|
40
|
+
* The returned promise rejects if redis operations fail.
|
|
41
|
+
*/
|
|
42
|
+
TelemetryCacheInRedis.prototype.popLatencies = function () {
|
|
43
|
+
var _this = this;
|
|
44
|
+
return this.redis.hgetall(this.keys.latencyPrefix).then(function (latencies) {
|
|
45
|
+
var result = new maps_1._Map();
|
|
46
|
+
Object.keys(latencies).forEach(function (field) {
|
|
47
|
+
var parsedField = (0, KeyBuilderSS_1.parseLatencyField)(field);
|
|
48
|
+
if ((0, lang_1.isString)(parsedField)) {
|
|
49
|
+
_this.log.error("Ignoring invalid latency field: " + field + ": " + parsedField);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
var count = parseInt(latencies[field]);
|
|
53
|
+
if ((0, lang_1.isNaNNumber)(count)) {
|
|
54
|
+
_this.log.error("Ignoring latency with invalid count: " + latencies[field]);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
var metadata = parsedField[0], method = parsedField[1], bucket = parsedField[2];
|
|
58
|
+
if (bucket >= TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT) {
|
|
59
|
+
_this.log.error("Ignoring latency with invalid bucket: " + bucket);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!result.has(metadata))
|
|
63
|
+
result.set(metadata, {
|
|
64
|
+
t: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
65
|
+
ts: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
66
|
+
tc: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
67
|
+
tcs: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
68
|
+
tr: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
69
|
+
});
|
|
70
|
+
result.get(metadata)[method][bucket] = count;
|
|
71
|
+
});
|
|
72
|
+
return _this.redis.del(_this.keys.latencyPrefix).then(function () { return result; });
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Pop telemetry exceptions.
|
|
77
|
+
* The returned promise rejects if redis operations fail.
|
|
78
|
+
*/
|
|
79
|
+
TelemetryCacheInRedis.prototype.popExceptions = function () {
|
|
80
|
+
var _this = this;
|
|
81
|
+
return this.redis.hgetall(this.keys.exceptionPrefix).then(function (exceptions) {
|
|
82
|
+
var result = new maps_1._Map();
|
|
83
|
+
Object.keys(exceptions).forEach(function (field) {
|
|
84
|
+
var parsedField = (0, KeyBuilderSS_1.parseExceptionField)(field);
|
|
85
|
+
if ((0, lang_1.isString)(parsedField)) {
|
|
86
|
+
_this.log.error("Ignoring invalid exception field: " + field + ": " + parsedField);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
var count = parseInt(exceptions[field]);
|
|
90
|
+
if ((0, lang_1.isNaNNumber)(count)) {
|
|
91
|
+
_this.log.error("Ignoring exception with invalid count: " + exceptions[field]);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
var metadata = parsedField[0], method = parsedField[1];
|
|
95
|
+
if (!result.has(metadata))
|
|
96
|
+
result.set(metadata, {
|
|
97
|
+
t: 0,
|
|
98
|
+
ts: 0,
|
|
99
|
+
tc: 0,
|
|
100
|
+
tcs: 0,
|
|
101
|
+
tr: 0,
|
|
102
|
+
});
|
|
103
|
+
result.get(metadata)[method] = count;
|
|
104
|
+
});
|
|
105
|
+
return _this.redis.del(_this.keys.exceptionPrefix).then(function () { return result; });
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Pop telemetry configs.
|
|
110
|
+
* The returned promise rejects if redis operations fail.
|
|
111
|
+
*/
|
|
112
|
+
TelemetryCacheInRedis.prototype.popConfigs = function () {
|
|
113
|
+
var _this = this;
|
|
114
|
+
return this.redis.hgetall(this.keys.initPrefix).then(function (configs) {
|
|
115
|
+
var result = new maps_1._Map();
|
|
116
|
+
Object.keys(configs).forEach(function (field) {
|
|
117
|
+
var parsedField = (0, KeyBuilderSS_1.parseMetadata)(field);
|
|
118
|
+
if ((0, lang_1.isString)(parsedField)) {
|
|
119
|
+
_this.log.error("Ignoring invalid config field: " + field + ": " + parsedField);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
var metadata = parsedField[0];
|
|
123
|
+
try {
|
|
124
|
+
var config = JSON.parse(configs[field]);
|
|
125
|
+
result.set(metadata, config);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
_this.log.error("Ignoring invalid config: " + configs[field]);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return _this.redis.del(_this.keys.initPrefix).then(function () { return result; });
|
|
132
|
+
});
|
|
133
|
+
};
|
|
34
134
|
return TelemetryCacheInRedis;
|
|
35
135
|
}());
|
|
36
136
|
exports.TelemetryCacheInRedis = TelemetryCacheInRedis;
|