@hotmeshio/hotmesh 0.4.0 → 0.4.1
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/build/modules/enums.d.ts +110 -0
- package/build/modules/enums.js +134 -0
- package/build/modules/errors.d.ts +124 -0
- package/build/modules/errors.js +191 -0
- package/build/modules/key.d.ts +66 -0
- package/build/modules/key.js +190 -0
- package/build/modules/storage.d.ts +3 -0
- package/build/modules/storage.js +5 -0
- package/build/modules/utils.d.ts +119 -0
- package/build/modules/utils.js +374 -0
- package/build/package.json +1 -1
- package/build/services/activities/activity.d.ts +104 -0
- package/build/services/activities/activity.js +549 -0
- package/build/services/activities/await.d.ts +12 -0
- package/build/services/activities/await.js +114 -0
- package/build/services/activities/cycle.d.ts +19 -0
- package/build/services/activities/cycle.js +112 -0
- package/build/services/activities/hook.d.ts +27 -0
- package/build/services/activities/hook.js +168 -0
- package/build/services/activities/index.d.ts +19 -0
- package/build/services/activities/index.js +20 -0
- package/build/services/activities/interrupt.d.ts +16 -0
- package/build/services/activities/interrupt.js +158 -0
- package/build/services/activities/signal.d.ts +20 -0
- package/build/services/activities/signal.js +134 -0
- package/build/services/activities/trigger.d.ts +37 -0
- package/build/services/activities/trigger.js +246 -0
- package/build/services/activities/worker.d.ts +12 -0
- package/build/services/activities/worker.js +106 -0
- package/build/services/collator/index.d.ts +111 -0
- package/build/services/collator/index.js +293 -0
- package/build/services/compiler/deployer.d.ts +40 -0
- package/build/services/compiler/deployer.js +488 -0
- package/build/services/compiler/index.d.ts +32 -0
- package/build/services/compiler/index.js +112 -0
- package/build/services/compiler/validator.d.ts +34 -0
- package/build/services/compiler/validator.js +147 -0
- package/build/services/connector/factory.d.ts +22 -0
- package/build/services/connector/factory.js +99 -0
- package/build/services/connector/index.d.ts +30 -0
- package/build/services/connector/index.js +54 -0
- package/build/services/connector/providers/ioredis.d.ts +9 -0
- package/build/services/connector/providers/ioredis.js +26 -0
- package/build/services/connector/providers/nats.d.ts +9 -0
- package/build/services/connector/providers/nats.js +34 -0
- package/build/services/connector/providers/postgres.d.ts +20 -0
- package/build/services/connector/providers/postgres.js +102 -0
- package/build/services/connector/providers/redis.d.ts +9 -0
- package/build/services/connector/providers/redis.js +38 -0
- package/build/services/engine/index.d.ts +264 -0
- package/build/services/engine/index.js +761 -0
- package/build/services/exporter/index.d.ts +44 -0
- package/build/services/exporter/index.js +126 -0
- package/build/services/hotmesh/index.d.ts +483 -0
- package/build/services/hotmesh/index.js +622 -0
- package/build/services/logger/index.d.ts +16 -0
- package/build/services/logger/index.js +54 -0
- package/build/services/mapper/index.d.ts +28 -0
- package/build/services/mapper/index.js +81 -0
- package/build/services/memflow/client.d.ts +108 -0
- package/build/services/memflow/client.js +372 -0
- package/build/services/memflow/connection.d.ts +23 -0
- package/build/services/memflow/connection.js +33 -0
- package/build/services/memflow/context.d.ts +143 -0
- package/build/services/memflow/context.js +299 -0
- package/build/services/memflow/exporter.d.ts +51 -0
- package/build/services/memflow/exporter.js +215 -0
- package/build/services/memflow/handle.d.ts +90 -0
- package/build/services/memflow/handle.js +176 -0
- package/build/services/memflow/index.d.ts +116 -0
- package/build/services/memflow/index.js +122 -0
- package/build/services/memflow/schemas/factory.d.ts +29 -0
- package/build/services/memflow/schemas/factory.js +2492 -0
- package/build/services/memflow/search.d.ts +142 -0
- package/build/services/memflow/search.js +320 -0
- package/build/services/memflow/worker.d.ts +124 -0
- package/build/services/memflow/worker.js +514 -0
- package/build/services/memflow/workflow/all.d.ts +7 -0
- package/build/services/memflow/workflow/all.js +15 -0
- package/build/services/memflow/workflow/common.d.ts +20 -0
- package/build/services/memflow/workflow/common.js +47 -0
- package/build/services/memflow/workflow/context.d.ts +6 -0
- package/build/services/memflow/workflow/context.js +45 -0
- package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
- package/build/services/memflow/workflow/contextMethods.js +33 -0
- package/build/services/memflow/workflow/didRun.d.ts +7 -0
- package/build/services/memflow/workflow/didRun.js +22 -0
- package/build/services/memflow/workflow/emit.d.ts +11 -0
- package/build/services/memflow/workflow/emit.js +29 -0
- package/build/services/memflow/workflow/enrich.d.ts +9 -0
- package/build/services/memflow/workflow/enrich.js +17 -0
- package/build/services/memflow/workflow/execChild.d.ts +18 -0
- package/build/services/memflow/workflow/execChild.js +102 -0
- package/build/services/memflow/workflow/execHook.d.ts +65 -0
- package/build/services/memflow/workflow/execHook.js +73 -0
- package/build/services/memflow/workflow/hook.d.ts +9 -0
- package/build/services/memflow/workflow/hook.js +56 -0
- package/build/services/memflow/workflow/index.d.ts +74 -0
- package/build/services/memflow/workflow/index.js +87 -0
- package/build/services/memflow/workflow/interrupt.d.ts +9 -0
- package/build/services/memflow/workflow/interrupt.js +24 -0
- package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +10 -0
- package/build/services/memflow/workflow/isSideEffectAllowed.js +33 -0
- package/build/services/memflow/workflow/proxyActivities.d.ts +20 -0
- package/build/services/memflow/workflow/proxyActivities.js +97 -0
- package/build/services/memflow/workflow/random.d.ts +6 -0
- package/build/services/memflow/workflow/random.js +16 -0
- package/build/services/memflow/workflow/searchMethods.d.ts +6 -0
- package/build/services/memflow/workflow/searchMethods.js +25 -0
- package/build/services/memflow/workflow/signal.d.ts +7 -0
- package/build/services/memflow/workflow/signal.js +28 -0
- package/build/services/memflow/workflow/sleepFor.d.ts +8 -0
- package/build/services/memflow/workflow/sleepFor.js +35 -0
- package/build/services/memflow/workflow/trace.d.ts +14 -0
- package/build/services/memflow/workflow/trace.js +33 -0
- package/build/services/memflow/workflow/waitFor.d.ts +8 -0
- package/build/services/memflow/workflow/waitFor.js +35 -0
- package/build/services/meshcall/index.d.ts +194 -0
- package/build/services/meshcall/index.js +452 -0
- package/build/services/meshcall/schemas/factory.d.ts +9 -0
- package/build/services/meshcall/schemas/factory.js +189 -0
- package/build/services/meshdata/index.d.ts +795 -0
- package/build/services/meshdata/index.js +1235 -0
- package/build/services/meshos/index.d.ts +293 -0
- package/build/services/meshos/index.js +547 -0
- package/build/services/pipe/functions/array.d.ts +17 -0
- package/build/services/pipe/functions/array.js +74 -0
- package/build/services/pipe/functions/bitwise.d.ts +9 -0
- package/build/services/pipe/functions/bitwise.js +24 -0
- package/build/services/pipe/functions/conditional.d.ts +13 -0
- package/build/services/pipe/functions/conditional.js +36 -0
- package/build/services/pipe/functions/cron.d.ts +12 -0
- package/build/services/pipe/functions/cron.js +40 -0
- package/build/services/pipe/functions/date.d.ts +58 -0
- package/build/services/pipe/functions/date.js +171 -0
- package/build/services/pipe/functions/index.d.ts +29 -0
- package/build/services/pipe/functions/index.js +30 -0
- package/build/services/pipe/functions/json.d.ts +5 -0
- package/build/services/pipe/functions/json.js +12 -0
- package/build/services/pipe/functions/logical.d.ts +5 -0
- package/build/services/pipe/functions/logical.js +12 -0
- package/build/services/pipe/functions/math.d.ts +42 -0
- package/build/services/pipe/functions/math.js +184 -0
- package/build/services/pipe/functions/number.d.ts +21 -0
- package/build/services/pipe/functions/number.js +60 -0
- package/build/services/pipe/functions/object.d.ts +25 -0
- package/build/services/pipe/functions/object.js +81 -0
- package/build/services/pipe/functions/string.d.ts +23 -0
- package/build/services/pipe/functions/string.js +69 -0
- package/build/services/pipe/functions/symbol.d.ts +12 -0
- package/build/services/pipe/functions/symbol.js +33 -0
- package/build/services/pipe/functions/unary.d.ts +7 -0
- package/build/services/pipe/functions/unary.js +18 -0
- package/build/services/pipe/index.d.ts +48 -0
- package/build/services/pipe/index.js +242 -0
- package/build/services/quorum/index.d.ts +90 -0
- package/build/services/quorum/index.js +263 -0
- package/build/services/reporter/index.d.ts +50 -0
- package/build/services/reporter/index.js +348 -0
- package/build/services/router/config/index.d.ts +11 -0
- package/build/services/router/config/index.js +36 -0
- package/build/services/router/consumption/index.d.ts +34 -0
- package/build/services/router/consumption/index.js +395 -0
- package/build/services/router/error-handling/index.d.ts +8 -0
- package/build/services/router/error-handling/index.js +98 -0
- package/build/services/router/index.d.ts +57 -0
- package/build/services/router/index.js +121 -0
- package/build/services/router/lifecycle/index.d.ts +27 -0
- package/build/services/router/lifecycle/index.js +80 -0
- package/build/services/router/telemetry/index.d.ts +11 -0
- package/build/services/router/telemetry/index.js +32 -0
- package/build/services/router/throttling/index.d.ts +23 -0
- package/build/services/router/throttling/index.js +76 -0
- package/build/services/search/factory.d.ts +7 -0
- package/build/services/search/factory.js +24 -0
- package/build/services/search/index.d.ts +23 -0
- package/build/services/search/index.js +10 -0
- package/build/services/search/providers/postgres/postgres.d.ts +25 -0
- package/build/services/search/providers/postgres/postgres.js +149 -0
- package/build/services/search/providers/redis/ioredis.d.ts +19 -0
- package/build/services/search/providers/redis/ioredis.js +121 -0
- package/build/services/search/providers/redis/redis.d.ts +19 -0
- package/build/services/search/providers/redis/redis.js +134 -0
- package/build/services/serializer/index.d.ts +42 -0
- package/build/services/serializer/index.js +282 -0
- package/build/services/store/cache.d.ts +67 -0
- package/build/services/store/cache.js +128 -0
- package/build/services/store/factory.d.ts +8 -0
- package/build/services/store/factory.js +24 -0
- package/build/services/store/index.d.ts +89 -0
- package/build/services/store/index.js +9 -0
- package/build/services/store/providers/postgres/kvsql.d.ts +168 -0
- package/build/services/store/providers/postgres/kvsql.js +198 -0
- package/build/services/store/providers/postgres/kvtables.d.ts +20 -0
- package/build/services/store/providers/postgres/kvtables.js +441 -0
- package/build/services/store/providers/postgres/kvtransaction.d.ts +36 -0
- package/build/services/store/providers/postgres/kvtransaction.js +248 -0
- package/build/services/store/providers/postgres/kvtypes/hash.d.ts +60 -0
- package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -0
- package/build/services/store/providers/postgres/kvtypes/list.d.ts +33 -0
- package/build/services/store/providers/postgres/kvtypes/list.js +194 -0
- package/build/services/store/providers/postgres/kvtypes/string.d.ts +20 -0
- package/build/services/store/providers/postgres/kvtypes/string.js +115 -0
- package/build/services/store/providers/postgres/kvtypes/zset.d.ts +41 -0
- package/build/services/store/providers/postgres/kvtypes/zset.js +214 -0
- package/build/services/store/providers/postgres/postgres.d.ts +145 -0
- package/build/services/store/providers/postgres/postgres.js +1036 -0
- package/build/services/store/providers/redis/_base.d.ts +137 -0
- package/build/services/store/providers/redis/_base.js +980 -0
- package/build/services/store/providers/redis/ioredis.d.ts +20 -0
- package/build/services/store/providers/redis/ioredis.js +180 -0
- package/build/services/store/providers/redis/redis.d.ts +18 -0
- package/build/services/store/providers/redis/redis.js +199 -0
- package/build/services/store/providers/store-initializable.d.ts +5 -0
- package/build/services/store/providers/store-initializable.js +2 -0
- package/build/services/stream/factory.d.ts +8 -0
- package/build/services/stream/factory.js +37 -0
- package/build/services/stream/index.d.ts +69 -0
- package/build/services/stream/index.js +11 -0
- package/build/services/stream/providers/nats/nats.d.ts +60 -0
- package/build/services/stream/providers/nats/nats.js +225 -0
- package/build/services/stream/providers/postgres/kvtables.d.ts +3 -0
- package/build/services/stream/providers/postgres/kvtables.js +146 -0
- package/build/services/stream/providers/postgres/postgres.d.ts +107 -0
- package/build/services/stream/providers/postgres/postgres.js +519 -0
- package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
- package/build/services/stream/providers/redis/ioredis.js +272 -0
- package/build/services/stream/providers/redis/redis.d.ts +61 -0
- package/build/services/stream/providers/redis/redis.js +305 -0
- package/build/services/stream/providers/stream-initializable.d.ts +4 -0
- package/build/services/stream/providers/stream-initializable.js +2 -0
- package/build/services/sub/factory.d.ts +7 -0
- package/build/services/sub/factory.js +29 -0
- package/build/services/sub/index.d.ts +22 -0
- package/build/services/sub/index.js +10 -0
- package/build/services/sub/providers/nats/nats.d.ts +19 -0
- package/build/services/sub/providers/nats/nats.js +105 -0
- package/build/services/sub/providers/postgres/postgres.d.ts +19 -0
- package/build/services/sub/providers/postgres/postgres.js +92 -0
- package/build/services/sub/providers/redis/ioredis.d.ts +17 -0
- package/build/services/sub/providers/redis/ioredis.js +81 -0
- package/build/services/sub/providers/redis/redis.d.ts +17 -0
- package/build/services/sub/providers/redis/redis.js +72 -0
- package/build/services/task/index.d.ts +36 -0
- package/build/services/task/index.js +206 -0
- package/build/services/telemetry/index.d.ts +52 -0
- package/build/services/telemetry/index.js +306 -0
- package/build/services/worker/index.d.ts +77 -0
- package/build/services/worker/index.js +197 -0
- package/package.json +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/typedoc.json +0 -47
- package/types/activity.ts +0 -268
- package/types/app.ts +0 -20
- package/types/async.ts +0 -6
- package/types/cache.ts +0 -1
- package/types/collator.ts +0 -9
- package/types/error.ts +0 -56
- package/types/exporter.ts +0 -102
- package/types/hook.ts +0 -44
- package/types/hotmesh.ts +0 -314
- package/types/index.ts +0 -306
- package/types/job.ts +0 -233
- package/types/logger.ts +0 -8
- package/types/manifest.ts +0 -70
- package/types/map.ts +0 -5
- package/types/memflow.ts +0 -645
- package/types/meshcall.ts +0 -235
- package/types/meshdata.ts +0 -278
- package/types/ms.d.ts +0 -7
- package/types/nats.ts +0 -270
- package/types/pipe.ts +0 -90
- package/types/postgres.ts +0 -114
- package/types/provider.ts +0 -161
- package/types/quorum.ts +0 -167
- package/types/redis.ts +0 -404
- package/types/serializer.ts +0 -40
- package/types/stats.ts +0 -117
- package/types/stream.ts +0 -231
- package/types/task.ts +0 -7
- package/types/telemetry.ts +0 -16
- package/types/transition.ts +0 -20
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReporterService = void 0;
|
|
4
|
+
const pipe_1 = require("../pipe");
|
|
5
|
+
class ReporterService {
|
|
6
|
+
constructor(appVersion, store, logger) {
|
|
7
|
+
this.appVersion = appVersion;
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
this.store = store;
|
|
10
|
+
}
|
|
11
|
+
async getStats(options) {
|
|
12
|
+
this.logger.debug('reporter-getstats-started', options);
|
|
13
|
+
const { key, granularity, range, end, start } = options;
|
|
14
|
+
this.validateOptions(options);
|
|
15
|
+
const dateTimeSets = this.generateDateTimeSets(granularity, range, end, start);
|
|
16
|
+
const redisKeys = dateTimeSets.map((dateTime) => this.buildRedisKey(key, dateTime));
|
|
17
|
+
const rawData = await this.store.getJobStats(redisKeys);
|
|
18
|
+
const [count, aggregatedData] = this.aggregateData(rawData);
|
|
19
|
+
const statsResponse = this.buildStatsResponse(rawData, redisKeys, aggregatedData, count, options);
|
|
20
|
+
return statsResponse;
|
|
21
|
+
}
|
|
22
|
+
validateOptions(options) {
|
|
23
|
+
const { start, end, range, granularity } = options;
|
|
24
|
+
if (granularity !== 'infinity' &&
|
|
25
|
+
(start && end && range || !start && !end && !range)) {
|
|
26
|
+
throw new Error('Invalid combination of start, end, and range values. Provide either start+end, end+range, or start+range.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
generateDateTimeSets(granularity, range, end, start) {
|
|
30
|
+
if (granularity === 'infinity') {
|
|
31
|
+
//if granularity is infinity, it means a date/time sequence/slice is not used to further segment the statistics
|
|
32
|
+
return ['0'];
|
|
33
|
+
}
|
|
34
|
+
if (!range) {
|
|
35
|
+
range = '0m';
|
|
36
|
+
}
|
|
37
|
+
const granularitiesInMinutes = {
|
|
38
|
+
'5m': 5,
|
|
39
|
+
'10m': 10,
|
|
40
|
+
'15m': 15,
|
|
41
|
+
'30m': 30,
|
|
42
|
+
'1h': 60,
|
|
43
|
+
};
|
|
44
|
+
const granularityMinutes = granularitiesInMinutes[granularity];
|
|
45
|
+
if (!granularityMinutes) {
|
|
46
|
+
throw new Error('Invalid granularity value.');
|
|
47
|
+
}
|
|
48
|
+
const rangeMinutes = this.convertRangeToMinutes(range);
|
|
49
|
+
if (rangeMinutes === null) {
|
|
50
|
+
throw new Error('Invalid range value.');
|
|
51
|
+
}
|
|
52
|
+
// If start is provided, use it. Otherwise, calculate it from the end time and range.
|
|
53
|
+
let startTime;
|
|
54
|
+
let endTime;
|
|
55
|
+
if (start) {
|
|
56
|
+
startTime = new Date(start);
|
|
57
|
+
endTime = new Date(startTime.getTime() + rangeMinutes * 60 * 1000);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
endTime = end === 'NOW' ? new Date() : new Date(end);
|
|
61
|
+
startTime = new Date(endTime.getTime() - rangeMinutes * 60 * 1000);
|
|
62
|
+
}
|
|
63
|
+
// Round the start time to the nearest granularity unit
|
|
64
|
+
startTime.setUTCMinutes(Math.floor(startTime.getUTCMinutes() / granularityMinutes) *
|
|
65
|
+
granularityMinutes);
|
|
66
|
+
const dateTimeSets = [];
|
|
67
|
+
for (let time = startTime; time <= endTime; time.setUTCMinutes(time.getUTCMinutes() + granularityMinutes)) {
|
|
68
|
+
const formattedTime = [
|
|
69
|
+
time.getUTCFullYear(),
|
|
70
|
+
String(time.getUTCMonth() + 1).padStart(2, '0'),
|
|
71
|
+
String(time.getUTCDate()).padStart(2, '0'),
|
|
72
|
+
String(time.getUTCHours()).padStart(2, '0'),
|
|
73
|
+
String(time.getUTCMinutes()).padStart(2, '0'),
|
|
74
|
+
].join('');
|
|
75
|
+
dateTimeSets.push(formattedTime);
|
|
76
|
+
}
|
|
77
|
+
return dateTimeSets;
|
|
78
|
+
}
|
|
79
|
+
convertRangeToMinutes(range) {
|
|
80
|
+
const timeUnit = range.slice(-1);
|
|
81
|
+
const value = parseInt(range.slice(0, -1), 10);
|
|
82
|
+
if (isNaN(value)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
switch (timeUnit) {
|
|
86
|
+
case 'm':
|
|
87
|
+
return value;
|
|
88
|
+
case 'h':
|
|
89
|
+
return value * 60;
|
|
90
|
+
case 'd':
|
|
91
|
+
return value * 60 * 24;
|
|
92
|
+
default:
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
buildRedisKey(key, dateTime, subTarget = '') {
|
|
97
|
+
return `hmsh:${this.appVersion.id}:s:${key}:${dateTime}${subTarget ? ':' + subTarget : ''}`;
|
|
98
|
+
}
|
|
99
|
+
aggregateData(rawData) {
|
|
100
|
+
const aggregatedData = {};
|
|
101
|
+
let count = 0;
|
|
102
|
+
Object.entries(rawData).forEach(([_, data]) => {
|
|
103
|
+
for (const key in data) {
|
|
104
|
+
if (key.startsWith('count:')) {
|
|
105
|
+
const target = key.slice('count:'.length);
|
|
106
|
+
if (!aggregatedData[target]) {
|
|
107
|
+
aggregatedData[target] = 0;
|
|
108
|
+
}
|
|
109
|
+
aggregatedData[target] += data[key];
|
|
110
|
+
}
|
|
111
|
+
else if (key === 'count') {
|
|
112
|
+
count += data[key];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return [count, aggregatedData];
|
|
117
|
+
}
|
|
118
|
+
buildStatsResponse(rawData, redisKeys, aggregatedData, count, options) {
|
|
119
|
+
const measures = [];
|
|
120
|
+
const measureKeys = Object.keys(aggregatedData).filter((key) => key !== 'count');
|
|
121
|
+
let segments = undefined;
|
|
122
|
+
if (options.sparse !== true) {
|
|
123
|
+
segments = this.handleSegments(rawData, redisKeys);
|
|
124
|
+
}
|
|
125
|
+
measureKeys.forEach((key) => {
|
|
126
|
+
const measure = {
|
|
127
|
+
target: key,
|
|
128
|
+
type: 'count',
|
|
129
|
+
value: aggregatedData[key],
|
|
130
|
+
};
|
|
131
|
+
measures.push(measure);
|
|
132
|
+
});
|
|
133
|
+
const response = {
|
|
134
|
+
key: options.key,
|
|
135
|
+
granularity: options.granularity,
|
|
136
|
+
range: options.range,
|
|
137
|
+
end: options.end,
|
|
138
|
+
count,
|
|
139
|
+
measures: measures,
|
|
140
|
+
};
|
|
141
|
+
if (segments) {
|
|
142
|
+
response.segments = segments;
|
|
143
|
+
}
|
|
144
|
+
return response;
|
|
145
|
+
}
|
|
146
|
+
handleSegments(data, hashKeys) {
|
|
147
|
+
const segments = [];
|
|
148
|
+
hashKeys.forEach((hashKey, index) => {
|
|
149
|
+
const segmentData = [];
|
|
150
|
+
data[hashKey] &&
|
|
151
|
+
Object.entries(data[hashKey]).forEach(([key, value]) => {
|
|
152
|
+
if (key.startsWith('count:')) {
|
|
153
|
+
const target = key.slice('count:'.length);
|
|
154
|
+
segmentData.push({ target, type: 'count', value });
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const isoTimestamp = this.isoTimestampFromKeyTimestamp(hashKey);
|
|
158
|
+
const count = data[hashKey] ? data[hashKey].count : 0;
|
|
159
|
+
segments.push({ count, time: isoTimestamp, measures: segmentData });
|
|
160
|
+
});
|
|
161
|
+
return segments;
|
|
162
|
+
}
|
|
163
|
+
isoTimestampFromKeyTimestamp(hashKey) {
|
|
164
|
+
if (hashKey.endsWith(':')) {
|
|
165
|
+
return '0';
|
|
166
|
+
}
|
|
167
|
+
const keyTimestamp = hashKey.slice(-12);
|
|
168
|
+
const year = keyTimestamp.slice(0, 4);
|
|
169
|
+
const month = keyTimestamp.slice(4, 6);
|
|
170
|
+
const day = keyTimestamp.slice(6, 8);
|
|
171
|
+
const hour = keyTimestamp.slice(8, 10);
|
|
172
|
+
const minute = keyTimestamp.slice(10, 12);
|
|
173
|
+
return `${year}-${month}-${day}T${hour}:${minute}Z`;
|
|
174
|
+
}
|
|
175
|
+
async getIds(options, facets, idRange = [0, -1]) {
|
|
176
|
+
if (!facets.length) {
|
|
177
|
+
const stats = await this.getStats(options);
|
|
178
|
+
facets = this.getUniqueFacets(stats);
|
|
179
|
+
}
|
|
180
|
+
const { key, granularity, range, end, start } = options;
|
|
181
|
+
this.validateOptions(options);
|
|
182
|
+
let redisKeys = [];
|
|
183
|
+
facets.forEach((facet) => {
|
|
184
|
+
const dateTimeSets = this.generateDateTimeSets(granularity, range, end, start);
|
|
185
|
+
redisKeys = redisKeys.concat(dateTimeSets.map((dateTime) => this.buildRedisKey(key, dateTime, `index:${facet}`)));
|
|
186
|
+
});
|
|
187
|
+
const idsData = await this.store.getJobIds(redisKeys, idRange);
|
|
188
|
+
const idsResponse = this.buildIdsResponse(idsData, options, facets);
|
|
189
|
+
return idsResponse;
|
|
190
|
+
}
|
|
191
|
+
buildIdsResponse(idsData, options, facets) {
|
|
192
|
+
const countsByFacet = {};
|
|
193
|
+
const measureKeys = Object.keys(idsData);
|
|
194
|
+
measureKeys.forEach((key) => {
|
|
195
|
+
const target = this.getTargetForKey(key);
|
|
196
|
+
const count = idsData[key].length;
|
|
197
|
+
if (countsByFacet[target]) {
|
|
198
|
+
countsByFacet[target] += count;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
countsByFacet[target] = count;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
const counts = Object.entries(countsByFacet).map(([facet, count]) => ({ facet, count }));
|
|
205
|
+
const response = {
|
|
206
|
+
key: options.key,
|
|
207
|
+
facets,
|
|
208
|
+
granularity: options.granularity,
|
|
209
|
+
range: options.range,
|
|
210
|
+
start: options.start,
|
|
211
|
+
counts,
|
|
212
|
+
segments: this.buildTimeSegments(idsData),
|
|
213
|
+
};
|
|
214
|
+
return response;
|
|
215
|
+
}
|
|
216
|
+
buildTimeSegments(idsData) {
|
|
217
|
+
const measureKeys = Object.keys(idsData);
|
|
218
|
+
const timeSegments = {};
|
|
219
|
+
measureKeys.forEach((key) => {
|
|
220
|
+
const measure = {
|
|
221
|
+
type: 'ids',
|
|
222
|
+
target: this.getTargetForKey(key),
|
|
223
|
+
time: this.isoTimestampFromKeyTimestamp(this.getTargetForTime(key)),
|
|
224
|
+
count: idsData[key].length,
|
|
225
|
+
ids: idsData[key],
|
|
226
|
+
};
|
|
227
|
+
if (timeSegments[measure.time]) {
|
|
228
|
+
timeSegments[measure.time].push(measure);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
timeSegments[measure.time] = [measure];
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
const segments = Object.entries(timeSegments).map(([time, measures]) => ({
|
|
235
|
+
time,
|
|
236
|
+
measures,
|
|
237
|
+
}));
|
|
238
|
+
return segments;
|
|
239
|
+
}
|
|
240
|
+
getUniqueFacets(data) {
|
|
241
|
+
const targets = data.measures.map((measure) => measure.target);
|
|
242
|
+
return Array.from(new Set(targets));
|
|
243
|
+
}
|
|
244
|
+
getTargetForKey(key) {
|
|
245
|
+
return key.split(':index:')[1];
|
|
246
|
+
}
|
|
247
|
+
getTargetForTime(key) {
|
|
248
|
+
return key.split(':index:')[0];
|
|
249
|
+
}
|
|
250
|
+
async getWorkItems(options, facets) {
|
|
251
|
+
if (!facets.length) {
|
|
252
|
+
const stats = await this.getStats(options);
|
|
253
|
+
facets = this.getUniqueFacets(stats);
|
|
254
|
+
}
|
|
255
|
+
const { key, granularity, range, end, start } = options;
|
|
256
|
+
this.validateOptions(options);
|
|
257
|
+
let redisKeys = [];
|
|
258
|
+
facets.forEach((facet) => {
|
|
259
|
+
const dateTimeSets = this.generateDateTimeSets(granularity, range, end, start);
|
|
260
|
+
redisKeys = redisKeys.concat(dateTimeSets.map((dateTime) => this.buildRedisKey(key, dateTime, `index:${facet}`)));
|
|
261
|
+
});
|
|
262
|
+
const idsData = await this.store.getJobIds(redisKeys, [0, 1]);
|
|
263
|
+
const workerLists = this.buildWorkerLists(idsData);
|
|
264
|
+
return workerLists;
|
|
265
|
+
}
|
|
266
|
+
buildWorkerLists(idsData) {
|
|
267
|
+
const workerLists = [];
|
|
268
|
+
for (const key in idsData) {
|
|
269
|
+
if (idsData[key].length) {
|
|
270
|
+
workerLists.push(key);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return workerLists;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* called by `trigger` activity to generate the stats that should
|
|
277
|
+
* be saved to the database. doesn't actually save the stats, but
|
|
278
|
+
* just generates the info that should be saved
|
|
279
|
+
*/
|
|
280
|
+
resolveTriggerStatistics({ stats: statsConfig }, context) {
|
|
281
|
+
const stats = {
|
|
282
|
+
general: [],
|
|
283
|
+
index: [],
|
|
284
|
+
median: [],
|
|
285
|
+
};
|
|
286
|
+
stats.general.push({ metric: 'count', target: 'count', value: 1 });
|
|
287
|
+
for (const measure of statsConfig.measures) {
|
|
288
|
+
const metric = this.resolveMetric({ metric: measure.measure, target: measure.target }, context);
|
|
289
|
+
if (this.isGeneralMetric(measure.measure)) {
|
|
290
|
+
stats.general.push(metric);
|
|
291
|
+
}
|
|
292
|
+
else if (this.isMedianMetric(measure.measure)) {
|
|
293
|
+
stats.median.push(metric);
|
|
294
|
+
}
|
|
295
|
+
else if (this.isIndexMetric(measure.measure)) {
|
|
296
|
+
stats.index.push(metric);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return stats;
|
|
300
|
+
}
|
|
301
|
+
isGeneralMetric(metric) {
|
|
302
|
+
return ReporterService.isGeneralMetric(metric);
|
|
303
|
+
}
|
|
304
|
+
isMedianMetric(metric) {
|
|
305
|
+
return ReporterService.isMedianMetric(metric);
|
|
306
|
+
}
|
|
307
|
+
isIndexMetric(metric) {
|
|
308
|
+
return ReporterService.isIndexMetric(metric);
|
|
309
|
+
}
|
|
310
|
+
static isGeneralMetric(metric) {
|
|
311
|
+
return metric === 'sum' || metric === 'avg' || metric === 'count';
|
|
312
|
+
}
|
|
313
|
+
static isMedianMetric(metric) {
|
|
314
|
+
return metric === 'mdn';
|
|
315
|
+
}
|
|
316
|
+
static isIndexMetric(metric) {
|
|
317
|
+
return metric === 'index';
|
|
318
|
+
}
|
|
319
|
+
resolveMetric({ metric, target }, context) {
|
|
320
|
+
const pipe = new pipe_1.Pipe([[target]], context);
|
|
321
|
+
const resolvedValue = pipe.process().toString();
|
|
322
|
+
const resolvedTarget = this.resolveTarget(metric, target, resolvedValue);
|
|
323
|
+
if (metric === 'index') {
|
|
324
|
+
return { metric, target: resolvedTarget, value: context.metadata.jid };
|
|
325
|
+
}
|
|
326
|
+
else if (metric === 'count') {
|
|
327
|
+
return { metric, target: resolvedTarget, value: 1 };
|
|
328
|
+
}
|
|
329
|
+
return { metric, target: resolvedTarget, value: resolvedValue };
|
|
330
|
+
}
|
|
331
|
+
isCardinalMetric(metric) {
|
|
332
|
+
return metric === 'index' || metric === 'count';
|
|
333
|
+
}
|
|
334
|
+
resolveTarget(metric, target, resolvedValue) {
|
|
335
|
+
const trimmed = target.substring(1, target.length - 1);
|
|
336
|
+
const trimmedTarget = trimmed.split('.').slice(3).join('/');
|
|
337
|
+
let resolvedTarget;
|
|
338
|
+
if (this.isCardinalMetric(metric)) {
|
|
339
|
+
resolvedTarget = `${metric}:${trimmedTarget}:${resolvedValue}`;
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
resolvedTarget = `${metric}:${trimmedTarget}`;
|
|
343
|
+
}
|
|
344
|
+
return resolvedTarget;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
exports.ReporterService = ReporterService;
|
|
348
|
+
ReporterService.DEFAULT_GRANULARITY = '5m';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HMSH_BLOCK_TIME_MS, HMSH_MAX_RETRIES, HMSH_MAX_TIMEOUT_MS, HMSH_GRADUATED_INTERVAL_MS, HMSH_CODE_UNACKED, HMSH_CODE_UNKNOWN, HMSH_STATUS_UNKNOWN, HMSH_XCLAIM_COUNT, HMSH_XCLAIM_DELAY_MS, HMSH_XPENDING_COUNT, MAX_DELAY, MAX_STREAM_BACKOFF, INITIAL_STREAM_BACKOFF, MAX_STREAM_RETRIES } from '../../../modules/enums';
|
|
2
|
+
import { RouterConfig } from '../../../types/stream';
|
|
3
|
+
export declare class RouterConfigManager {
|
|
4
|
+
static validateThrottle(delayInMillis: number): void;
|
|
5
|
+
static setDefaults(config: RouterConfig): RouterConfig & {
|
|
6
|
+
reclaimDelay: number;
|
|
7
|
+
reclaimCount: number;
|
|
8
|
+
readonly: boolean;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export { HMSH_BLOCK_TIME_MS, HMSH_MAX_RETRIES, HMSH_MAX_TIMEOUT_MS, HMSH_GRADUATED_INTERVAL_MS, HMSH_CODE_UNACKED, HMSH_CODE_UNKNOWN, HMSH_STATUS_UNKNOWN, HMSH_XCLAIM_COUNT, HMSH_XCLAIM_DELAY_MS, HMSH_XPENDING_COUNT, MAX_DELAY, MAX_STREAM_BACKOFF, INITIAL_STREAM_BACKOFF, MAX_STREAM_RETRIES, };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_STREAM_RETRIES = exports.INITIAL_STREAM_BACKOFF = exports.MAX_STREAM_BACKOFF = exports.MAX_DELAY = exports.HMSH_XPENDING_COUNT = exports.HMSH_XCLAIM_DELAY_MS = exports.HMSH_XCLAIM_COUNT = exports.HMSH_STATUS_UNKNOWN = exports.HMSH_CODE_UNKNOWN = exports.HMSH_CODE_UNACKED = exports.HMSH_GRADUATED_INTERVAL_MS = exports.HMSH_MAX_TIMEOUT_MS = exports.HMSH_MAX_RETRIES = exports.HMSH_BLOCK_TIME_MS = exports.RouterConfigManager = void 0;
|
|
4
|
+
const enums_1 = require("../../../modules/enums");
|
|
5
|
+
Object.defineProperty(exports, "HMSH_BLOCK_TIME_MS", { enumerable: true, get: function () { return enums_1.HMSH_BLOCK_TIME_MS; } });
|
|
6
|
+
Object.defineProperty(exports, "HMSH_MAX_RETRIES", { enumerable: true, get: function () { return enums_1.HMSH_MAX_RETRIES; } });
|
|
7
|
+
Object.defineProperty(exports, "HMSH_MAX_TIMEOUT_MS", { enumerable: true, get: function () { return enums_1.HMSH_MAX_TIMEOUT_MS; } });
|
|
8
|
+
Object.defineProperty(exports, "HMSH_GRADUATED_INTERVAL_MS", { enumerable: true, get: function () { return enums_1.HMSH_GRADUATED_INTERVAL_MS; } });
|
|
9
|
+
Object.defineProperty(exports, "HMSH_CODE_UNACKED", { enumerable: true, get: function () { return enums_1.HMSH_CODE_UNACKED; } });
|
|
10
|
+
Object.defineProperty(exports, "HMSH_CODE_UNKNOWN", { enumerable: true, get: function () { return enums_1.HMSH_CODE_UNKNOWN; } });
|
|
11
|
+
Object.defineProperty(exports, "HMSH_STATUS_UNKNOWN", { enumerable: true, get: function () { return enums_1.HMSH_STATUS_UNKNOWN; } });
|
|
12
|
+
Object.defineProperty(exports, "HMSH_XCLAIM_COUNT", { enumerable: true, get: function () { return enums_1.HMSH_XCLAIM_COUNT; } });
|
|
13
|
+
Object.defineProperty(exports, "HMSH_XCLAIM_DELAY_MS", { enumerable: true, get: function () { return enums_1.HMSH_XCLAIM_DELAY_MS; } });
|
|
14
|
+
Object.defineProperty(exports, "HMSH_XPENDING_COUNT", { enumerable: true, get: function () { return enums_1.HMSH_XPENDING_COUNT; } });
|
|
15
|
+
Object.defineProperty(exports, "MAX_DELAY", { enumerable: true, get: function () { return enums_1.MAX_DELAY; } });
|
|
16
|
+
Object.defineProperty(exports, "MAX_STREAM_BACKOFF", { enumerable: true, get: function () { return enums_1.MAX_STREAM_BACKOFF; } });
|
|
17
|
+
Object.defineProperty(exports, "INITIAL_STREAM_BACKOFF", { enumerable: true, get: function () { return enums_1.INITIAL_STREAM_BACKOFF; } });
|
|
18
|
+
Object.defineProperty(exports, "MAX_STREAM_RETRIES", { enumerable: true, get: function () { return enums_1.MAX_STREAM_RETRIES; } });
|
|
19
|
+
class RouterConfigManager {
|
|
20
|
+
static validateThrottle(delayInMillis) {
|
|
21
|
+
if (!Number.isInteger(delayInMillis) ||
|
|
22
|
+
delayInMillis < 0 ||
|
|
23
|
+
delayInMillis > enums_1.MAX_DELAY) {
|
|
24
|
+
throw new Error(`Throttle must be a non-negative integer and not exceed ${enums_1.MAX_DELAY} ms; send -1 to throttle indefinitely`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
static setDefaults(config) {
|
|
28
|
+
return {
|
|
29
|
+
...config,
|
|
30
|
+
reclaimDelay: config.reclaimDelay || enums_1.HMSH_XCLAIM_DELAY_MS,
|
|
31
|
+
reclaimCount: config.reclaimCount || enums_1.HMSH_XCLAIM_COUNT,
|
|
32
|
+
readonly: config.readonly || false,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.RouterConfigManager = RouterConfigManager;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ILogger } from '../../logger';
|
|
2
|
+
import { StreamService } from '../../stream';
|
|
3
|
+
import { ThrottleManager } from '../throttling';
|
|
4
|
+
import { ErrorHandler } from '../error-handling';
|
|
5
|
+
import { LifecycleManager } from '../lifecycle';
|
|
6
|
+
import { StreamData, StreamDataResponse } from '../../../types/stream';
|
|
7
|
+
import { ProviderClient, ProviderTransaction } from '../../../types/provider';
|
|
8
|
+
export declare class ConsumptionManager<S extends StreamService<ProviderClient, ProviderTransaction>> {
|
|
9
|
+
private stream;
|
|
10
|
+
private logger;
|
|
11
|
+
private throttleManager;
|
|
12
|
+
private errorHandler;
|
|
13
|
+
private lifecycleManager;
|
|
14
|
+
private reclaimDelay;
|
|
15
|
+
private reclaimCount;
|
|
16
|
+
private appId;
|
|
17
|
+
private role;
|
|
18
|
+
private errorCount;
|
|
19
|
+
private counts;
|
|
20
|
+
private hasReachedMaxBackoff;
|
|
21
|
+
private router;
|
|
22
|
+
constructor(stream: S, logger: ILogger, throttleManager: ThrottleManager, errorHandler: ErrorHandler, lifecycleManager: LifecycleManager<S>, reclaimDelay: number, reclaimCount: number, appId: string, role: any, router: any);
|
|
23
|
+
createGroup(stream: string, group: string): Promise<void>;
|
|
24
|
+
publishMessage(topic: string, streamData: StreamData | StreamDataResponse, transaction?: ProviderTransaction): Promise<string | ProviderTransaction>;
|
|
25
|
+
consumeMessages(stream: string, group: string, consumer: string, callback: (streamData: StreamData) => Promise<StreamDataResponse | void>): Promise<void>;
|
|
26
|
+
private consumeWithNotifications;
|
|
27
|
+
private consumeWithPolling;
|
|
28
|
+
consumeOne(stream: string, group: string, id: string, input: StreamData, callback: (streamData: StreamData) => Promise<StreamDataResponse | void>): Promise<void>;
|
|
29
|
+
execStreamLeg(input: StreamData, stream: string, id: string, callback: (streamData: StreamData) => Promise<StreamDataResponse | void>): Promise<StreamDataResponse>;
|
|
30
|
+
ackAndDelete(stream: string, group: string, id: string): Promise<void>;
|
|
31
|
+
ackAndDeleteBatch(stream: string, group: string, ids: string[]): Promise<void>;
|
|
32
|
+
publishResponse(input: StreamData, output: StreamDataResponse | void): Promise<string>;
|
|
33
|
+
isStreamMessage(result: any): boolean;
|
|
34
|
+
}
|