@splitsoftware/splitio-commons 1.3.1 → 1.3.2-rc.2
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/consent/sdkUserConsent.js +1 -1
- package/cjs/listeners/browser.js +5 -4
- package/cjs/logger/constants.js +2 -1
- package/cjs/logger/messages/error.js +2 -1
- package/cjs/logger/messages/info.js +3 -3
- package/cjs/logger/messages/warn.js +2 -2
- package/cjs/sdkClient/client.js +17 -3
- package/cjs/sdkClient/sdkClient.js +4 -1
- package/cjs/sdkFactory/index.js +16 -19
- package/cjs/services/splitApi.js +15 -14
- package/cjs/services/splitHttpClient.js +4 -1
- package/cjs/storages/AbstractSegmentsCacheSync.js +0 -5
- package/cjs/storages/KeyBuilderSS.js +12 -19
- package/cjs/storages/findLatencyIndex.js +11 -6
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +13 -1
- package/cjs/storages/inLocalStorage/index.js +4 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +2 -0
- package/cjs/storages/inMemory/InMemoryStorageCS.js +3 -0
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +6 -0
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +6 -0
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +165 -0
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +29 -0
- package/cjs/storages/inRedis/index.js +2 -4
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +27 -0
- package/cjs/storages/pluggable/index.js +2 -1
- package/cjs/sync/polling/pollingManagerCS.js +1 -1
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +2 -2
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +0 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -8
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +3 -6
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +20 -13
- package/cjs/sync/streaming/SSEHandler/index.js +21 -15
- package/cjs/sync/streaming/pushManager.js +7 -4
- package/cjs/sync/submitters/eventsSubmitter.js +28 -0
- package/cjs/sync/submitters/{impressionCountsSyncTask.js → impressionCountsSubmitter.js} +10 -7
- package/cjs/sync/submitters/{impressionsSyncTask.js → impressionsSubmitter.js} +8 -8
- package/cjs/sync/submitters/submitter.js +66 -0
- package/cjs/sync/submitters/submitterManager.js +12 -10
- package/cjs/sync/submitters/telemetrySubmitter.js +128 -0
- package/cjs/sync/syncManagerOnline.js +6 -2
- package/cjs/trackers/eventTracker.js +5 -1
- package/cjs/trackers/impressionsTracker.js +9 -1
- package/cjs/trackers/telemetryTracker.js +65 -0
- package/cjs/utils/constants/index.js +40 -1
- package/cjs/utils/inputValidation/apiKey.js +12 -11
- package/cjs/utils/settingsValidation/index.js +35 -11
- package/cjs/utils/settingsValidation/url.js +4 -0
- package/cjs/utils/timeTracker/index.js +1 -0
- package/cjs/utils/timeTracker/timer.js +2 -2
- package/esm/consent/sdkUserConsent.js +1 -1
- package/esm/listeners/browser.js +3 -2
- package/esm/logger/constants.js +1 -0
- package/esm/logger/messages/error.js +2 -1
- package/esm/logger/messages/info.js +3 -3
- package/esm/logger/messages/warn.js +2 -2
- package/esm/sdkClient/client.js +18 -4
- package/esm/sdkClient/sdkClient.js +4 -1
- package/esm/sdkFactory/index.js +16 -19
- package/esm/services/splitApi.js +15 -14
- package/esm/services/splitHttpClient.js +4 -1
- package/esm/storages/AbstractSegmentsCacheSync.js +0 -5
- package/esm/storages/KeyBuilderSS.js +12 -19
- package/esm/storages/findLatencyIndex.js +11 -6
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +13 -1
- package/esm/storages/inLocalStorage/index.js +5 -2
- package/esm/storages/inMemory/InMemoryStorage.js +3 -1
- package/esm/storages/inMemory/InMemoryStorageCS.js +4 -1
- package/esm/storages/inMemory/MySegmentsCacheInMemory.js +6 -0
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +6 -0
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +161 -0
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +26 -0
- package/esm/storages/inRedis/index.js +2 -4
- package/esm/storages/pluggable/TelemetryCachePluggable.js +24 -0
- package/esm/storages/pluggable/index.js +2 -1
- package/esm/sync/polling/pollingManagerCS.js +1 -1
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +2 -2
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +0 -3
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -8
- package/esm/sync/polling/updaters/splitChangesUpdater.js +3 -6
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +8 -1
- package/esm/sync/streaming/SSEHandler/index.js +21 -15
- package/esm/sync/streaming/pushManager.js +7 -4
- package/esm/sync/submitters/eventsSubmitter.js +24 -0
- package/esm/sync/submitters/{impressionCountsSyncTask.js → impressionCountsSubmitter.js} +8 -5
- package/esm/sync/submitters/{impressionsSyncTask.js → impressionsSubmitter.js} +6 -6
- package/esm/sync/submitters/submitter.js +61 -0
- package/esm/sync/submitters/submitterManager.js +12 -10
- package/esm/sync/submitters/telemetrySubmitter.js +122 -0
- package/esm/sync/syncManagerOnline.js +6 -2
- package/esm/trackers/eventTracker.js +6 -2
- package/esm/trackers/impressionsTracker.js +10 -2
- package/esm/trackers/telemetryTracker.js +61 -0
- package/esm/utils/constants/index.js +38 -0
- package/esm/utils/inputValidation/apiKey.js +2 -1
- package/esm/utils/settingsValidation/index.js +34 -10
- package/esm/utils/settingsValidation/url.js +4 -0
- package/esm/utils/timeTracker/index.js +1 -0
- package/esm/utils/timeTracker/timer.js +2 -2
- package/package.json +1 -1
- package/src/consent/sdkUserConsent.ts +1 -1
- package/src/listeners/browser.ts +3 -2
- package/src/logger/constants.ts +1 -0
- package/src/logger/messages/error.ts +2 -1
- package/src/logger/messages/info.ts +3 -3
- package/src/logger/messages/warn.ts +2 -2
- package/src/sdkClient/client.ts +23 -4
- package/src/sdkClient/sdkClient.ts +4 -1
- package/src/sdkFactory/index.ts +22 -24
- package/src/sdkFactory/types.ts +32 -15
- package/src/services/splitApi.ts +17 -14
- package/src/services/splitHttpClient.ts +6 -3
- package/src/services/types.ts +7 -5
- package/src/storages/AbstractSegmentsCacheSync.ts +8 -3
- package/src/storages/KeyBuilderSS.ts +13 -50
- package/src/storages/findLatencyIndex.ts +12 -3
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +13 -1
- package/src/storages/inLocalStorage/index.ts +5 -2
- package/src/storages/inMemory/InMemoryStorage.ts +3 -1
- package/src/storages/inMemory/InMemoryStorageCS.ts +4 -1
- package/src/storages/inMemory/MySegmentsCacheInMemory.ts +8 -0
- package/src/storages/inMemory/SegmentsCacheInMemory.ts +6 -0
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +210 -0
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +29 -0
- package/src/storages/inRedis/index.ts +2 -4
- package/src/storages/pluggable/TelemetryCachePluggable.ts +26 -0
- package/src/storages/pluggable/index.ts +2 -1
- package/src/storages/types.ts +84 -32
- package/src/sync/offline/syncManagerOffline.ts +4 -3
- package/src/sync/polling/pollingManagerCS.ts +3 -3
- package/src/sync/polling/pollingManagerSS.ts +2 -2
- package/src/sync/polling/syncTasks/splitsSyncTask.ts +2 -0
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +0 -4
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +2 -10
- package/src/sync/polling/updaters/splitChangesUpdater.ts +3 -6
- package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +11 -1
- package/src/sync/streaming/SSEHandler/index.ts +21 -14
- package/src/sync/streaming/pushManager.ts +11 -7
- package/src/sync/submitters/eventsSubmitter.ts +35 -0
- package/src/sync/submitters/{impressionCountsSyncTask.ts → impressionCountsSubmitter.ts} +15 -15
- package/src/sync/submitters/{impressionsSyncTask.ts → impressionsSubmitter.ts} +12 -16
- package/src/sync/submitters/{submitterSyncTask.ts → submitter.ts} +34 -16
- package/src/sync/submitters/submitterManager.ts +14 -11
- package/src/sync/submitters/telemetrySubmitter.ts +143 -0
- package/src/sync/submitters/types.ts +123 -0
- package/src/sync/syncManagerOnline.ts +13 -7
- package/src/sync/types.ts +0 -15
- package/src/trackers/eventTracker.ts +7 -3
- package/src/trackers/impressionsTracker.ts +11 -3
- package/src/trackers/telemetryTracker.ts +63 -0
- package/src/trackers/types.ts +24 -0
- package/src/types.ts +35 -6
- package/src/utils/constants/index.ts +45 -0
- package/src/utils/inputValidation/apiKey.ts +2 -1
- package/src/utils/settingsValidation/index.ts +35 -11
- package/src/utils/settingsValidation/url.ts +4 -0
- package/src/utils/timeTracker/index.ts +1 -1
- package/src/utils/timeTracker/timer.ts +3 -3
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkFactory/types.d.ts +29 -14
- package/types/services/splitApi.d.ts +2 -1
- package/types/services/types.d.ts +8 -5
- package/types/storages/AbstractSegmentsCacheSync.d.ts +7 -3
- package/types/storages/KeyBuilderSS.d.ts +3 -3
- package/types/storages/findLatencyIndex.d.ts +7 -1
- package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +2 -0
- package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +2 -0
- package/types/storages/inMemory/SegmentsCacheInMemory.d.ts +1 -0
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -2
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +3 -3
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +2 -2
- package/types/storages/types.d.ts +71 -22
- package/types/sync/offline/syncManagerOffline.d.ts +3 -2
- package/types/sync/polling/pollingManagerCS.d.ts +2 -2
- package/types/sync/polling/pollingManagerSS.d.ts +2 -2
- package/types/sync/polling/syncTasks/splitsSyncTask.d.ts +1 -1
- package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
- package/types/sync/streaming/SSEHandler/NotificationKeeper.d.ts +2 -1
- package/types/sync/streaming/SSEHandler/index.d.ts +2 -1
- package/types/sync/streaming/pushManager.d.ts +2 -2
- package/types/sync/submitters/eventsSubmitter.d.ts +5 -0
- package/types/sync/submitters/impressionCountsSubmitter.d.ts +10 -0
- package/types/sync/submitters/impressionsSubmitter.d.ts +11 -0
- package/types/sync/submitters/submitter.d.ts +12 -0
- package/types/sync/submitters/submitterManager.d.ts +2 -2
- package/types/sync/submitters/telemetrySubmitter.d.ts +24 -0
- package/types/sync/submitters/telemetrySyncTask.d.ts +0 -27
- package/types/sync/submitters/types.d.ts +107 -0
- package/types/sync/syncManagerOnline.d.ts +3 -2
- package/types/sync/types.d.ts +0 -13
- package/types/trackers/eventTracker.d.ts +2 -2
- package/types/trackers/impressionsTracker.d.ts +2 -2
- package/types/trackers/telemetryTracker.d.ts +2 -3
- package/types/trackers/types.d.ts +22 -0
- package/types/types.d.ts +33 -4
- package/types/utils/constants/index.d.ts +37 -0
- package/types/utils/inputValidation/apiKey.d.ts +1 -0
- package/types/utils/settingsValidation/index.d.ts +40 -0
- package/types/utils/timeTracker/index.d.ts +1 -1
- package/types/utils/timeTracker/timer.d.ts +1 -1
- package/cjs/storages/inMemory/CountsCacheInMemory.js +0 -38
- package/cjs/storages/inMemory/LatenciesCacheInMemory.js +0 -43
- package/cjs/storages/inRedis/CountsCacheInRedis.js +0 -16
- package/cjs/storages/inRedis/LatenciesCacheInRedis.js +0 -18
- package/cjs/sync/submitters/eventsSyncTask.js +0 -44
- package/cjs/sync/submitters/metricsSyncTask.js +0 -31
- package/cjs/sync/submitters/submitterSyncTask.js +0 -44
- package/esm/storages/inMemory/CountsCacheInMemory.js +0 -35
- package/esm/storages/inMemory/LatenciesCacheInMemory.js +0 -40
- package/esm/storages/inRedis/CountsCacheInRedis.js +0 -13
- package/esm/storages/inRedis/LatenciesCacheInRedis.js +0 -15
- package/esm/sync/submitters/eventsSyncTask.js +0 -40
- package/esm/sync/submitters/metricsSyncTask.js +0 -26
- package/esm/sync/submitters/submitterSyncTask.js +0 -40
- package/src/storages/inMemory/CountsCacheInMemory.ts +0 -37
- package/src/storages/inMemory/LatenciesCacheInMemory.ts +0 -45
- package/src/storages/inRedis/CountsCacheInRedis.ts +0 -20
- package/src/storages/inRedis/LatenciesCacheInRedis.ts +0 -23
- package/src/sync/submitters/eventsSyncTask.ts +0 -57
- package/src/sync/submitters/metricsSyncTask.ts +0 -49
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.submitterSyncTaskFactory = void 0;
|
|
4
|
-
var syncTask_1 = require("../syncTask");
|
|
5
|
-
var constants_1 = require("../../logger/constants");
|
|
6
|
-
/**
|
|
7
|
-
* Base function to create submitter sync tasks, such as ImpressionsSyncTask and EventsSyncTask
|
|
8
|
-
*/
|
|
9
|
-
function submitterSyncTaskFactory(log, postClient, sourceCache, postRate, dataName, latencyTracker, fromCacheToPayload, maxRetries, debugLogs) {
|
|
10
|
-
if (maxRetries === void 0) { maxRetries = 0; }
|
|
11
|
-
var retries = 0;
|
|
12
|
-
function postData() {
|
|
13
|
-
if (sourceCache.isEmpty())
|
|
14
|
-
return Promise.resolve();
|
|
15
|
-
var data = sourceCache.state();
|
|
16
|
-
var dataCount = typeof data.length === 'number' ? data.length : '';
|
|
17
|
-
log[debugLogs ? 'debug' : 'info'](constants_1.SUBMITTERS_PUSH, [dataCount, dataName]);
|
|
18
|
-
var latencyTrackerStop = latencyTracker && latencyTracker.start();
|
|
19
|
-
var jsonPayload = JSON.stringify(fromCacheToPayload ? fromCacheToPayload(data) : data);
|
|
20
|
-
if (!maxRetries)
|
|
21
|
-
sourceCache.clear();
|
|
22
|
-
var postPromise = postClient(jsonPayload).then(function () {
|
|
23
|
-
retries = 0;
|
|
24
|
-
sourceCache.clear(); // we clear the queue if request successes.
|
|
25
|
-
}).catch(function (err) {
|
|
26
|
-
if (!maxRetries) {
|
|
27
|
-
log.warn(constants_1.SUBMITTERS_PUSH_FAILS, [dataCount, dataName, err]);
|
|
28
|
-
}
|
|
29
|
-
else if (retries === maxRetries) {
|
|
30
|
-
retries = 0;
|
|
31
|
-
sourceCache.clear(); // we clear the queue if request fails after retries.
|
|
32
|
-
log.warn(constants_1.SUBMITTERS_PUSH_FAILS, [dataCount, dataName, err]);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
retries++;
|
|
36
|
-
log.warn(constants_1.SUBMITTERS_PUSH_RETRY, [dataCount, dataName, err]);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
// if latencyTracker provided, attach stop callback to postEventsPromise
|
|
40
|
-
return latencyTrackerStop ? postPromise.then(latencyTrackerStop).catch(latencyTrackerStop) : postPromise;
|
|
41
|
-
}
|
|
42
|
-
return (0, syncTask_1.syncTaskFactory)(log, postData, postRate, dataName + ' submitter');
|
|
43
|
-
}
|
|
44
|
-
exports.submitterSyncTaskFactory = submitterSyncTaskFactory;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
var CountsCacheInMemory = /** @class */ (function () {
|
|
2
|
-
function CountsCacheInMemory() {
|
|
3
|
-
this.counters = {};
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Add counts.
|
|
7
|
-
*/
|
|
8
|
-
CountsCacheInMemory.prototype.track = function (metricName) {
|
|
9
|
-
if (this.counters[metricName] === undefined)
|
|
10
|
-
this.counters[metricName] = 1;
|
|
11
|
-
else
|
|
12
|
-
this.counters[metricName]++;
|
|
13
|
-
return true;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Clear the collector
|
|
17
|
-
*/
|
|
18
|
-
CountsCacheInMemory.prototype.clear = function () {
|
|
19
|
-
this.counters = {};
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Get the collected data, used as payload for posting.
|
|
23
|
-
*/
|
|
24
|
-
CountsCacheInMemory.prototype.state = function () {
|
|
25
|
-
return this.counters;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Check if the cache is empty.
|
|
29
|
-
*/
|
|
30
|
-
CountsCacheInMemory.prototype.isEmpty = function () {
|
|
31
|
-
return Object.keys(this.counters).length === 0;
|
|
32
|
-
};
|
|
33
|
-
return CountsCacheInMemory;
|
|
34
|
-
}());
|
|
35
|
-
export { CountsCacheInMemory };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { findLatencyIndex } from '../findLatencyIndex';
|
|
2
|
-
var LatenciesCacheInMemory = /** @class */ (function () {
|
|
3
|
-
function LatenciesCacheInMemory() {
|
|
4
|
-
this.counters = {};
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Add latencies.
|
|
8
|
-
*/
|
|
9
|
-
LatenciesCacheInMemory.prototype.track = function (metricName, latency) {
|
|
10
|
-
// Initialize if needed
|
|
11
|
-
if (this.counters[metricName] === undefined) {
|
|
12
|
-
this.counters[metricName] = [
|
|
13
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
14
|
-
];
|
|
15
|
-
}
|
|
16
|
-
// +1 based on the latency number
|
|
17
|
-
this.counters[metricName][findLatencyIndex(latency)]++;
|
|
18
|
-
return true;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Clear the collector
|
|
22
|
-
*/
|
|
23
|
-
LatenciesCacheInMemory.prototype.clear = function () {
|
|
24
|
-
this.counters = {};
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Get the collected data, used as payload for posting.
|
|
28
|
-
*/
|
|
29
|
-
LatenciesCacheInMemory.prototype.state = function () {
|
|
30
|
-
return this.counters;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Check if the cache is empty.
|
|
34
|
-
*/
|
|
35
|
-
LatenciesCacheInMemory.prototype.isEmpty = function () {
|
|
36
|
-
return Object.keys(this.counters).length === 0;
|
|
37
|
-
};
|
|
38
|
-
return LatenciesCacheInMemory;
|
|
39
|
-
}());
|
|
40
|
-
export { LatenciesCacheInMemory };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
var CountsCacheInRedis = /** @class */ (function () {
|
|
2
|
-
function CountsCacheInRedis(keys, redis) {
|
|
3
|
-
this.keys = keys;
|
|
4
|
-
this.redis = redis;
|
|
5
|
-
}
|
|
6
|
-
CountsCacheInRedis.prototype.track = function (metricName) {
|
|
7
|
-
return this.redis.incr(this.keys.buildCountKey(metricName)).catch(function () {
|
|
8
|
-
// noop, for telemetry metrics there's no need to throw.
|
|
9
|
-
}).then(function () { return true; });
|
|
10
|
-
};
|
|
11
|
-
return CountsCacheInRedis;
|
|
12
|
-
}());
|
|
13
|
-
export { CountsCacheInRedis };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { findLatencyIndex } from '../findLatencyIndex';
|
|
2
|
-
var LatenciesCacheInRedis = /** @class */ (function () {
|
|
3
|
-
function LatenciesCacheInRedis(keys, redis) {
|
|
4
|
-
this.keys = keys;
|
|
5
|
-
this.redis = redis;
|
|
6
|
-
}
|
|
7
|
-
LatenciesCacheInRedis.prototype.track = function (metricName, latency) {
|
|
8
|
-
var bucketNumber = findLatencyIndex(latency);
|
|
9
|
-
return this.redis.incr(this.keys.buildLatencyKey(metricName, bucketNumber)).catch(function () {
|
|
10
|
-
// noop, for telemetry metrics there's no need to throw.
|
|
11
|
-
}).then(function () { return true; });
|
|
12
|
-
};
|
|
13
|
-
return LatenciesCacheInRedis;
|
|
14
|
-
}());
|
|
15
|
-
export { LatenciesCacheInRedis };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { submitterSyncTaskFactory } from './submitterSyncTask';
|
|
2
|
-
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
|
|
3
|
-
var DATA_NAME = 'events';
|
|
4
|
-
/**
|
|
5
|
-
* Sync task that periodically posts tracked events
|
|
6
|
-
*/
|
|
7
|
-
export function eventsSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, eventsFirstPushWindow, latencyTracker) {
|
|
8
|
-
// don't retry events.
|
|
9
|
-
var syncTask = submitterSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, DATA_NAME, latencyTracker);
|
|
10
|
-
// Set a timer for the first push window of events.
|
|
11
|
-
// Not implemented in the base submitter or sync task, since this feature is only used by the events submitter.
|
|
12
|
-
if (eventsFirstPushWindow > 0) {
|
|
13
|
-
var running_1 = false;
|
|
14
|
-
var stopEventPublisherTimeout_1;
|
|
15
|
-
var originalStart_1 = syncTask.start;
|
|
16
|
-
syncTask.start = function () {
|
|
17
|
-
running_1 = true;
|
|
18
|
-
stopEventPublisherTimeout_1 = setTimeout(originalStart_1, eventsFirstPushWindow);
|
|
19
|
-
};
|
|
20
|
-
var originalStop_1 = syncTask.stop;
|
|
21
|
-
syncTask.stop = function () {
|
|
22
|
-
running_1 = false;
|
|
23
|
-
clearTimeout(stopEventPublisherTimeout_1);
|
|
24
|
-
originalStop_1();
|
|
25
|
-
};
|
|
26
|
-
syncTask.isRunning = function () {
|
|
27
|
-
return running_1;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
// register events submitter to be executed when events cache is full
|
|
31
|
-
eventsCache.setOnFullQueueCb(function () {
|
|
32
|
-
if (syncTask.isRunning()) {
|
|
33
|
-
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
|
|
34
|
-
syncTask.execute();
|
|
35
|
-
}
|
|
36
|
-
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
|
|
37
|
-
// Data will be sent when submitter is resumed.
|
|
38
|
-
});
|
|
39
|
-
return syncTask;
|
|
40
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { forOwn } from '../../utils/lang';
|
|
2
|
-
import { submitterSyncTaskFactory } from './submitterSyncTask';
|
|
3
|
-
// extract POST payload object from cache
|
|
4
|
-
function fromCache(propertyName) {
|
|
5
|
-
return function (data) {
|
|
6
|
-
var result = [];
|
|
7
|
-
forOwn(data, function (value, key) {
|
|
8
|
-
var _a;
|
|
9
|
-
result.push((_a = { name: key }, _a[propertyName] = value, _a));
|
|
10
|
-
});
|
|
11
|
-
return result;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Sync task that periodically posts telemetry counts
|
|
16
|
-
*/
|
|
17
|
-
export function countsSyncTaskFactory(log, postMetricsCounters, countsCache, metricsRefreshRate, latencyTracker) {
|
|
18
|
-
return submitterSyncTaskFactory(log, postMetricsCounters, countsCache, metricsRefreshRate, 'count metrics', latencyTracker, fromCache('delta'));
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Sync task that periodically posts telemetry latencies
|
|
22
|
-
*/
|
|
23
|
-
export function latenciesSyncTaskFactory(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, latencyTracker) {
|
|
24
|
-
// don't retry metrics.
|
|
25
|
-
return submitterSyncTaskFactory(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, 'latency metrics', latencyTracker, fromCache('latencies'), 0, true);
|
|
26
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { syncTaskFactory } from '../syncTask';
|
|
2
|
-
import { SUBMITTERS_PUSH, SUBMITTERS_PUSH_FAILS, SUBMITTERS_PUSH_RETRY } from '../../logger/constants';
|
|
3
|
-
/**
|
|
4
|
-
* Base function to create submitter sync tasks, such as ImpressionsSyncTask and EventsSyncTask
|
|
5
|
-
*/
|
|
6
|
-
export function submitterSyncTaskFactory(log, postClient, sourceCache, postRate, dataName, latencyTracker, fromCacheToPayload, maxRetries, debugLogs) {
|
|
7
|
-
if (maxRetries === void 0) { maxRetries = 0; }
|
|
8
|
-
var retries = 0;
|
|
9
|
-
function postData() {
|
|
10
|
-
if (sourceCache.isEmpty())
|
|
11
|
-
return Promise.resolve();
|
|
12
|
-
var data = sourceCache.state();
|
|
13
|
-
var dataCount = typeof data.length === 'number' ? data.length : '';
|
|
14
|
-
log[debugLogs ? 'debug' : 'info'](SUBMITTERS_PUSH, [dataCount, dataName]);
|
|
15
|
-
var latencyTrackerStop = latencyTracker && latencyTracker.start();
|
|
16
|
-
var jsonPayload = JSON.stringify(fromCacheToPayload ? fromCacheToPayload(data) : data);
|
|
17
|
-
if (!maxRetries)
|
|
18
|
-
sourceCache.clear();
|
|
19
|
-
var postPromise = postClient(jsonPayload).then(function () {
|
|
20
|
-
retries = 0;
|
|
21
|
-
sourceCache.clear(); // we clear the queue if request successes.
|
|
22
|
-
}).catch(function (err) {
|
|
23
|
-
if (!maxRetries) {
|
|
24
|
-
log.warn(SUBMITTERS_PUSH_FAILS, [dataCount, dataName, err]);
|
|
25
|
-
}
|
|
26
|
-
else if (retries === maxRetries) {
|
|
27
|
-
retries = 0;
|
|
28
|
-
sourceCache.clear(); // we clear the queue if request fails after retries.
|
|
29
|
-
log.warn(SUBMITTERS_PUSH_FAILS, [dataCount, dataName, err]);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
retries++;
|
|
33
|
-
log.warn(SUBMITTERS_PUSH_RETRY, [dataCount, dataName, err]);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
// if latencyTracker provided, attach stop callback to postEventsPromise
|
|
37
|
-
return latencyTrackerStop ? postPromise.then(latencyTrackerStop).catch(latencyTrackerStop) : postPromise;
|
|
38
|
-
}
|
|
39
|
-
return syncTaskFactory(log, postData, postRate, dataName + ' submitter');
|
|
40
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ICountsCacheSync } from '../types';
|
|
2
|
-
|
|
3
|
-
export class CountsCacheInMemory implements ICountsCacheSync {
|
|
4
|
-
|
|
5
|
-
private counters: Record<string, number> = {};
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Add counts.
|
|
9
|
-
*/
|
|
10
|
-
track(metricName: string) {
|
|
11
|
-
if (this.counters[metricName] === undefined) this.counters[metricName] = 1;
|
|
12
|
-
else this.counters[metricName]++;
|
|
13
|
-
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Clear the collector
|
|
19
|
-
*/
|
|
20
|
-
clear() {
|
|
21
|
-
this.counters = {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Get the collected data, used as payload for posting.
|
|
26
|
-
*/
|
|
27
|
-
state() {
|
|
28
|
-
return this.counters;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Check if the cache is empty.
|
|
33
|
-
*/
|
|
34
|
-
isEmpty() {
|
|
35
|
-
return Object.keys(this.counters).length === 0;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { ILatenciesCacheSync } from '../types';
|
|
2
|
-
import { findLatencyIndex } from '../findLatencyIndex';
|
|
3
|
-
|
|
4
|
-
export class LatenciesCacheInMemory implements ILatenciesCacheSync {
|
|
5
|
-
|
|
6
|
-
private counters: Record<string, number[]> = {};
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Add latencies.
|
|
10
|
-
*/
|
|
11
|
-
track(metricName: string, latency: number) {
|
|
12
|
-
// Initialize if needed
|
|
13
|
-
if (this.counters[metricName] === undefined) {
|
|
14
|
-
this.counters[metricName] = [
|
|
15
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
16
|
-
];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// +1 based on the latency number
|
|
20
|
-
this.counters[metricName][findLatencyIndex(latency)]++;
|
|
21
|
-
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Clear the collector
|
|
27
|
-
*/
|
|
28
|
-
clear() {
|
|
29
|
-
this.counters = {};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Get the collected data, used as payload for posting.
|
|
34
|
-
*/
|
|
35
|
-
state() {
|
|
36
|
-
return this.counters;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Check if the cache is empty.
|
|
41
|
-
*/
|
|
42
|
-
isEmpty() {
|
|
43
|
-
return Object.keys(this.counters).length === 0;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ICountsCacheAsync } from '../types';
|
|
2
|
-
import { KeyBuilderSS } from '../KeyBuilderSS';
|
|
3
|
-
import { Redis } from 'ioredis';
|
|
4
|
-
|
|
5
|
-
export class CountsCacheInRedis implements ICountsCacheAsync {
|
|
6
|
-
|
|
7
|
-
private readonly redis: Redis;
|
|
8
|
-
private readonly keys: KeyBuilderSS;
|
|
9
|
-
|
|
10
|
-
constructor(keys: KeyBuilderSS, redis: Redis) {
|
|
11
|
-
this.keys = keys;
|
|
12
|
-
this.redis = redis;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
track(metricName: string): Promise<boolean> {
|
|
16
|
-
return this.redis.incr(this.keys.buildCountKey(metricName)).catch(() => {
|
|
17
|
-
// noop, for telemetry metrics there's no need to throw.
|
|
18
|
-
}).then(() => true);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ILatenciesCacheAsync } from '../types';
|
|
2
|
-
import { KeyBuilderSS } from '../KeyBuilderSS';
|
|
3
|
-
import { findLatencyIndex } from '../findLatencyIndex';
|
|
4
|
-
import { Redis } from 'ioredis';
|
|
5
|
-
|
|
6
|
-
export class LatenciesCacheInRedis implements ILatenciesCacheAsync {
|
|
7
|
-
|
|
8
|
-
private readonly redis: Redis;
|
|
9
|
-
private readonly keys: KeyBuilderSS;
|
|
10
|
-
|
|
11
|
-
constructor(keys: KeyBuilderSS, redis: Redis) {
|
|
12
|
-
this.keys = keys;
|
|
13
|
-
this.redis = redis;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
track(metricName: string, latency: number): Promise<boolean> {
|
|
17
|
-
const bucketNumber = findLatencyIndex(latency);
|
|
18
|
-
|
|
19
|
-
return this.redis.incr(this.keys.buildLatencyKey(metricName, bucketNumber)).catch(() => {
|
|
20
|
-
// noop, for telemetry metrics there's no need to throw.
|
|
21
|
-
}).then(() => true);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { IEventsCacheSync } from '../../storages/types';
|
|
2
|
-
import { IPostEventsBulk } from '../../services/types';
|
|
3
|
-
import { ISyncTask, ITimeTracker } from '../types';
|
|
4
|
-
import { submitterSyncTaskFactory } from './submitterSyncTask';
|
|
5
|
-
import { ILogger } from '../../logger/types';
|
|
6
|
-
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
|
|
7
|
-
|
|
8
|
-
const DATA_NAME = 'events';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Sync task that periodically posts tracked events
|
|
12
|
-
*/
|
|
13
|
-
export function eventsSyncTaskFactory(
|
|
14
|
-
log: ILogger,
|
|
15
|
-
postEventsBulk: IPostEventsBulk,
|
|
16
|
-
eventsCache: IEventsCacheSync,
|
|
17
|
-
eventsPushRate: number,
|
|
18
|
-
eventsFirstPushWindow: number,
|
|
19
|
-
latencyTracker?: ITimeTracker
|
|
20
|
-
): ISyncTask {
|
|
21
|
-
|
|
22
|
-
// don't retry events.
|
|
23
|
-
const syncTask = submitterSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, DATA_NAME, latencyTracker);
|
|
24
|
-
|
|
25
|
-
// Set a timer for the first push window of events.
|
|
26
|
-
// Not implemented in the base submitter or sync task, since this feature is only used by the events submitter.
|
|
27
|
-
if (eventsFirstPushWindow > 0) {
|
|
28
|
-
let running = false;
|
|
29
|
-
let stopEventPublisherTimeout: ReturnType<typeof setTimeout>;
|
|
30
|
-
const originalStart = syncTask.start;
|
|
31
|
-
syncTask.start = () => {
|
|
32
|
-
running = true;
|
|
33
|
-
stopEventPublisherTimeout = setTimeout(originalStart, eventsFirstPushWindow);
|
|
34
|
-
};
|
|
35
|
-
const originalStop = syncTask.stop;
|
|
36
|
-
syncTask.stop = () => {
|
|
37
|
-
running = false;
|
|
38
|
-
clearTimeout(stopEventPublisherTimeout);
|
|
39
|
-
originalStop();
|
|
40
|
-
};
|
|
41
|
-
syncTask.isRunning = () => {
|
|
42
|
-
return running;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// register events submitter to be executed when events cache is full
|
|
47
|
-
eventsCache.setOnFullQueueCb(() => {
|
|
48
|
-
if (syncTask.isRunning()) {
|
|
49
|
-
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
|
|
50
|
-
syncTask.execute();
|
|
51
|
-
}
|
|
52
|
-
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
|
|
53
|
-
// Data will be sent when submitter is resumed.
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
return syncTask;
|
|
57
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { forOwn } from '../../utils/lang';
|
|
3
|
-
import { ICountsCacheSync, ILatenciesCacheSync } from '../../storages/types';
|
|
4
|
-
import { IPostMetricsCounters, IPostMetricsTimes } from '../../services/types';
|
|
5
|
-
import { ISyncTask, ITimeTracker } from '../types';
|
|
6
|
-
import { submitterSyncTaskFactory } from './submitterSyncTask';
|
|
7
|
-
import { ILogger } from '../../logger/types';
|
|
8
|
-
|
|
9
|
-
// extract POST payload object from cache
|
|
10
|
-
function fromCache<V>(propertyName: 'latencies' | 'delta') {
|
|
11
|
-
return (data: Record<string, V>): any[] => {
|
|
12
|
-
const result: any[] = [];
|
|
13
|
-
|
|
14
|
-
forOwn(data, (value, key) => {
|
|
15
|
-
result.push({ name: key, [propertyName]: value });
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return result;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Sync task that periodically posts telemetry counts
|
|
24
|
-
*/
|
|
25
|
-
export function countsSyncTaskFactory(
|
|
26
|
-
log: ILogger,
|
|
27
|
-
postMetricsCounters: IPostMetricsCounters,
|
|
28
|
-
countsCache: ICountsCacheSync,
|
|
29
|
-
metricsRefreshRate: number,
|
|
30
|
-
latencyTracker?: ITimeTracker
|
|
31
|
-
): ISyncTask {
|
|
32
|
-
|
|
33
|
-
return submitterSyncTaskFactory(log, postMetricsCounters, countsCache, metricsRefreshRate, 'count metrics', latencyTracker, fromCache<number>('delta'));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Sync task that periodically posts telemetry latencies
|
|
38
|
-
*/
|
|
39
|
-
export function latenciesSyncTaskFactory(
|
|
40
|
-
log: ILogger,
|
|
41
|
-
postMetricsLatencies: IPostMetricsTimes,
|
|
42
|
-
latenciesCache: ILatenciesCacheSync,
|
|
43
|
-
metricsRefreshRate: number,
|
|
44
|
-
latencyTracker?: ITimeTracker
|
|
45
|
-
): ISyncTask {
|
|
46
|
-
|
|
47
|
-
// don't retry metrics.
|
|
48
|
-
return submitterSyncTaskFactory(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, 'latency metrics', latencyTracker, fromCache<number[]>('latencies'), 0, true);
|
|
49
|
-
}
|