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