@worker-manager/metrics 1.0.0 → 1.1.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/README.md +86 -6
- package/dist/HistoryAdmin.d.ts +23 -87
- package/dist/HistoryAdmin.js +21 -330
- package/dist/HistoryAdmin.js.map +1 -1
- package/dist/HistoryStore.d.ts +9 -9
- package/dist/HistoryStore.js +22 -0
- package/dist/HistoryStore.js.map +1 -1
- package/dist/LatencySampler.d.ts +27 -32
- package/dist/LatencySampler.js +55 -156
- package/dist/LatencySampler.js.map +1 -1
- package/dist/LatencyStore.d.ts +8 -3
- package/dist/LatencyStore.js +18 -0
- package/dist/LatencyStore.js.map +1 -1
- package/dist/MetricsRecorder.d.ts +34 -10
- package/dist/MetricsRecorder.js +30 -20
- package/dist/MetricsRecorder.js.map +1 -1
- package/dist/RedisHistoryAdmin.d.ts +95 -0
- package/dist/RedisHistoryAdmin.js +328 -0
- package/dist/RedisHistoryAdmin.js.map +1 -0
- package/dist/RedisMetricsHistoryProvider.d.ts +7 -17
- package/dist/RedisMetricsHistoryProvider.js +9 -136
- package/dist/RedisMetricsHistoryProvider.js.map +1 -1
- package/dist/RedisMetricsStore.d.ts +27 -0
- package/dist/RedisMetricsStore.js +42 -0
- package/dist/RedisMetricsStore.js.map +1 -0
- package/dist/StoreHistoryProvider.d.ts +27 -0
- package/dist/StoreHistoryProvider.js +127 -0
- package/dist/StoreHistoryProvider.js.map +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/jobSources.d.ts +97 -0
- package/dist/jobSources.js +248 -0
- package/dist/jobSources.js.map +1 -0
- package/dist/keys.d.ts +7 -0
- package/dist/keys.js +23 -1
- package/dist/keys.js.map +1 -1
- package/dist/postgres/PostgresMetricsHistoryProvider.d.ts +37 -0
- package/dist/postgres/PostgresMetricsHistoryProvider.js +30 -0
- package/dist/postgres/PostgresMetricsHistoryProvider.js.map +1 -0
- package/dist/postgres/PostgresMetricsStore.d.ts +65 -0
- package/dist/postgres/PostgresMetricsStore.js +88 -0
- package/dist/postgres/PostgresMetricsStore.js.map +1 -0
- package/dist/postgres/admin.d.ts +31 -0
- package/dist/postgres/admin.js +178 -0
- package/dist/postgres/admin.js.map +1 -0
- package/dist/postgres/connection.d.ts +53 -0
- package/dist/postgres/connection.js +54 -0
- package/dist/postgres/connection.js.map +1 -0
- package/dist/postgres/context.d.ts +29 -0
- package/dist/postgres/context.js +76 -0
- package/dist/postgres/context.js.map +1 -0
- package/dist/postgres/schema.d.ts +26 -0
- package/dist/postgres/schema.js +148 -0
- package/dist/postgres/schema.js.map +1 -0
- package/dist/postgres/stores.d.ts +51 -0
- package/dist/postgres/stores.js +252 -0
- package/dist/postgres/stores.js.map +1 -0
- package/dist/store.d.ts +80 -0
- package/dist/store.js +3 -0
- package/dist/store.js.map +1 -0
- package/package.json +13 -3
package/dist/HistoryAdmin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HistoryAdmin.js","sourceRoot":"","sources":["../src/HistoryAdmin.ts"],"names":[],"mappings":";;;AA6FA,0CA0BC;AAvHD,6CAMsB;AACtB,iCAAkG;AAElG,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,KAAK,GAAG,GAAG,CAAC;AAClB,uEAAuE;AACvE,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAC1C,MAAM,OAAO,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAC3E;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AA4DjD;;;;;;;;;;;GAWG;AACH,SAAgB,eAAe,CAAC,GAAW,EAAE,SAAiB;IAC5D,MAAM,MAAM,GAAG,GAAG,SAAS,GAAG,CAAC;IAC/B,IAAI,C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AO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAqB,EAAE;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACF;AA5BD,kDA4BC"}
|
package/dist/HistoryStore.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { MetricsClient } from './connection';
|
|
2
|
+
import type { MinutePoint } from './dataMapping';
|
|
2
3
|
import { type MetricsKeys } from './keys';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
hours: number;
|
|
8
|
-
/** Days of daily totals, which is what the shipped charts read. */
|
|
9
|
-
days: number;
|
|
10
|
-
}
|
|
11
|
-
export declare class HistoryStore {
|
|
4
|
+
import type { CounterStore, Retention } from './store';
|
|
5
|
+
export type { Retention } from './store';
|
|
6
|
+
/** The Redis `CounterStore`: one hash per queue, metric and day, rolled up by one EVAL. */
|
|
7
|
+
export declare class HistoryStore implements CounterStore {
|
|
12
8
|
private readonly redis;
|
|
13
9
|
private readonly keys;
|
|
14
10
|
readonly retention: Retention;
|
|
@@ -18,6 +14,10 @@ export declare class HistoryStore {
|
|
|
18
14
|
retention: Retention;
|
|
19
15
|
});
|
|
20
16
|
upsertMinute(queue: string, metric: string, minute: number, value: number): Promise<void>;
|
|
17
|
+
/** One EVAL per minute, in order, exactly as a caller looping `upsertMinute` would. */
|
|
18
|
+
upsertMinutes(queue: string, metric: string, points: MinutePoint[]): Promise<void>;
|
|
19
|
+
readDailyTotals(queue: string, metric: string, days: string[]): Promise<(number | null)[]>;
|
|
20
|
+
readHours(queue: string, metric: string, days: string[]): Promise<Record<string, number>>;
|
|
21
21
|
/**
|
|
22
22
|
* Raw HMGET of the totals hash: `null` means the day was never recorded, a present
|
|
23
23
|
* string (including `'0'`) means it was. Distinguishing "missing" from "stored zero"
|
package/dist/HistoryStore.js
CHANGED
|
@@ -73,6 +73,7 @@ const SECONDS_PER_DAY = 86400;
|
|
|
73
73
|
function ttl(days) {
|
|
74
74
|
return String(Math.max(1, Math.floor(days * SECONDS_PER_DAY)));
|
|
75
75
|
}
|
|
76
|
+
/** The Redis `CounterStore`: one hash per queue, metric and day, rolled up by one EVAL. */
|
|
76
77
|
class HistoryStore {
|
|
77
78
|
constructor(opts) {
|
|
78
79
|
this.redis = opts.redis;
|
|
@@ -87,6 +88,27 @@ class HistoryStore {
|
|
|
87
88
|
const day = (0, keys_1.minuteToDay)(minute);
|
|
88
89
|
await this.redis.eval(UPSERT_MINUTE, 6, this.keys.day(queue, metric, day), this.keys.hour(queue, metric, day), this.keys.totals(queue, metric), this.keys.day(keys_1.GLOBAL_QUEUE, metric, day), this.keys.hour(keys_1.GLOBAL_QUEUE, metric, day), this.keys.totals(keys_1.GLOBAL_QUEUE, metric), String(minute), String((0, keys_1.minuteToHour)(minute)), day, String(value), ttl(this.retention.minutes), ttl(this.retention.hours), ttl(this.retention.days), (0, keys_1.shiftDay)(day, -this.retention.days));
|
|
89
90
|
}
|
|
91
|
+
/** One EVAL per minute, in order, exactly as a caller looping `upsertMinute` would. */
|
|
92
|
+
async upsertMinutes(queue, metric, points) {
|
|
93
|
+
for (const point of points) {
|
|
94
|
+
await this.upsertMinute(queue, metric, point.minute, point.value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async readDailyTotals(queue, metric, days) {
|
|
98
|
+
const raw = await this.readDailyTotalsRaw(queue, metric, days);
|
|
99
|
+
return raw.map((value) => (value == null ? null : Number(value) || 0));
|
|
100
|
+
}
|
|
101
|
+
async readHours(queue, metric, days) {
|
|
102
|
+
var _a;
|
|
103
|
+
const out = {};
|
|
104
|
+
const perDay = await Promise.all(days.map((day) => this.readDayHours(queue, metric, day)));
|
|
105
|
+
for (const hours of perDay) {
|
|
106
|
+
for (const field of Object.keys(hours)) {
|
|
107
|
+
out[field] = ((_a = out[field]) !== null && _a !== void 0 ? _a : 0) + hours[field];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
90
112
|
/**
|
|
91
113
|
* Raw HMGET of the totals hash: `null` means the day was never recorded, a present
|
|
92
114
|
* string (including `'0'`) means it was. Distinguishing "missing" from "stored zero"
|
package/dist/HistoryStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HistoryStore.js","sourceRoot":"","sources":["../src/HistoryStore.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"HistoryStore.js","sourceRoot":"","sources":["../src/HistoryStore.ts"],"names":[],"mappings":";;;AAEA,iCAA6F;AAK7F;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CrB,CAAC;AAEF,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B,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,2FAA2F;AAC3F,MAAa,YAAY;IAKvB,YAAY,IAAuE;QACjF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG;YACf,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACxD,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACpD,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI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CAAC,CAAC;QACtD,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,GAAW;QACvC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,GAAG,GAA2B,EAAE,CAAC;QACvC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACrC,GAAG,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAxHD,oCAwHC"}
|
package/dist/LatencySampler.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { BaseAdapter } from '@worker-manager/api/baseAdapter';
|
|
2
2
|
import type { MetricsClient } from './connection';
|
|
3
3
|
import type { MetricsKeys } from './keys';
|
|
4
|
-
import type {
|
|
4
|
+
import type { LatencyStorage } from './store';
|
|
5
5
|
export interface LatencySamplerOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Redis to read Redis-backed queues through. The recorder passes its Redis store's client,
|
|
8
|
+
* which is the queues' Redis in the classic setup. Omitted, each adapter's own client is
|
|
9
|
+
* used. PostgreSQL-backed queues are always read through their own pool.
|
|
10
|
+
*/
|
|
11
|
+
redis?: MetricsClient;
|
|
12
|
+
/** Unused since the lease and watermark moved into `store`. Accepted for compatibility. */
|
|
13
|
+
keys?: MetricsKeys;
|
|
14
|
+
store: LatencyStorage;
|
|
9
15
|
/** Recorder tick, used to size the lease and to bound a cold start. */
|
|
10
16
|
tickMs: number;
|
|
11
17
|
/** Above this, the tick subsamples uniformly rather than fetching every job. */
|
|
@@ -26,24 +32,26 @@ export interface LatencySamplerOptions {
|
|
|
26
32
|
onError?: (error: unknown, queueName: string) => void;
|
|
27
33
|
}
|
|
28
34
|
/**
|
|
29
|
-
* Copies job durations out of
|
|
35
|
+
* Copies job durations out of a queue's finished jobs on the recorder's tick.
|
|
36
|
+
*
|
|
37
|
+
* Both backends index finished jobs by finish time (Redis: the completed and failed sorted
|
|
38
|
+
* sets; PostgreSQL: `job_finished_idx`), so scanning past a stored watermark returns exactly
|
|
39
|
+
* the jobs finished since the last tick, with no gaps and no bias. The only loss is a queue
|
|
40
|
+
* whose removeOnComplete trims faster than the tick runs.
|
|
30
41
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* last tick, with no gaps and no bias. The only loss is a queue whose removeOnComplete
|
|
35
|
-
* trims faster than the tick runs.
|
|
42
|
+
* Where the durations are read from (a `JobSource`) and where they are written to (a
|
|
43
|
+
* `LatencyStorage`) are independent: the watermark, margin, lease and subsampling logic
|
|
44
|
+
* here is the same for every combination.
|
|
36
45
|
*/
|
|
37
46
|
export declare class LatencySampler {
|
|
38
47
|
private readonly redis;
|
|
39
|
-
private readonly keys;
|
|
40
48
|
private readonly store;
|
|
41
49
|
private readonly tickMs;
|
|
42
50
|
private readonly maxSamples;
|
|
43
51
|
private readonly safetyMarginMs;
|
|
44
52
|
private readonly onError?;
|
|
45
53
|
private readonly id;
|
|
46
|
-
private readonly
|
|
54
|
+
private readonly sources;
|
|
47
55
|
constructor(opts: LatencySamplerOptions);
|
|
48
56
|
static supports(adapter: BaseAdapter): boolean;
|
|
49
57
|
/**
|
|
@@ -53,21 +61,15 @@ export declare class LatencySampler {
|
|
|
53
61
|
* indistinguishable from a queue with nothing to sample.
|
|
54
62
|
*/
|
|
55
63
|
sample(adapter: BaseAdapter): Promise<void>;
|
|
56
|
-
/** `getQueueKey` answers for a PostgreSQL-backed queue too, with keys no Redis holds. */
|
|
57
|
-
private isRedisBacked;
|
|
58
64
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* not lock the queue out forever. The normal path releases in a finally, because a lease
|
|
64
|
-
* outliving its scan would make the next tick no-op and halve the sampling rate.
|
|
65
|
+
* PostgreSQL first, because `getQueueKey` answers for a PostgreSQL-backed queue too, with
|
|
66
|
+
* keys no Redis holds: reading those would record a reassuring zero backlog forever. A Redis
|
|
67
|
+
* source is only used once the adapter confirms it really sits on Redis. Cached per queue,
|
|
68
|
+
* since a queue does not change datastores while the board runs.
|
|
65
69
|
*/
|
|
66
|
-
private
|
|
67
|
-
/** Compare and delete, so a lease that already expired and was retaken is left alone. */
|
|
68
|
-
private releaseLease;
|
|
70
|
+
private sourceFor;
|
|
69
71
|
/**
|
|
70
|
-
* Bounded rather than eternal: an unexpiring watermark would leave one
|
|
72
|
+
* Bounded rather than eternal: an unexpiring watermark would leave one entry behind per
|
|
71
73
|
* queue forever once that queue is purged or decommissioned, which is exactly the
|
|
72
74
|
* unbounded-storage failure this package exists to avoid. The day retention is already the
|
|
73
75
|
* horizon everything else here is bounded by. Losing the watermark just means the next
|
|
@@ -76,13 +78,6 @@ export declare class LatencySampler {
|
|
|
76
78
|
private watermarkTtlSeconds;
|
|
77
79
|
private sampleDurations;
|
|
78
80
|
private flush;
|
|
79
|
-
/**
|
|
80
|
-
* The backlog is not all in one place. `wait` holds it while the queue is running, but
|
|
81
|
-
* pausing RENAMEs that list to `paused` and routes new jobs there, and anything added with
|
|
82
|
-
* a priority goes to the `prioritized` sorted set instead, which can leave `wait`
|
|
83
|
-
* permanently empty. Reading only `wait` reports a healthy zero for a queue that is badly
|
|
84
|
-
* backed up, which is the opposite of what this gauge is for, so all three are consulted
|
|
85
|
-
* and the worst age wins.
|
|
86
|
-
*/
|
|
81
|
+
/** A tick that could not read the backlog cleanly records nothing, see `JobSource`. */
|
|
87
82
|
private sampleQueueAge;
|
|
88
83
|
}
|
package/dist/LatencySampler.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LatencySampler = void 0;
|
|
4
4
|
const histogram_1 = require("./histogram");
|
|
5
|
+
const jobSources_1 = require("./jobSources");
|
|
5
6
|
const MS_PER_HOUR = 3600000;
|
|
6
7
|
const SECONDS_PER_DAY = 86400;
|
|
7
8
|
const DEFAULT_MAX_SAMPLES = 5000;
|
|
@@ -13,28 +14,30 @@ const DEFAULT_MAX_SAMPLES = 5000;
|
|
|
13
14
|
* means anything finishing inside the margin is picked up by the next tick instead.
|
|
14
15
|
* Costs a few seconds of freshness in data that is bucketed hourly.
|
|
15
16
|
*
|
|
16
|
-
* The score is `Date.now()` read in the worker process and passed into BullMQ's Lua
|
|
17
|
-
*
|
|
17
|
+
* The score is `Date.now()` read in the worker process and passed into BullMQ's Lua (or SQL),
|
|
18
|
+
* not a datastore clock, so the margin only holds while the worker and this recorder agree on
|
|
18
19
|
* the time: the effective margin is `margin - skew`. A worker running far enough ahead of
|
|
19
20
|
* the recorder can still land jobs below an already-advanced watermark and lose them.
|
|
20
21
|
*/
|
|
21
22
|
const SAFETY_MARGIN_MS = 5000;
|
|
22
23
|
/**
|
|
23
|
-
* Copies job durations out of
|
|
24
|
+
* Copies job durations out of a queue's finished jobs on the recorder's tick.
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* Both backends index finished jobs by finish time (Redis: the completed and failed sorted
|
|
27
|
+
* sets; PostgreSQL: `job_finished_idx`), so scanning past a stored watermark returns exactly
|
|
28
|
+
* the jobs finished since the last tick, with no gaps and no bias. The only loss is a queue
|
|
29
|
+
* whose removeOnComplete trims faster than the tick runs.
|
|
30
|
+
*
|
|
31
|
+
* Where the durations are read from (a `JobSource`) and where they are written to (a
|
|
32
|
+
* `LatencyStorage`) are independent: the watermark, margin, lease and subsampling logic
|
|
33
|
+
* here is the same for every combination.
|
|
30
34
|
*/
|
|
31
35
|
class LatencySampler {
|
|
32
36
|
constructor(opts) {
|
|
33
37
|
var _a, _b;
|
|
34
38
|
this.id = `${process.pid}-${Math.random().toString(36).slice(2)}`;
|
|
35
|
-
this.
|
|
39
|
+
this.sources = new Map();
|
|
36
40
|
this.redis = opts.redis;
|
|
37
|
-
this.keys = opts.keys;
|
|
38
41
|
this.store = opts.store;
|
|
39
42
|
this.tickMs = opts.tickMs;
|
|
40
43
|
this.maxSamples = (_a = opts.maxSamplesPerTick) !== null && _a !== void 0 ? _a : DEFAULT_MAX_SAMPLES;
|
|
@@ -57,18 +60,19 @@ class LatencySampler {
|
|
|
57
60
|
}
|
|
58
61
|
const name = adapter.getName();
|
|
59
62
|
try {
|
|
60
|
-
|
|
63
|
+
const source = await this.sourceFor(adapter, name);
|
|
64
|
+
if (!source) {
|
|
61
65
|
return;
|
|
62
66
|
}
|
|
63
|
-
if (!(await this.acquireLease(name))) {
|
|
67
|
+
if (!(await this.store.acquireLease(name, this.id, this.tickMs * 2))) {
|
|
64
68
|
return;
|
|
65
69
|
}
|
|
66
70
|
try {
|
|
67
|
-
await this.sampleDurations(
|
|
68
|
-
await this.sampleQueueAge(
|
|
71
|
+
await this.sampleDurations(source, name);
|
|
72
|
+
await this.sampleQueueAge(source, name);
|
|
69
73
|
}
|
|
70
74
|
finally {
|
|
71
|
-
await this.releaseLease(name);
|
|
75
|
+
await this.store.releaseLease(name, this.id);
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
catch (error) {
|
|
@@ -81,35 +85,27 @@ class LatencySampler {
|
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
|
-
/** `getQueueKey` answers for a PostgreSQL-backed queue too, with keys no Redis holds. */
|
|
85
|
-
async isRedisBacked(adapter, name) {
|
|
86
|
-
const known = this.redisBacked.get(name);
|
|
87
|
-
if (known !== undefined) {
|
|
88
|
-
return known;
|
|
89
|
-
}
|
|
90
|
-
const backed = (await adapter.getRedisInfo()) !== null;
|
|
91
|
-
this.redisBacked.set(name, backed);
|
|
92
|
-
return backed;
|
|
93
|
-
}
|
|
94
88
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* not lock the queue out forever. The normal path releases in a finally, because a lease
|
|
100
|
-
* outliving its scan would make the next tick no-op and halve the sampling rate.
|
|
89
|
+
* PostgreSQL first, because `getQueueKey` answers for a PostgreSQL-backed queue too, with
|
|
90
|
+
* keys no Redis holds: reading those would record a reassuring zero backlog forever. A Redis
|
|
91
|
+
* source is only used once the adapter confirms it really sits on Redis. Cached per queue,
|
|
92
|
+
* since a queue does not change datastores while the board runs.
|
|
101
93
|
*/
|
|
102
|
-
async
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
94
|
+
async sourceFor(adapter, name) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
if (this.sources.has(name)) {
|
|
97
|
+
return (_a = this.sources.get(name)) !== null && _a !== void 0 ? _a : null;
|
|
98
|
+
}
|
|
99
|
+
let source = (0, jobSources_1.postgresSourceOf)(adapter);
|
|
100
|
+
if (!source && (await adapter.getRedisInfo()) !== null) {
|
|
101
|
+
const client = (_b = this.redis) !== null && _b !== void 0 ? _b : (typeof adapter.getClient === 'function' ? await adapter.getClient() : null);
|
|
102
|
+
source = client ? new jobSources_1.RedisJobSource(client, adapter) : null;
|
|
103
|
+
}
|
|
104
|
+
this.sources.set(name, source);
|
|
105
|
+
return source;
|
|
110
106
|
}
|
|
111
107
|
/**
|
|
112
|
-
* Bounded rather than eternal: an unexpiring watermark would leave one
|
|
108
|
+
* Bounded rather than eternal: an unexpiring watermark would leave one entry behind per
|
|
113
109
|
* queue forever once that queue is purged or decommissioned, which is exactly the
|
|
114
110
|
* unbounded-storage failure this package exists to avoid. The day retention is already the
|
|
115
111
|
* horizon everything else here is bounded by. Losing the watermark just means the next
|
|
@@ -118,74 +114,45 @@ class LatencySampler {
|
|
|
118
114
|
watermarkTtlSeconds() {
|
|
119
115
|
return Math.max(1, Math.floor(this.store.retention.days * SECONDS_PER_DAY));
|
|
120
116
|
}
|
|
121
|
-
async sampleDurations(
|
|
122
|
-
|
|
123
|
-
const watermarkRaw = await this.redis.get(this.keys.watermark(name));
|
|
117
|
+
async sampleDurations(source, name) {
|
|
118
|
+
const stored = await this.store.readWatermark(name);
|
|
124
119
|
// Cold start covers one tick ending at the safety bound rather than backfilling, since a
|
|
125
120
|
// first run against a large completed set would be a surprise fetch storm. Ending at the
|
|
126
121
|
// bound rather than at now is what keeps a tick shorter than the margin from producing a
|
|
127
122
|
// window that is empty on every tick, leaving the watermark stuck forever.
|
|
128
|
-
const watermark =
|
|
129
|
-
? Number(watermarkRaw)
|
|
130
|
-
: Date.now() - this.tickMs - this.safetyMarginMs;
|
|
123
|
+
const watermark = stored !== null && stored !== void 0 ? stored : Date.now() - this.tickMs - this.safetyMarginMs;
|
|
131
124
|
const upperBound = Date.now() - this.safetyMarginMs;
|
|
132
125
|
if (upperBound <= watermark) {
|
|
133
126
|
return; // ticks closer together than the margin; next tick covers this range
|
|
134
127
|
}
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
ids.push(...found);
|
|
139
|
-
}
|
|
140
|
-
if (ids.length === 0) {
|
|
141
|
-
await this.redis.set(this.keys.watermark(name), String(upperBound), 'EX', this.watermarkTtlSeconds());
|
|
128
|
+
const { total, sampled, jobs } = await source.finishedJobs(watermark, upperBound, this.maxSamples);
|
|
129
|
+
if (total === 0) {
|
|
130
|
+
await this.store.writeWatermark(name, upperBound, this.watermarkTtlSeconds());
|
|
142
131
|
return;
|
|
143
132
|
}
|
|
144
|
-
// The id list is one cheap round trip; the HMGETs are the real cost. Above the cap take
|
|
145
|
-
// a uniform subset rather than the first N, which would bias towards the tick's start.
|
|
146
|
-
const selected = ids.length > this.maxSamples ? sampleUniformly(ids, this.maxSamples) : ids;
|
|
147
133
|
// Counts are scaled back up by this ratio, so a subsampled hour reads as an estimate
|
|
148
134
|
// with the same shape rather than a dip. The fact that it was subsampled is currently
|
|
149
135
|
// invisible to clients: marking it would mean persisting a flag alongside the packed
|
|
150
136
|
// vector, which is a storage-format change. Known follow-up.
|
|
151
|
-
const ratio =
|
|
152
|
-
const pipeline = this.redis.pipeline();
|
|
153
|
-
for (const id of selected) {
|
|
154
|
-
pipeline.hmget(adapter.getQueueKey(String(id)), 'timestamp', 'processedOn', 'finishedOn',
|
|
155
|
-
// BullMQ 5 counts attempts in `atm`; `attemptsMade` is the pre-v5 name and is read
|
|
156
|
-
// as a fallback exactly the way Job.fromJSON does.
|
|
157
|
-
'atm', 'attemptsMade');
|
|
158
|
-
}
|
|
159
|
-
const rows = await pipeline.exec();
|
|
137
|
+
const ratio = total / Math.max(1, sampled);
|
|
160
138
|
const runByHour = new Map();
|
|
161
139
|
const waitByHour = new Map();
|
|
162
|
-
for (const
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
const [timestamp, processedOn, finishedOn, atm, attemptsMade] = values;
|
|
168
|
-
if (!processedOn || !finishedOn) {
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
const finished = Number(finishedOn);
|
|
172
|
-
const processed = Number(processedOn);
|
|
173
|
-
const hour = Math.floor(finished / MS_PER_HOUR);
|
|
174
|
-
observe(runByHour, hour, finished - processed, ratio);
|
|
140
|
+
for (const job of jobs) {
|
|
141
|
+
const hour = Math.floor(job.finishedOn / MS_PER_HOUR);
|
|
142
|
+
observe(runByHour, hour, job.finishedOn - job.processedOn, ratio);
|
|
175
143
|
// A retried job's timestamp is its creation, but processedOn is the latest attempt,
|
|
176
144
|
// so wait would absorb every prior attempt and backoff. Run time is unaffected.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
// Every one of these is a Date.now() taken in some client process, not a Redis-side
|
|
145
|
+
if (job.timestamp !== null && job.attempts <= 1) {
|
|
146
|
+
// Every one of these is a Date.now() taken in some client process, not a datastore
|
|
180
147
|
// clock: timestamp in the producer, processedOn in the worker. Skew between the two
|
|
181
148
|
// can make the difference negative, hence the clamp.
|
|
182
|
-
observe(waitByHour, hour, Math.max(0,
|
|
149
|
+
observe(waitByHour, hour, Math.max(0, job.processedOn - job.timestamp), ratio);
|
|
183
150
|
}
|
|
184
151
|
}
|
|
185
152
|
await this.flush(name, 'runtime', runByHour);
|
|
186
153
|
await this.flush(name, 'waittime', waitByHour);
|
|
187
154
|
// The bound, not the highest score observed. See SAFETY_MARGIN_MS.
|
|
188
|
-
await this.
|
|
155
|
+
await this.store.writeWatermark(name, upperBound, this.watermarkTtlSeconds());
|
|
189
156
|
}
|
|
190
157
|
async flush(name, metric, byHour) {
|
|
191
158
|
for (const [hour, vector] of byHour) {
|
|
@@ -195,73 +162,14 @@ class LatencySampler {
|
|
|
195
162
|
await this.store.addSamples(name, metric, hour, vector.map((v) => Math.round(v)));
|
|
196
163
|
}
|
|
197
164
|
}
|
|
198
|
-
/**
|
|
199
|
-
|
|
200
|
-
* pausing RENAMEs that list to `paused` and routes new jobs there, and anything added with
|
|
201
|
-
* a priority goes to the `prioritized` sorted set instead, which can leave `wait`
|
|
202
|
-
* permanently empty. Reading only `wait` reports a healthy zero for a queue that is badly
|
|
203
|
-
* backed up, which is the opposite of what this gauge is for, so all three are consulted
|
|
204
|
-
* and the worst age wins.
|
|
205
|
-
*/
|
|
206
|
-
async sampleQueueAge(adapter, name) {
|
|
207
|
-
var _a;
|
|
165
|
+
/** A tick that could not read the backlog cleanly records nothing, see `JobSource`. */
|
|
166
|
+
async sampleQueueAge(source, name) {
|
|
208
167
|
const hour = Math.floor(Date.now() / MS_PER_HOUR);
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
// BullMQ LPUSHes to the wait list and workers RPOPLPUSH from it, so the tail is oldest.
|
|
212
|
-
.lrange(adapter.getQueueKey('wait'), -1, -1)
|
|
213
|
-
.lrange(adapter.getQueueKey('paused'), -1, -1)
|
|
214
|
-
// The prioritized set is scored by priority, not by time, so neither end is guaranteed
|
|
215
|
-
// to hold the oldest job. Both ends are an approximation, and a cheap one: the true
|
|
216
|
-
// oldest would mean fetching the whole set every tick.
|
|
217
|
-
// String indices: ioredis v6 types `zrange`'s stop arg as string-only (Redis coerces
|
|
218
|
-
// either way), so numeric literals no longer typecheck. '0'/'-1' are the first/last members.
|
|
219
|
-
.zrange(adapter.getQueueKey('prioritized'), '0', '0')
|
|
220
|
-
.zrange(adapter.getQueueKey('prioritized'), '-1', '-1')
|
|
221
|
-
.exec();
|
|
222
|
-
// A pipeline reports failures per command: a Redis error arrives in the entry's error
|
|
223
|
-
// slot next to a null result, rather than as a throw. Reading only the result slot turns
|
|
224
|
-
// a failed read into an empty backlog and records an age of 0, which is the most
|
|
225
|
-
// reassuring number this gauge can produce, at the moment it is least entitled to. A gap
|
|
226
|
-
// in the series reads as "not measured" and is recoverable; a zero is a wrong answer that
|
|
227
|
-
// looks like a healthy one, so a tick that could not read cleanly records nothing.
|
|
228
|
-
if (!candidates || candidates.some(([error]) => error)) {
|
|
168
|
+
const age = await source.oldestWaitingAge(Date.now());
|
|
169
|
+
if (age === null) {
|
|
229
170
|
return;
|
|
230
171
|
}
|
|
231
|
-
|
|
232
|
-
for (const entry of candidates) {
|
|
233
|
-
for (const id of (_a = entry[1]) !== null && _a !== void 0 ? _a : []) {
|
|
234
|
-
ids.add(String(id));
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
if (ids.size === 0) {
|
|
238
|
-
await this.store.recordQueueAge(name, hour, 0);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
const stamps = this.redis.pipeline();
|
|
242
|
-
for (const id of ids) {
|
|
243
|
-
stamps.hget(adapter.getQueueKey(id), 'timestamp');
|
|
244
|
-
}
|
|
245
|
-
const rows = await stamps.exec();
|
|
246
|
-
// Same reasoning: a failed timestamp read does not zero the gauge, it understates it,
|
|
247
|
-
// which is the same wrong-but-reassuring answer in a quieter form.
|
|
248
|
-
if (!rows || rows.some(([error]) => error)) {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
const now = Date.now();
|
|
252
|
-
let oldest = 0;
|
|
253
|
-
for (const row of rows) {
|
|
254
|
-
const raw = row[1];
|
|
255
|
-
if (!raw) {
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
const enqueuedAt = Number(raw);
|
|
259
|
-
if (!Number.isFinite(enqueuedAt)) {
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
oldest = Math.max(oldest, now - enqueuedAt);
|
|
263
|
-
}
|
|
264
|
-
await this.store.recordQueueAge(name, hour, Math.max(0, oldest));
|
|
172
|
+
await this.store.recordQueueAge(name, hour, age);
|
|
265
173
|
}
|
|
266
174
|
}
|
|
267
175
|
exports.LatencySampler = LatencySampler;
|
|
@@ -273,13 +181,4 @@ function observe(byHour, hour, durationMs, ratio) {
|
|
|
273
181
|
}
|
|
274
182
|
vector[(0, histogram_1.bucketIndex)(durationMs)] += ratio;
|
|
275
183
|
}
|
|
276
|
-
/** Evenly spaced pick across the list, which preserves the distribution's shape. */
|
|
277
|
-
function sampleUniformly(ids, target) {
|
|
278
|
-
const stride = ids.length / target;
|
|
279
|
-
const out = [];
|
|
280
|
-
for (let i = 0; i < target; i++) {
|
|
281
|
-
out.push(ids[Math.floor(i * stride)]);
|
|
282
|
-
}
|
|
283
|
-
return out;
|
|
284
|
-
}
|
|
285
184
|
//# sourceMappingURL=LatencySampler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LatencySampler.js","sourceRoot":"","sources":["../src/LatencySampler.ts"],"names":[],"mappings":";;;AAEA,2CAAuD;
|
|
1
|
+
{"version":3,"file":"LatencySampler.js","sourceRoot":"","sources":["../src/LatencySampler.ts"],"names":[],"mappings":";;;AAEA,2CAAuD;AACvD,6CAAgF;AAIhF,MAAM,WAAW,GAAG,OAAO,CAAC;AAC5B,MAAM,eAAe,GAAG,KAAK,CAAC;AAC9B,MAAM,mBAAmB,GAAG,IAAI,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M,EAAE,CAAC;YACpC,gFAAgF;YAChF,gFAAgF;YAChF,4BAA4B;YAC5B,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CACzB,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACjC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,uFAAuF;IAC/E,KAAK,CAAC,cAAc,CAAC,MAAiB,EAAE,IAAY;QAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,CAAC;QAClD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACtD,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QACD,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC;CACF;AAzKD,wCAyKC;AAED,SAAS,OAAO,CACd,MAA6B,EAC7B,IAAY,EACZ,UAAkB,EAClB,KAAa;IAEb,IAAI,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,IAAA,uBAAW,GAAE,CAAC;QACvB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC;IACD,MAAM,CAAC,IAAA,uBAAW,EAAC,UAAU,CAAC,CAAC,IAAI,KAAK,CAAC;AAC3C,CAAC"}
|
package/dist/LatencyStore.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { MetricsClient } from './connection';
|
|
2
|
-
import type { Retention } from './HistoryStore';
|
|
3
2
|
import { type MetricsKeys } from './keys';
|
|
4
|
-
|
|
3
|
+
import type { LatencyMetric, LatencyStorage, Retention } from './store';
|
|
4
|
+
export type { LatencyMetric } from './store';
|
|
5
5
|
export declare const QUEUE_AGE_METRIC = "queueage";
|
|
6
|
-
|
|
6
|
+
/** The Redis `LatencyStorage`: packed vectors in hour and totals hashes, one EVAL per write. */
|
|
7
|
+
export declare class LatencyStore implements LatencyStorage {
|
|
7
8
|
private readonly redis;
|
|
8
9
|
private readonly keys;
|
|
9
10
|
readonly retention: Retention;
|
|
@@ -16,6 +17,10 @@ export declare class LatencyStore {
|
|
|
16
17
|
recordQueueAge(queue: string, hour: number, ms: number): Promise<void>;
|
|
17
18
|
readRange(queue: string, metric: LatencyMetric, granularity: 'hour' | 'day', days: string[]): Promise<Record<string, number[]>>;
|
|
18
19
|
readQueueAge(queue: string, granularity: 'hour' | 'day', days: string[]): Promise<Record<string, number>>;
|
|
20
|
+
acquireLease(queue: string, holder: string, ttlMs: number): Promise<boolean>;
|
|
21
|
+
releaseLease(queue: string, holder: string): Promise<void>;
|
|
22
|
+
readWatermark(queue: string): Promise<number | null>;
|
|
23
|
+
writeWatermark(queue: string, ms: number, ttlSeconds: number): Promise<void>;
|
|
19
24
|
/** Epoch ms for an absolute hour index, for building response timestamps. */
|
|
20
25
|
static hourToMs(hour: number): number;
|
|
21
26
|
}
|