@worker-manager/metrics 1.1.0 → 9.10.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/README.md +6 -86
- package/dist/HistoryAdmin.d.ts +87 -23
- package/dist/HistoryAdmin.js +330 -21
- package/dist/HistoryAdmin.js.map +1 -1
- package/dist/HistoryStore.d.ts +9 -9
- package/dist/HistoryStore.js +0 -22
- package/dist/HistoryStore.js.map +1 -1
- package/dist/LatencySampler.d.ts +32 -27
- package/dist/LatencySampler.js +156 -55
- package/dist/LatencySampler.js.map +1 -1
- package/dist/LatencyStore.d.ts +3 -8
- package/dist/LatencyStore.js +0 -18
- package/dist/LatencyStore.js.map +1 -1
- package/dist/MetricsRecorder.d.ts +10 -34
- package/dist/MetricsRecorder.js +20 -30
- package/dist/MetricsRecorder.js.map +1 -1
- package/dist/RedisMetricsHistoryProvider.d.ts +17 -7
- package/dist/RedisMetricsHistoryProvider.js +136 -9
- package/dist/RedisMetricsHistoryProvider.js.map +1 -1
- package/dist/index.d.ts +2 -10
- package/dist/index.js +1 -10
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +0 -7
- package/dist/keys.js +1 -23
- package/dist/keys.js.map +1 -1
- package/package.json +4 -14
- package/dist/RedisHistoryAdmin.d.ts +0 -95
- package/dist/RedisHistoryAdmin.js +0 -328
- package/dist/RedisHistoryAdmin.js.map +0 -1
- package/dist/RedisMetricsStore.d.ts +0 -27
- package/dist/RedisMetricsStore.js +0 -42
- package/dist/RedisMetricsStore.js.map +0 -1
- package/dist/StoreHistoryProvider.d.ts +0 -27
- package/dist/StoreHistoryProvider.js +0 -127
- package/dist/StoreHistoryProvider.js.map +0 -1
- package/dist/jobSources.d.ts +0 -97
- package/dist/jobSources.js +0 -248
- package/dist/jobSources.js.map +0 -1
- package/dist/postgres/PostgresMetricsHistoryProvider.d.ts +0 -37
- package/dist/postgres/PostgresMetricsHistoryProvider.js +0 -30
- package/dist/postgres/PostgresMetricsHistoryProvider.js.map +0 -1
- package/dist/postgres/PostgresMetricsStore.d.ts +0 -65
- package/dist/postgres/PostgresMetricsStore.js +0 -88
- package/dist/postgres/PostgresMetricsStore.js.map +0 -1
- package/dist/postgres/admin.d.ts +0 -31
- package/dist/postgres/admin.js +0 -178
- package/dist/postgres/admin.js.map +0 -1
- package/dist/postgres/connection.d.ts +0 -53
- package/dist/postgres/connection.js +0 -54
- package/dist/postgres/connection.js.map +0 -1
- package/dist/postgres/context.d.ts +0 -29
- package/dist/postgres/context.js +0 -76
- package/dist/postgres/context.js.map +0 -1
- package/dist/postgres/schema.d.ts +0 -26
- package/dist/postgres/schema.js +0 -148
- package/dist/postgres/schema.js.map +0 -1
- package/dist/postgres/stores.d.ts +0 -51
- package/dist/postgres/stores.js +0 -252
- package/dist/postgres/stores.js.map +0 -1
- package/dist/store.d.ts +0 -80
- package/dist/store.js +0 -3
- package/dist/store.js.map +0 -1
package/dist/LatencyStore.js
CHANGED
|
@@ -152,10 +152,6 @@ if newDay then
|
|
|
152
152
|
end
|
|
153
153
|
return 1
|
|
154
154
|
`;
|
|
155
|
-
/** Compare and delete, so a lease that already expired and was retaken is left alone. */
|
|
156
|
-
const RELEASE_LEASE = `if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('DEL', KEYS[1]) end
|
|
157
|
-
return 0`;
|
|
158
|
-
/** The Redis `LatencyStorage`: packed vectors in hour and totals hashes, one EVAL per write. */
|
|
159
155
|
class LatencyStore {
|
|
160
156
|
constructor(opts) {
|
|
161
157
|
this.redis = opts.redis;
|
|
@@ -213,20 +209,6 @@ class LatencyStore {
|
|
|
213
209
|
}
|
|
214
210
|
return out;
|
|
215
211
|
}
|
|
216
|
-
async acquireLease(queue, holder, ttlMs) {
|
|
217
|
-
const held = await this.redis.set(this.keys.lease(queue), holder, 'PX', ttlMs, 'NX');
|
|
218
|
-
return held === 'OK';
|
|
219
|
-
}
|
|
220
|
-
async releaseLease(queue, holder) {
|
|
221
|
-
await this.redis.eval(RELEASE_LEASE, 1, this.keys.lease(queue), holder);
|
|
222
|
-
}
|
|
223
|
-
async readWatermark(queue) {
|
|
224
|
-
const raw = await this.redis.get(this.keys.watermark(queue));
|
|
225
|
-
return raw ? Number(raw) : null;
|
|
226
|
-
}
|
|
227
|
-
async writeWatermark(queue, ms, ttlSeconds) {
|
|
228
|
-
await this.redis.set(this.keys.watermark(queue), String(ms), 'EX', ttlSeconds);
|
|
229
|
-
}
|
|
230
212
|
/** Epoch ms for an absolute hour index, for building response timestamps. */
|
|
231
213
|
static hourToMs(hour) {
|
|
232
214
|
return hour * MS_PER_HOUR;
|
package/dist/LatencyStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LatencyStore.js","sourceRoot":"","sources":["../src/LatencyStore.ts"],"names":[],"mappings":";;;AACA,2CAAmF;
|
|
1
|
+
{"version":3,"file":"LatencyStore.js","sourceRoot":"","sources":["../src/LatencyStore.ts"],"names":[],"mappings":";;;AACA,2CAAmF;AAEnF,iCAA+E;AAIlE,QAAA,gBAAgB,GAAG,UAAU,CAAC;AAE3C,MAAM,eAAe,GAAG,KAAK,CAAC;AAC9B,MAAM,WAAW,GAAG,OAAO,CAAC;AAE5B,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CjB,CAAC;AAEF,MAAa,YAAY;IAKvB,YAAY,IAAuE;QACjF,IAA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AC,GAAG,CAC9B,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,wBAAgB,EAAE,GAAG,CAAC,CAAC,CAAC,CACpF,CAAC;QACF,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACzB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAA,GAAG,CAAC,KAAK,CAAC,mCAAI,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,6EAA6E;IAC7E,MAAM,CAAC,QAAQ,CAAC,IAAY;QAC1B,OAAO,IAAI,GAAG,WAAW,CAAC;IAC5B,CAAC;CACF;AAlHD,oCAkHC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BaseAdapter } from '@worker-manager/api/baseAdapter';
|
|
2
|
-
import type
|
|
3
|
-
import
|
|
2
|
+
import { type MetricsConnection } from './connection';
|
|
3
|
+
import { type Retention } from './HistoryStore';
|
|
4
4
|
/**
|
|
5
5
|
* Minute detail is the expensive tier by two orders of magnitude, so it defaults to a week
|
|
6
6
|
* rather than the full window: long enough to match the recommended `MetricsTime.ONE_WEEK`
|
|
@@ -8,8 +8,12 @@ import type { MetricsStore, Retention } from './store';
|
|
|
8
8
|
* The hourly and daily rollups are cheap enough to keep for the whole window.
|
|
9
9
|
*/
|
|
10
10
|
export declare const DEFAULT_RETENTION: Retention;
|
|
11
|
-
interface
|
|
12
|
-
/**
|
|
11
|
+
export interface MetricsRecorderOptions {
|
|
12
|
+
/**
|
|
13
|
+
* A function is resolved on every tick, for a board whose queue set changes while it
|
|
14
|
+
* runs. An array is read once, at construction.
|
|
15
|
+
*/
|
|
16
|
+
queues: BaseAdapter[] | (() => BaseAdapter[]);
|
|
13
17
|
connection: MetricsConnection;
|
|
14
18
|
/**
|
|
15
19
|
* Redis key namespace, defaulting to `bull-board:metrics`. Set it to separate two boards
|
|
@@ -21,24 +25,6 @@ interface RedisOptions {
|
|
|
21
25
|
* tag to choose the slot yourself.
|
|
22
26
|
*/
|
|
23
27
|
prefix?: string;
|
|
24
|
-
store?: never;
|
|
25
|
-
}
|
|
26
|
-
interface StoreOptions {
|
|
27
|
-
/**
|
|
28
|
-
* Where history is written, e.g. `new PostgresMetricsStore({ connection, migrate: true })`
|
|
29
|
-
* for a board with no Redis. The recorder never closes a store it was handed.
|
|
30
|
-
*/
|
|
31
|
-
store: MetricsStore;
|
|
32
|
-
connection?: never;
|
|
33
|
-
prefix?: never;
|
|
34
|
-
}
|
|
35
|
-
export type MetricsRecorderOptions = RecorderBaseOptions & (RedisOptions | StoreOptions);
|
|
36
|
-
interface RecorderBaseOptions {
|
|
37
|
-
/**
|
|
38
|
-
* A function is resolved on every tick, for a board whose queue set changes while it
|
|
39
|
-
* runs. An array is read once, at construction.
|
|
40
|
-
*/
|
|
41
|
-
queues: BaseAdapter[] | (() => BaseAdapter[]);
|
|
42
28
|
/** Per-resolution retention in days. Unspecified tiers fall back to the defaults. */
|
|
43
29
|
retention?: Partial<Retention>;
|
|
44
30
|
/**
|
|
@@ -71,12 +57,6 @@ interface RecorderBaseOptions {
|
|
|
71
57
|
* wire this to your logger to tell an empty chart from a broken one.
|
|
72
58
|
*/
|
|
73
59
|
onLatencyError?: (error: unknown, queueName: string) => void;
|
|
74
|
-
/**
|
|
75
|
-
* Notified when a scheduled snapshot fails, say because the store is unreachable. The
|
|
76
|
-
* timer keeps running and the next tick retries; without a listener the failure is
|
|
77
|
-
* dropped rather than surfacing as an unhandled rejection.
|
|
78
|
-
*/
|
|
79
|
-
onSnapshotError?: (error: unknown) => void;
|
|
80
60
|
}
|
|
81
61
|
export declare function resolveRetention(opts: {
|
|
82
62
|
retention?: Partial<Retention>;
|
|
@@ -85,8 +65,8 @@ export declare function resolveRetention(opts: {
|
|
|
85
65
|
export declare class MetricsRecorder {
|
|
86
66
|
private readonly resolveQueues;
|
|
87
67
|
private readonly store;
|
|
88
|
-
|
|
89
|
-
private readonly
|
|
68
|
+
private readonly redis;
|
|
69
|
+
private readonly ownsRedis;
|
|
90
70
|
private readonly intervalMs;
|
|
91
71
|
private readonly lastMinute;
|
|
92
72
|
private timer;
|
|
@@ -94,13 +74,10 @@ export declare class MetricsRecorder {
|
|
|
94
74
|
private stopped;
|
|
95
75
|
readonly latencyEnabled: boolean;
|
|
96
76
|
private readonly latencySampler;
|
|
97
|
-
private readonly onSnapshotError?;
|
|
98
77
|
constructor(opts: MetricsRecorderOptions);
|
|
99
78
|
get retention(): Retention;
|
|
100
79
|
start(): void;
|
|
101
|
-
/** Stops the timer and closes a connection the recorder opened. A store handed in stays open. */
|
|
102
80
|
stop(): void;
|
|
103
|
-
private scheduledSnapshot;
|
|
104
81
|
snapshot(): Promise<void>;
|
|
105
82
|
/**
|
|
106
83
|
* Incrementally copies BullMQ's per-minute ring buffer into long-retention storage.
|
|
@@ -113,4 +90,3 @@ export declare class MetricsRecorder {
|
|
|
113
90
|
*/
|
|
114
91
|
private snapshotOne;
|
|
115
92
|
}
|
|
116
|
-
export {};
|
package/dist/MetricsRecorder.js
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MetricsRecorder = exports.DEFAULT_RETENTION = void 0;
|
|
4
4
|
exports.resolveRetention = resolveRetention;
|
|
5
|
+
const connection_1 = require("./connection");
|
|
5
6
|
const dataMapping_1 = require("./dataMapping");
|
|
7
|
+
const HistoryStore_1 = require("./HistoryStore");
|
|
8
|
+
const keys_1 = require("./keys");
|
|
6
9
|
const LatencySampler_1 = require("./LatencySampler");
|
|
7
|
-
const
|
|
10
|
+
const LatencyStore_1 = require("./LatencyStore");
|
|
8
11
|
const METRICS = ['completed', 'failed'];
|
|
9
12
|
const MS_PER_MINUTE = 60000;
|
|
10
13
|
const MINUTES_PER_DAY = 1440;
|
|
@@ -27,7 +30,7 @@ function resolveRetention(opts) {
|
|
|
27
30
|
}
|
|
28
31
|
class MetricsRecorder {
|
|
29
32
|
constructor(opts) {
|
|
30
|
-
var _a
|
|
33
|
+
var _a;
|
|
31
34
|
this.lastMinute = new Map();
|
|
32
35
|
this.timer = null;
|
|
33
36
|
this.running = false;
|
|
@@ -35,16 +38,17 @@ class MetricsRecorder {
|
|
|
35
38
|
const { queues } = opts;
|
|
36
39
|
this.resolveQueues = typeof queues === 'function' ? queues : () => queues;
|
|
37
40
|
this.intervalMs = (_a = opts.snapshotIntervalMs) !== null && _a !== void 0 ? _a : 60000;
|
|
38
|
-
const
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this.
|
|
41
|
+
const { client, owned } = (0, connection_1.resolveClient)(opts.connection);
|
|
42
|
+
this.redis = client;
|
|
43
|
+
this.ownsRedis = owned;
|
|
44
|
+
const keys = (0, keys_1.metricsKeys)((0, keys_1.resolveNamespace)(opts.prefix, (0, connection_1.isCluster)(client)));
|
|
45
|
+
this.store = new HistoryStore_1.HistoryStore({ redis: this.redis, keys, retention: resolveRetention(opts) });
|
|
43
46
|
this.latencyEnabled = opts.latency !== false;
|
|
44
47
|
this.latencySampler = this.latencyEnabled
|
|
45
48
|
? new LatencySampler_1.LatencySampler({
|
|
46
|
-
redis:
|
|
47
|
-
|
|
49
|
+
redis: this.redis,
|
|
50
|
+
keys,
|
|
51
|
+
store: new LatencyStore_1.LatencyStore({ redis: this.redis, keys, retention: resolveRetention(opts) }),
|
|
48
52
|
tickMs: this.intervalMs,
|
|
49
53
|
maxSamplesPerTick: opts.maxLatencySamplesPerTick,
|
|
50
54
|
safetyMarginMs: opts.latencySafetyMarginMs,
|
|
@@ -59,35 +63,25 @@ class MetricsRecorder {
|
|
|
59
63
|
if (this.timer) {
|
|
60
64
|
return;
|
|
61
65
|
}
|
|
62
|
-
this.timer = setInterval(() =>
|
|
66
|
+
this.timer = setInterval(() => {
|
|
67
|
+
void this.snapshot();
|
|
68
|
+
}, this.intervalMs);
|
|
63
69
|
// Do not keep the event loop alive solely for the recorder.
|
|
64
70
|
if (typeof this.timer.unref === 'function') {
|
|
65
71
|
this.timer.unref();
|
|
66
72
|
}
|
|
67
|
-
this.
|
|
73
|
+
void this.snapshot();
|
|
68
74
|
}
|
|
69
|
-
/** Stops the timer and closes a connection the recorder opened. A store handed in stays open. */
|
|
70
75
|
stop() {
|
|
71
76
|
if (this.timer) {
|
|
72
77
|
clearInterval(this.timer);
|
|
73
78
|
this.timer = null;
|
|
74
79
|
}
|
|
75
|
-
if (this.
|
|
76
|
-
|
|
80
|
+
if (this.ownsRedis && !this.stopped) {
|
|
81
|
+
this.redis.disconnect();
|
|
77
82
|
}
|
|
78
83
|
this.stopped = true;
|
|
79
84
|
}
|
|
80
|
-
scheduledSnapshot() {
|
|
81
|
-
this.snapshot().catch((error) => {
|
|
82
|
-
var _a;
|
|
83
|
-
try {
|
|
84
|
-
(_a = this.onSnapshotError) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
// A throwing reporter must not turn a contained failure into an unhandled one.
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
85
|
async snapshot() {
|
|
92
86
|
if (this.running) {
|
|
93
87
|
return;
|
|
@@ -135,7 +129,6 @@ class MetricsRecorder {
|
|
|
135
129
|
// it. Nothing is lost that could have been retained anyway.
|
|
136
130
|
const oldestWritable = Math.floor(Date.now() / MS_PER_MINUTE) - this.store.retention.minutes * MINUTES_PER_DAY;
|
|
137
131
|
let newest = seenUpTo;
|
|
138
|
-
const fresh = [];
|
|
139
132
|
for (const point of points) {
|
|
140
133
|
if (point.minute <= seenUpTo) {
|
|
141
134
|
break; // points are newest-first; everything older is already stored
|
|
@@ -143,14 +136,11 @@ class MetricsRecorder {
|
|
|
143
136
|
if (point.minute < oldestWritable) {
|
|
144
137
|
break; // ...and everything past here is older still
|
|
145
138
|
}
|
|
146
|
-
|
|
139
|
+
await this.store.upsertMinute(name, metric, point.minute, point.value);
|
|
147
140
|
if (point.minute > newest) {
|
|
148
141
|
newest = point.minute;
|
|
149
142
|
}
|
|
150
143
|
}
|
|
151
|
-
// One call per queue and metric, so a SQL store can make it one transaction. The
|
|
152
|
-
// watermark only moves once the write has landed.
|
|
153
|
-
await this.store.upsertMinutes(name, metric, fresh);
|
|
154
144
|
this.lastMinute.set(cursorKey, newest);
|
|
155
145
|
}
|
|
156
146
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetricsRecorder.js","sourceRoot":"","sources":["../src/MetricsRecorder.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"MetricsRecorder.js","sourceRoot":"","sources":["../src/MetricsRecorder.ts"],"names":[],"mappings":";;;AAwEA,4CAaC;AAnFD,6CAAoG;AACpG,+CAAsD;AACtD,iDAA8D;AAC9D,iCAAuD;AACvD,qDAAkD;AAClD,iDAA8C;AAE9C,MAAM,OAAO,GAAkB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AACvD,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B;;;;;GAKG;AACU,QAAA,iBAAiB,GAAc,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAqDhF,SAAgB,gBAAgB,CAAC,IAGhC;IACC,MAAM,IAAI,GACR,IAAI,CAAC,aAAa,KAAK,SAAS;QAC9B,CAAC,CAAC,yBAAiB;QACnB,CAAC,CAAC;YACE,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,yBAAiB,CAA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mF;QACnF,sFAAsF;QACtF,mFAAmF;QACnF,qFAAqF;QACrF,4DAA4D;QAC5D,MAAM,cAAc,GAClB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,aAAa,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,eAAe,CAAC;QAE1F,IAAI,MAAM,GAAG,QAAQ,CAAC;QACtB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;gBAC7B,MAAM,CAAC,8DAA8D;YACvE,CAAC;YACD,IAAI,KAAK,CAAC,MAAM,GAAG,cAAc,EAAE,CAAC;gBAClC,MAAM,CAAC,6CAA6C;YACtD,CAAC;YACD,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACvE,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;gBAC1B,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YACxB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;CACF;AArID,0CAqIC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
1
|
+
import type { MetricsHistoryPoint, MetricsHistoryProvider, MetricsHistoryQuery, MetricsLatencyPoint, MetricsLatencyQuery } from '@worker-manager/api/typings/app';
|
|
2
|
+
import { type MetricsConnection } from './connection';
|
|
3
|
+
import { type HistoryStats, type PurgeOptions, type PurgeResult } from './HistoryAdmin';
|
|
4
|
+
import { type Retention } from './HistoryStore';
|
|
4
5
|
export interface RedisMetricsHistoryProviderOptions {
|
|
5
6
|
connection: MetricsConnection;
|
|
6
7
|
/** Must match the recorder's. See `MetricsRecorderOptions.prefix`. */
|
|
@@ -9,10 +10,19 @@ export interface RedisMetricsHistoryProviderOptions {
|
|
|
9
10
|
retention?: Partial<Retention>;
|
|
10
11
|
retentionDays?: number;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
private readonly
|
|
13
|
+
export declare class RedisMetricsHistoryProvider implements MetricsHistoryProvider {
|
|
14
|
+
private readonly store;
|
|
15
|
+
private readonly latencyStore;
|
|
16
|
+
private readonly admin;
|
|
17
|
+
private readonly redis;
|
|
18
|
+
private readonly ownsRedis;
|
|
19
|
+
private readonly retentionDays;
|
|
15
20
|
constructor(opts: RedisMetricsHistoryProviderOptions);
|
|
16
|
-
/** Closes the Redis connection this provider opened itself. A client handed in is left open. */
|
|
17
21
|
disconnect(): void;
|
|
22
|
+
/** Backs the board's storage panel. See MetricsHistoryAdmin.stats. */
|
|
23
|
+
getUsage(): Promise<HistoryStats>;
|
|
24
|
+
/** Backs the board's "clear history" action. See MetricsHistoryAdmin.purge. */
|
|
25
|
+
purge(options?: PurgeOptions): Promise<PurgeResult>;
|
|
26
|
+
getHistory(query: MetricsHistoryQuery): Promise<MetricsHistoryPoint[]>;
|
|
27
|
+
getLatency(query: MetricsLatencyQuery): Promise<MetricsLatencyPoint[]>;
|
|
18
28
|
}
|
|
@@ -1,20 +1,147 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RedisMetricsHistoryProvider = void 0;
|
|
4
|
+
const connection_1 = require("./connection");
|
|
5
|
+
const histogram_1 = require("./histogram");
|
|
6
|
+
const HistoryAdmin_1 = require("./HistoryAdmin");
|
|
7
|
+
const HistoryStore_1 = require("./HistoryStore");
|
|
8
|
+
const keys_1 = require("./keys");
|
|
9
|
+
const LatencyStore_1 = require("./LatencyStore");
|
|
4
10
|
const MetricsRecorder_1 = require("./MetricsRecorder");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
/** Serves the board's history charts and storage panel from the Redis store. */
|
|
8
|
-
class RedisMetricsHistoryProvider extends StoreHistoryProvider_1.StoreHistoryProvider {
|
|
11
|
+
const MS_PER_HOUR = 3600000;
|
|
12
|
+
class RedisMetricsHistoryProvider {
|
|
9
13
|
constructor(opts) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
this.
|
|
14
|
+
const { client, owned } = (0, connection_1.resolveClient)(opts.connection);
|
|
15
|
+
this.redis = client;
|
|
16
|
+
this.ownsRedis = owned;
|
|
17
|
+
const keys = (0, keys_1.metricsKeys)((0, keys_1.resolveNamespace)(opts.prefix, (0, connection_1.isCluster)(client)));
|
|
18
|
+
const retention = (0, MetricsRecorder_1.resolveRetention)(opts);
|
|
19
|
+
this.retentionDays = retention.days;
|
|
20
|
+
this.store = new HistoryStore_1.HistoryStore({ redis: this.redis, keys, retention });
|
|
21
|
+
this.latencyStore = new LatencyStore_1.LatencyStore({ redis: this.redis, keys, retention });
|
|
22
|
+
this.admin = new HistoryAdmin_1.MetricsHistoryAdmin({ connection: this.redis, prefix: opts.prefix });
|
|
13
23
|
}
|
|
14
|
-
/** Closes the Redis connection this provider opened itself. A client handed in is left open. */
|
|
15
24
|
disconnect() {
|
|
16
|
-
|
|
25
|
+
if (this.ownsRedis) {
|
|
26
|
+
this.redis.disconnect();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Backs the board's storage panel. See MetricsHistoryAdmin.stats. */
|
|
30
|
+
async getUsage() {
|
|
31
|
+
return this.admin.stats();
|
|
32
|
+
}
|
|
33
|
+
/** Backs the board's "clear history" action. See MetricsHistoryAdmin.purge. */
|
|
34
|
+
async purge(options = {}) {
|
|
35
|
+
return this.admin.purge(options);
|
|
36
|
+
}
|
|
37
|
+
async getHistory(query) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const queue = (_a = query.queue) !== null && _a !== void 0 ? _a : keys_1.GLOBAL_QUEUE;
|
|
40
|
+
// Clamp the span to the retention window so an unbounded `from` (e.g. 0) can't make
|
|
41
|
+
// dayRange produce an unbounded number of day buckets -- older data doesn't exist anyway.
|
|
42
|
+
const maxSpanMs = (this.retentionDays + 1) * 86400000;
|
|
43
|
+
const from = Math.max(query.from, query.to - maxSpanMs);
|
|
44
|
+
const days = (0, keys_1.dayRange)(from, query.to);
|
|
45
|
+
if (query.metric === 'queueage') {
|
|
46
|
+
const ages = await this.latencyStore.readQueueAge(queue, query.granularity, days);
|
|
47
|
+
// Day points are stamped at the day's start, so an intraday `from` would drop the day
|
|
48
|
+
// it falls in. Floored, exactly as the counter path below does it.
|
|
49
|
+
const lowerBound = query.granularity === 'day' ? dayFloor(query.from) : query.from;
|
|
50
|
+
return Object.keys(ages)
|
|
51
|
+
.map((key) => ({
|
|
52
|
+
ts: query.granularity === 'day' ? (0, keys_1.dayToStartMs)(key) : Number(key) * MS_PER_HOUR,
|
|
53
|
+
value: ages[key],
|
|
54
|
+
}))
|
|
55
|
+
.filter((p) => p.ts >= lowerBound && p.ts <= query.to)
|
|
56
|
+
.sort((a, b) => a.ts - b.ts);
|
|
57
|
+
}
|
|
58
|
+
if (query.granularity === 'day') {
|
|
59
|
+
const rawTotals = await this.store.readDailyTotalsRaw(queue, query.metric, days);
|
|
60
|
+
// Empty history only when no day in range was ever recorded (all fields missing).
|
|
61
|
+
// A day with a stored '0' still counts as recorded -- otherwise the UI's empty
|
|
62
|
+
// state would be unreachable once any data exists.
|
|
63
|
+
if (rawTotals.every((value) => value == null)) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
const totals = {};
|
|
67
|
+
days.forEach((day, i) => {
|
|
68
|
+
totals[day] = Number(rawTotals[i]) || 0;
|
|
69
|
+
});
|
|
70
|
+
return days
|
|
71
|
+
.map((day) => { var _a; return ({ ts: (0, keys_1.dayToStartMs)(day), value: (_a = totals[day]) !== null && _a !== void 0 ? _a : 0 }); })
|
|
72
|
+
.filter((p) => p.ts >= dayFloor(query.from) && p.ts <= query.to);
|
|
73
|
+
}
|
|
74
|
+
const hourBuckets = new Map();
|
|
75
|
+
const dayHours = await Promise.all(days.map((day) => this.store.readDayHours(queue, query.metric, day)));
|
|
76
|
+
for (const hours of dayHours) {
|
|
77
|
+
for (const field of Object.keys(hours)) {
|
|
78
|
+
const ts = Number(field) * MS_PER_HOUR;
|
|
79
|
+
if (ts < query.from || ts > query.to) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
hourBuckets.set(ts, ((_b = hourBuckets.get(ts)) !== null && _b !== void 0 ? _b : 0) + hours[field]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return [...hourBuckets.entries()]
|
|
86
|
+
.map(([ts, value]) => ({ ts, value }))
|
|
87
|
+
.sort((a, b) => a.ts - b.ts);
|
|
88
|
+
}
|
|
89
|
+
async getLatency(query) {
|
|
90
|
+
var _a;
|
|
91
|
+
const queue = (_a = query.queue) !== null && _a !== void 0 ? _a : keys_1.GLOBAL_QUEUE;
|
|
92
|
+
const maxSpanMs = (this.retentionDays + 1) * 86400000;
|
|
93
|
+
const from = Math.max(query.from, query.to - maxSpanMs);
|
|
94
|
+
const days = (0, keys_1.dayRange)(from, query.to);
|
|
95
|
+
if (query.granularity === 'range') {
|
|
96
|
+
// Percentiles don't merge: averaging per-day p95s isn't the same number as the p95 of
|
|
97
|
+
// the whole range. Read the day tier's bucket vectors and merge them, then compute each
|
|
98
|
+
// requested percentile once from the summed vector.
|
|
99
|
+
const raw = await this.latencyStore.readRange(queue, query.metric, 'day', days);
|
|
100
|
+
let merged = (0, histogram_1.emptyVector)();
|
|
101
|
+
for (const day of days) {
|
|
102
|
+
const vector = raw[day];
|
|
103
|
+
if (vector) {
|
|
104
|
+
merged = (0, histogram_1.mergeVectors)(merged, vector);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const count = (0, histogram_1.vectorTotal)(merged);
|
|
108
|
+
if (count === 0) {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
const values = {};
|
|
112
|
+
for (const p of query.percentiles) {
|
|
113
|
+
values[String(p)] = (0, histogram_1.quantile)(merged, p);
|
|
114
|
+
}
|
|
115
|
+
return [{ ts: query.from, count: Math.round(count), values }];
|
|
116
|
+
}
|
|
117
|
+
const raw = await this.latencyStore.readRange(queue, query.metric, query.granularity, days);
|
|
118
|
+
// Same day-start alignment as getHistory: comparing a day bucket against a raw `from`
|
|
119
|
+
// would drop the oldest day and leave this chart one bucket shorter than the throughput
|
|
120
|
+
// chart drawn for the same range.
|
|
121
|
+
const lowerBound = query.granularity === 'day' ? dayFloor(query.from) : query.from;
|
|
122
|
+
const points = [];
|
|
123
|
+
for (const key of Object.keys(raw)) {
|
|
124
|
+
const ts = query.granularity === 'day' ? (0, keys_1.dayToStartMs)(key) : Number(key) * MS_PER_HOUR;
|
|
125
|
+
if (ts < lowerBound || ts > query.to) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const vector = raw[key];
|
|
129
|
+
const count = (0, histogram_1.vectorTotal)(vector);
|
|
130
|
+
if (count === 0) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const values = {};
|
|
134
|
+
for (const p of query.percentiles) {
|
|
135
|
+
values[String(p)] = (0, histogram_1.quantile)(vector, p);
|
|
136
|
+
}
|
|
137
|
+
points.push({ ts, count: Math.round(count), values });
|
|
138
|
+
}
|
|
139
|
+
return points.sort((a, b) => a.ts - b.ts);
|
|
17
140
|
}
|
|
18
141
|
}
|
|
19
142
|
exports.RedisMetricsHistoryProvider = RedisMetricsHistoryProvider;
|
|
143
|
+
function dayFloor(ms) {
|
|
144
|
+
const d = new Date(ms);
|
|
145
|
+
return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
146
|
+
}
|
|
20
147
|
//# sourceMappingURL=RedisMetricsHistoryProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisMetricsHistoryProvider.js","sourceRoot":"","sources":["../src/RedisMetricsHistoryProvider.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"RedisMetricsHistoryProvider.js","sourceRoot":"","sources":["../src/RedisMetricsHistoryProvider.ts"],"names":[],"mappings":";;;AAOA,6CAAoG;AACpG,2CAA+E;AAC/E,iDAKwB;AACxB,iDAA8D;AAC9D,iCAA6F;AAC7F,iDAA8C;AAC9C,uDAAqD;AAErD,MAAM,WAAW,GAAG,OAAO,CAAC;AAW5B,MAAa,2BAA2B;IAQtC,YAAY,IAAwC;QAClD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,0BAAa,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,MAAM,IAAI,GAAG,IAAA,kBAAW,EAAC,IAAA,uBAAgB,EAAC,IAAI,CAAC,MAAM,EAAE,IAAA,sBAAS,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC3E,MAAM,SAAS,GAAG,IAAA,kCAAgB,EAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,IAAI,2BAAY,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,YAAY,GAAG,IAAI,2BAAY,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,KAAK,GAAG,IAAI,kCAAmB,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACxF,CAAC;IAED,UAAU;QACR,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,IAA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A,oBAAQ,EAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YAC1C,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF;AAnJD,kEAmJC;AAED,SAAS,QAAQ,CAAC,EAAU;IAC1B,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC;IACvB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;AACvE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
export { MetricsHistoryAdmin } from './HistoryAdmin';
|
|
2
|
-
export type { HistoryQueueStats, HistoryStats,
|
|
2
|
+
export type { HistoryQueueStats, HistoryStats, MetricsHistoryAdminOptions, PurgeOptions, PurgeResult, } from './HistoryAdmin';
|
|
3
3
|
export { MetricsRecorder } from './MetricsRecorder';
|
|
4
4
|
export type { MetricsRecorderOptions } from './MetricsRecorder';
|
|
5
|
-
export type {
|
|
6
|
-
export { RedisMetricsStore } from './RedisMetricsStore';
|
|
7
|
-
export type { RedisMetricsStoreOptions } from './RedisMetricsStore';
|
|
5
|
+
export type { Retention } from './HistoryStore';
|
|
8
6
|
export { RedisMetricsHistoryProvider } from './RedisMetricsHistoryProvider';
|
|
9
7
|
export type { RedisMetricsHistoryProviderOptions } from './RedisMetricsHistoryProvider';
|
|
10
|
-
export { PostgresMetricsStore, migratePostgresMetrics } from './postgres/PostgresMetricsStore';
|
|
11
|
-
export type { MigratePostgresMetricsOptions, PostgresMetricsStoreOptions, } from './postgres/PostgresMetricsStore';
|
|
12
|
-
export { PostgresMetricsHistoryProvider } from './postgres/PostgresMetricsHistoryProvider';
|
|
13
|
-
export type { PostgresMetricsHistoryProviderOptions } from './postgres/PostgresMetricsHistoryProvider';
|
|
14
|
-
export type { PgPool, PostgresConnection, PostgresPoolConfig } from './postgres/connection';
|
|
15
|
-
export { SCHEMA_VERSION as POSTGRES_METRICS_SCHEMA_VERSION } from './postgres/schema';
|
|
16
8
|
export { LatencySampler } from './LatencySampler';
|
|
17
9
|
export type { LatencySamplerOptions } from './LatencySampler';
|
|
18
10
|
export { LatencyStore, QUEUE_AGE_METRIC } from './LatencyStore';
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.quantile = exports.BUCKET_COUNT = exports.BUCKET_BOUNDS = exports.QUEUE_AGE_METRIC = exports.LatencyStore = exports.LatencySampler = exports.
|
|
3
|
+
exports.quantile = exports.BUCKET_COUNT = exports.BUCKET_BOUNDS = exports.QUEUE_AGE_METRIC = exports.LatencyStore = exports.LatencySampler = exports.RedisMetricsHistoryProvider = exports.MetricsRecorder = exports.MetricsHistoryAdmin = void 0;
|
|
4
4
|
var HistoryAdmin_1 = require("./HistoryAdmin");
|
|
5
5
|
Object.defineProperty(exports, "MetricsHistoryAdmin", { enumerable: true, get: function () { return HistoryAdmin_1.MetricsHistoryAdmin; } });
|
|
6
6
|
var MetricsRecorder_1 = require("./MetricsRecorder");
|
|
7
7
|
Object.defineProperty(exports, "MetricsRecorder", { enumerable: true, get: function () { return MetricsRecorder_1.MetricsRecorder; } });
|
|
8
|
-
var RedisMetricsStore_1 = require("./RedisMetricsStore");
|
|
9
|
-
Object.defineProperty(exports, "RedisMetricsStore", { enumerable: true, get: function () { return RedisMetricsStore_1.RedisMetricsStore; } });
|
|
10
8
|
var RedisMetricsHistoryProvider_1 = require("./RedisMetricsHistoryProvider");
|
|
11
9
|
Object.defineProperty(exports, "RedisMetricsHistoryProvider", { enumerable: true, get: function () { return RedisMetricsHistoryProvider_1.RedisMetricsHistoryProvider; } });
|
|
12
|
-
var PostgresMetricsStore_1 = require("./postgres/PostgresMetricsStore");
|
|
13
|
-
Object.defineProperty(exports, "PostgresMetricsStore", { enumerable: true, get: function () { return PostgresMetricsStore_1.PostgresMetricsStore; } });
|
|
14
|
-
Object.defineProperty(exports, "migratePostgresMetrics", { enumerable: true, get: function () { return PostgresMetricsStore_1.migratePostgresMetrics; } });
|
|
15
|
-
var PostgresMetricsHistoryProvider_1 = require("./postgres/PostgresMetricsHistoryProvider");
|
|
16
|
-
Object.defineProperty(exports, "PostgresMetricsHistoryProvider", { enumerable: true, get: function () { return PostgresMetricsHistoryProvider_1.PostgresMetricsHistoryProvider; } });
|
|
17
|
-
var schema_1 = require("./postgres/schema");
|
|
18
|
-
Object.defineProperty(exports, "POSTGRES_METRICS_SCHEMA_VERSION", { enumerable: true, get: function () { return schema_1.SCHEMA_VERSION; } });
|
|
19
10
|
var LatencySampler_1 = require("./LatencySampler");
|
|
20
11
|
Object.defineProperty(exports, "LatencySampler", { enumerable: true, get: function () { return LatencySampler_1.LatencySampler; } });
|
|
21
12
|
var LatencyStore_1 = require("./LatencyStore");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+CAAqD;AAA5C,mHAAA,mBAAmB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+CAAqD;AAA5C,mHAAA,mBAAmB,OAAA;AAQ5B,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AAGxB,6EAA4E;AAAnE,0IAAA,2BAA2B,OAAA;AAEpC,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAEvB,+CAAgE;AAAvD,4GAAA,YAAY,OAAA;AAAE,gHAAA,gBAAgB,OAAA;AAEvC,yCAAoE;AAA3D,0GAAA,aAAa,OAAA;AAAE,yGAAA,YAAY,OAAA;AAAE,qGAAA,QAAQ,OAAA"}
|
package/dist/keys.d.ts
CHANGED
|
@@ -2,16 +2,11 @@ export declare const DEFAULT_NAMESPACE = "bull-board:metrics";
|
|
|
2
2
|
export declare const GLOBAL_QUEUE = "__global__";
|
|
3
3
|
/** Marks the hourly rollup key so it can't be mistaken for a minute-level day hash. */
|
|
4
4
|
export declare const HOUR_TIER = "hour";
|
|
5
|
-
export declare const DAY_PATTERN: RegExp;
|
|
6
|
-
export declare function msToDay(ms: number): string;
|
|
7
5
|
export declare function minuteToDay(minute: number): string;
|
|
8
6
|
/** Absolute hour index, the hourly counterpart of the absolute minute index. */
|
|
9
7
|
export declare function minuteToHour(minute: number): number;
|
|
10
8
|
export declare function shiftDay(day: string, offsetDays: number): string;
|
|
11
9
|
export declare function dayToStartMs(day: string): number;
|
|
12
|
-
/** Days since the epoch, the integer form of an ISO day that SQL buckets use. */
|
|
13
|
-
export declare function dayToIndex(day: string): number;
|
|
14
|
-
export declare function indexToDay(index: number): string;
|
|
15
10
|
export declare function dayRange(fromMs: number, toMs: number): string[];
|
|
16
11
|
export declare function resolveNamespace(prefix: string | undefined, clustered: boolean): string;
|
|
17
12
|
export interface MetricsKeys {
|
|
@@ -24,5 +19,3 @@ export interface MetricsKeys {
|
|
|
24
19
|
scanPattern: string;
|
|
25
20
|
}
|
|
26
21
|
export declare function metricsKeys(namespace: string): MetricsKeys;
|
|
27
|
-
/** An ISO `YYYY-MM-DD` day, validated, from a day string or a Date (UTC). */
|
|
28
|
-
export declare function toDay(value: Date | string): string;
|
package/dist/keys.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.msToDay = msToDay;
|
|
3
|
+
exports.HOUR_TIER = exports.GLOBAL_QUEUE = exports.DEFAULT_NAMESPACE = void 0;
|
|
5
4
|
exports.minuteToDay = minuteToDay;
|
|
6
5
|
exports.minuteToHour = minuteToHour;
|
|
7
6
|
exports.shiftDay = shiftDay;
|
|
8
7
|
exports.dayToStartMs = dayToStartMs;
|
|
9
|
-
exports.dayToIndex = dayToIndex;
|
|
10
|
-
exports.indexToDay = indexToDay;
|
|
11
8
|
exports.dayRange = dayRange;
|
|
12
9
|
exports.resolveNamespace = resolveNamespace;
|
|
13
10
|
exports.metricsKeys = metricsKeys;
|
|
14
|
-
exports.toDay = toDay;
|
|
15
11
|
exports.DEFAULT_NAMESPACE = 'bull-board:metrics';
|
|
16
12
|
exports.GLOBAL_QUEUE = '__global__';
|
|
17
13
|
/** Marks the hourly rollup key so it can't be mistaken for a minute-level day hash. */
|
|
18
14
|
exports.HOUR_TIER = 'hour';
|
|
19
|
-
exports.DAY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
20
15
|
const MS_PER_MINUTE = 60000;
|
|
21
16
|
const MS_PER_DAY = 86400000;
|
|
22
17
|
const MINUTES_PER_HOUR = 60;
|
|
@@ -41,13 +36,6 @@ function dayToStartMs(day) {
|
|
|
41
36
|
const [y, m, d] = day.split('-').map(Number);
|
|
42
37
|
return Date.UTC(y, m - 1, d);
|
|
43
38
|
}
|
|
44
|
-
/** Days since the epoch, the integer form of an ISO day that SQL buckets use. */
|
|
45
|
-
function dayToIndex(day) {
|
|
46
|
-
return Math.floor(dayToStartMs(day) / MS_PER_DAY);
|
|
47
|
-
}
|
|
48
|
-
function indexToDay(index) {
|
|
49
|
-
return msToDay(index * MS_PER_DAY);
|
|
50
|
-
}
|
|
51
39
|
function dayRange(fromMs, toMs) {
|
|
52
40
|
const days = [];
|
|
53
41
|
let cursor = Date.UTC(new Date(fromMs).getUTCFullYear(), new Date(fromMs).getUTCMonth(), new Date(fromMs).getUTCDate());
|
|
@@ -85,14 +73,4 @@ function metricsKeys(namespace) {
|
|
|
85
73
|
scanPattern: `${namespace}:*`,
|
|
86
74
|
};
|
|
87
75
|
}
|
|
88
|
-
/** An ISO `YYYY-MM-DD` day, validated, from a day string or a Date (UTC). */
|
|
89
|
-
function toDay(value) {
|
|
90
|
-
if (typeof value === 'string') {
|
|
91
|
-
if (!exports.DAY_PATTERN.test(value)) {
|
|
92
|
-
throw new Error(`Expected a YYYY-MM-DD day or a Date, got "${value}"`);
|
|
93
|
-
}
|
|
94
|
-
return value;
|
|
95
|
-
}
|
|
96
|
-
return value.toISOString().slice(0, 10);
|
|
97
|
-
}
|
|
98
76
|
//# sourceMappingURL=keys.js.map
|