@fluojs/terminus 1.0.0-beta.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/LICENSE +21 -0
- package/README.ko.md +148 -0
- package/README.md +148 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +8 -0
- package/dist/health-check.d.ts +37 -0
- package/dist/health-check.d.ts.map +1 -0
- package/dist/health-check.js +191 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/indicators/disk.d.ts +31 -0
- package/dist/indicators/disk.d.ts.map +1 -0
- package/dist/indicators/disk.js +73 -0
- package/dist/indicators/drizzle.d.ts +36 -0
- package/dist/indicators/drizzle.d.ts.map +1 -0
- package/dist/indicators/drizzle.js +64 -0
- package/dist/indicators/http.d.ts +33 -0
- package/dist/indicators/http.d.ts.map +1 -0
- package/dist/indicators/http.js +87 -0
- package/dist/indicators/index.d.ts +6 -0
- package/dist/indicators/index.d.ts.map +1 -0
- package/dist/indicators/index.js +5 -0
- package/dist/indicators/memory.d.ts +31 -0
- package/dist/indicators/memory.d.ts.map +1 -0
- package/dist/indicators/memory.js +68 -0
- package/dist/indicators/prisma.d.ts +38 -0
- package/dist/indicators/prisma.d.ts.map +1 -0
- package/dist/indicators/prisma.js +79 -0
- package/dist/indicators/redis.d.ts +36 -0
- package/dist/indicators/redis.d.ts.map +1 -0
- package/dist/indicators/redis.js +64 -0
- package/dist/indicators/utils.d.ts +48 -0
- package/dist/indicators/utils.d.ts.map +1 -0
- package/dist/indicators/utils.js +82 -0
- package/dist/module.d.ts +20 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +138 -0
- package/dist/redis.d.ts +2 -0
- package/dist/redis.d.ts.map +1 -0
- package/dist/redis.js +1 -0
- package/dist/tokens.d.ts +9 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +9 -0
- package/dist/types.d.ts +52 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { statfs } from 'node:fs/promises';
|
|
2
|
+
import { createDownResult, createUpResult, resolveIndicatorKey, throwHealthCheckError } from './utils.js';
|
|
3
|
+
|
|
4
|
+
/** Options for checking free disk bytes and free-ratio thresholds. */
|
|
5
|
+
|
|
6
|
+
const DEFAULT_DISK_FREE_RATIO_THRESHOLD = 0.1;
|
|
7
|
+
function toNumber(value) {
|
|
8
|
+
return typeof value === 'bigint' ? Number(value) : value;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create a disk-space health indicator.
|
|
13
|
+
*
|
|
14
|
+
* @param options Optional filesystem path and free-space thresholds.
|
|
15
|
+
* @returns A health indicator backed by `statfs()`.
|
|
16
|
+
*/
|
|
17
|
+
export function createDiskHealthIndicator(options = {}) {
|
|
18
|
+
return new DiskHealthIndicator(options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a provider that registers a `DiskHealthIndicator` instance.
|
|
23
|
+
*
|
|
24
|
+
* @param options Optional filesystem path and free-space thresholds.
|
|
25
|
+
* @returns A value provider that exposes `DiskHealthIndicator` from the DI container.
|
|
26
|
+
*/
|
|
27
|
+
export function createDiskHealthIndicatorProvider(options = {}) {
|
|
28
|
+
return {
|
|
29
|
+
provide: DiskHealthIndicator,
|
|
30
|
+
useValue: new DiskHealthIndicator(options)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Health indicator that inspects free space for one filesystem path. */
|
|
35
|
+
export class DiskHealthIndicator {
|
|
36
|
+
key;
|
|
37
|
+
constructor(options = {}) {
|
|
38
|
+
this.options = options;
|
|
39
|
+
this.key = options.key;
|
|
40
|
+
}
|
|
41
|
+
async check(key) {
|
|
42
|
+
const indicatorKey = resolveIndicatorKey('disk', this.options.key ?? key);
|
|
43
|
+
const path = this.options.path ?? '.';
|
|
44
|
+
const minFreeRatio = this.options.minFreeRatio ?? DEFAULT_DISK_FREE_RATIO_THRESHOLD;
|
|
45
|
+
try {
|
|
46
|
+
const stats = await statfs(path);
|
|
47
|
+
const blockSize = toNumber(stats.bsize);
|
|
48
|
+
const blocks = toNumber(stats.blocks);
|
|
49
|
+
const availableBlocks = toNumber(stats.bavail);
|
|
50
|
+
const freeBytes = availableBlocks * blockSize;
|
|
51
|
+
const totalBytes = blocks * blockSize;
|
|
52
|
+
const freeRatio = totalBytes > 0 ? freeBytes / totalBytes : 1;
|
|
53
|
+
const details = {
|
|
54
|
+
freeBytes,
|
|
55
|
+
freeRatio,
|
|
56
|
+
path,
|
|
57
|
+
totalBytes
|
|
58
|
+
};
|
|
59
|
+
if (this.options.minFreeBytes !== undefined && freeBytes < this.options.minFreeBytes) {
|
|
60
|
+
throwHealthCheckError('Disk health check failed.', createDownResult(indicatorKey, 'Disk free bytes dropped below the configured threshold.', details));
|
|
61
|
+
}
|
|
62
|
+
if (freeRatio < minFreeRatio) {
|
|
63
|
+
throwHealthCheckError('Disk health check failed.', createDownResult(indicatorKey, 'Disk free ratio dropped below the configured threshold.', details));
|
|
64
|
+
}
|
|
65
|
+
return createUpResult(indicatorKey, details);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error instanceof Error && error.name === 'HealthCheckError') {
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
throwHealthCheckError('Disk health check failed.', createDownResult(indicatorKey, error instanceof Error ? error.message : 'Disk health check failed.'));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Provider } from '@fluojs/di';
|
|
2
|
+
import type { HealthIndicator, HealthIndicatorResult } from '../types.js';
|
|
3
|
+
interface DrizzleExecuteLike {
|
|
4
|
+
execute?: (query: unknown) => Promise<unknown>;
|
|
5
|
+
}
|
|
6
|
+
/** Options for probing Drizzle-backed database connectivity. */
|
|
7
|
+
export interface DrizzleHealthIndicatorOptions {
|
|
8
|
+
database?: DrizzleExecuteLike;
|
|
9
|
+
key?: string;
|
|
10
|
+
ping?: () => Promise<unknown> | unknown;
|
|
11
|
+
query?: unknown;
|
|
12
|
+
timeoutMs?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a Drizzle health indicator.
|
|
16
|
+
*
|
|
17
|
+
* @param options Optional database handle, ping callback, timeout, query, and key override.
|
|
18
|
+
* @returns A health indicator that executes a lightweight Drizzle query.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createDrizzleHealthIndicator(options?: DrizzleHealthIndicatorOptions): HealthIndicator;
|
|
21
|
+
/**
|
|
22
|
+
* Create a provider that resolves a Drizzle database handle from DI and wraps it as an indicator.
|
|
23
|
+
*
|
|
24
|
+
* @param options Optional timeout, query override, key override, or custom ping callback.
|
|
25
|
+
* @returns A factory provider that exposes `DrizzleHealthIndicator` from the DI container.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createDrizzleHealthIndicatorProvider(options?: Omit<DrizzleHealthIndicatorOptions, 'database'>): Provider;
|
|
28
|
+
/** Health indicator that probes Drizzle connectivity with an execute-capable handle. */
|
|
29
|
+
export declare class DrizzleHealthIndicator implements HealthIndicator {
|
|
30
|
+
private readonly options;
|
|
31
|
+
readonly key: string | undefined;
|
|
32
|
+
constructor(options?: DrizzleHealthIndicatorOptions);
|
|
33
|
+
check(key: string): Promise<HealthIndicatorResult>;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=drizzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../src/indicators/drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAI1E,UAAU,kBAAkB;IAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAChD;AAED,gEAAgE;AAChE,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAsBD;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,GAAE,6BAAkC,GAAG,eAAe,CAEzG;AAED;;;;;GAKG;AACH,wBAAgB,oCAAoC,CAAC,OAAO,GAAE,IAAI,CAAC,6BAA6B,EAAE,UAAU,CAAM,GAAG,QAAQ,CAM5H;AAED,wFAAwF;AACxF,qBAAa,sBAAuB,YAAW,eAAe;IAGhD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEJ,OAAO,GAAE,6BAAkC;IAIlE,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAczD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createDownResult, createUpResult, resolveIndicatorKey, throwHealthCheckError, withIndicatorTimeout } from './utils.js';
|
|
2
|
+
const DRIZZLE_DATABASE = Symbol.for('fluo.drizzle.database');
|
|
3
|
+
|
|
4
|
+
/** Options for probing Drizzle-backed database connectivity. */
|
|
5
|
+
|
|
6
|
+
const DEFAULT_DRIZZLE_TIMEOUT_MS = 2_000;
|
|
7
|
+
const DEFAULT_DRIZZLE_QUERY = 'select 1';
|
|
8
|
+
async function runDrizzlePing(options) {
|
|
9
|
+
if (options.ping) {
|
|
10
|
+
await options.ping();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const database = options.database;
|
|
14
|
+
if (!database || typeof database.execute !== 'function') {
|
|
15
|
+
throw new Error('Drizzle indicator requires an execute-capable database handle or a ping callback.');
|
|
16
|
+
}
|
|
17
|
+
await database.execute(options.query ?? DEFAULT_DRIZZLE_QUERY);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create a Drizzle health indicator.
|
|
22
|
+
*
|
|
23
|
+
* @param options Optional database handle, ping callback, timeout, query, and key override.
|
|
24
|
+
* @returns A health indicator that executes a lightweight Drizzle query.
|
|
25
|
+
*/
|
|
26
|
+
export function createDrizzleHealthIndicator(options = {}) {
|
|
27
|
+
return new DrizzleHealthIndicator(options);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a provider that resolves a Drizzle database handle from DI and wraps it as an indicator.
|
|
32
|
+
*
|
|
33
|
+
* @param options Optional timeout, query override, key override, or custom ping callback.
|
|
34
|
+
* @returns A factory provider that exposes `DrizzleHealthIndicator` from the DI container.
|
|
35
|
+
*/
|
|
36
|
+
export function createDrizzleHealthIndicatorProvider(options = {}) {
|
|
37
|
+
return {
|
|
38
|
+
inject: [DRIZZLE_DATABASE],
|
|
39
|
+
provide: DrizzleHealthIndicator,
|
|
40
|
+
useFactory: database => new DrizzleHealthIndicator({
|
|
41
|
+
...options,
|
|
42
|
+
database: database
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Health indicator that probes Drizzle connectivity with an execute-capable handle. */
|
|
48
|
+
export class DrizzleHealthIndicator {
|
|
49
|
+
key;
|
|
50
|
+
constructor(options = {}) {
|
|
51
|
+
this.options = options;
|
|
52
|
+
this.key = options.key;
|
|
53
|
+
}
|
|
54
|
+
async check(key) {
|
|
55
|
+
const indicatorKey = resolveIndicatorKey('drizzle', this.options.key ?? key);
|
|
56
|
+
const timeoutMs = this.options.timeoutMs ?? DEFAULT_DRIZZLE_TIMEOUT_MS;
|
|
57
|
+
try {
|
|
58
|
+
await withIndicatorTimeout(runDrizzlePing(this.options), timeoutMs, indicatorKey);
|
|
59
|
+
return createUpResult(indicatorKey);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
throwHealthCheckError('Drizzle health check failed.', createDownResult(indicatorKey, error instanceof Error ? error.message : 'Drizzle health check failed.'));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Provider } from '@fluojs/di';
|
|
2
|
+
import type { HealthIndicator, HealthIndicatorResult } from '../types.js';
|
|
3
|
+
/** Options for probing one upstream HTTP dependency. */
|
|
4
|
+
export interface HttpHealthIndicatorOptions {
|
|
5
|
+
expectedStatus?: number | readonly number[] | ((status: number) => boolean);
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
key?: string;
|
|
8
|
+
method?: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
url: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create an HTTP-backed health indicator.
|
|
14
|
+
*
|
|
15
|
+
* @param options HTTP probe settings such as URL, method, headers, and accepted status codes.
|
|
16
|
+
* @returns A health indicator that fetches the configured endpoint on each check.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createHttpHealthIndicator(options: HttpHealthIndicatorOptions): HealthIndicator;
|
|
19
|
+
/**
|
|
20
|
+
* Create a provider that registers an `HttpHealthIndicator` instance.
|
|
21
|
+
*
|
|
22
|
+
* @param options HTTP probe settings such as URL, method, headers, and accepted status codes.
|
|
23
|
+
* @returns A value provider that exposes `HttpHealthIndicator` from the DI container.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createHttpHealthIndicatorProvider(options: HttpHealthIndicatorOptions): Provider;
|
|
26
|
+
/** Health indicator that probes an upstream HTTP endpoint with `fetch()`. */
|
|
27
|
+
export declare class HttpHealthIndicator implements HealthIndicator {
|
|
28
|
+
private readonly options;
|
|
29
|
+
readonly key: string | undefined;
|
|
30
|
+
constructor(options: HttpHealthIndicatorOptions);
|
|
31
|
+
check(key: string): Promise<HealthIndicatorResult>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/indicators/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAE1E,wDAAwD;AACxD,MAAM,WAAW,0BAA0B;IACzC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;AAoBD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,0BAA0B,GAAG,eAAe,CAE9F;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,0BAA0B,GAAG,QAAQ,CAK/F;AAED,6EAA6E;AAC7E,qBAAa,mBAAoB,YAAW,eAAe;IAG7C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEJ,OAAO,EAAE,0BAA0B;IAI1D,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CA6CzD"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createDownResult, createUpResult, resolveIndicatorKey, throwHealthCheckError } from './utils.js';
|
|
2
|
+
import { HealthCheckError } from '../errors.js';
|
|
3
|
+
|
|
4
|
+
/** Options for probing one upstream HTTP dependency. */
|
|
5
|
+
|
|
6
|
+
const DEFAULT_HTTP_TIMEOUT_MS = 2_000;
|
|
7
|
+
function isExpectedStatus(status, expected) {
|
|
8
|
+
if (typeof expected === 'function') {
|
|
9
|
+
return expected(status);
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(expected)) {
|
|
12
|
+
return expected.includes(status);
|
|
13
|
+
}
|
|
14
|
+
if (typeof expected === 'number') {
|
|
15
|
+
return status === expected;
|
|
16
|
+
}
|
|
17
|
+
return status >= 200 && status < 300;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create an HTTP-backed health indicator.
|
|
22
|
+
*
|
|
23
|
+
* @param options HTTP probe settings such as URL, method, headers, and accepted status codes.
|
|
24
|
+
* @returns A health indicator that fetches the configured endpoint on each check.
|
|
25
|
+
*/
|
|
26
|
+
export function createHttpHealthIndicator(options) {
|
|
27
|
+
return new HttpHealthIndicator(options);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a provider that registers an `HttpHealthIndicator` instance.
|
|
32
|
+
*
|
|
33
|
+
* @param options HTTP probe settings such as URL, method, headers, and accepted status codes.
|
|
34
|
+
* @returns A value provider that exposes `HttpHealthIndicator` from the DI container.
|
|
35
|
+
*/
|
|
36
|
+
export function createHttpHealthIndicatorProvider(options) {
|
|
37
|
+
return {
|
|
38
|
+
provide: HttpHealthIndicator,
|
|
39
|
+
useValue: new HttpHealthIndicator(options)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Health indicator that probes an upstream HTTP endpoint with `fetch()`. */
|
|
44
|
+
export class HttpHealthIndicator {
|
|
45
|
+
key;
|
|
46
|
+
constructor(options) {
|
|
47
|
+
this.options = options;
|
|
48
|
+
this.key = options.key;
|
|
49
|
+
}
|
|
50
|
+
async check(key) {
|
|
51
|
+
const indicatorKey = resolveIndicatorKey('http', this.options.key ?? key);
|
|
52
|
+
const timeoutMs = this.options.timeoutMs ?? DEFAULT_HTTP_TIMEOUT_MS;
|
|
53
|
+
const method = this.options.method ?? 'GET';
|
|
54
|
+
const abortController = new AbortController();
|
|
55
|
+
const startedAt = Date.now();
|
|
56
|
+
const timeout = setTimeout(() => {
|
|
57
|
+
abortController.abort(new Error(`HTTP health check timed out after ${String(timeoutMs)}ms.`));
|
|
58
|
+
}, timeoutMs);
|
|
59
|
+
try {
|
|
60
|
+
const response = await fetch(this.options.url, {
|
|
61
|
+
headers: this.options.headers,
|
|
62
|
+
method,
|
|
63
|
+
signal: abortController.signal
|
|
64
|
+
});
|
|
65
|
+
const responseTimeMs = Date.now() - startedAt;
|
|
66
|
+
if (!isExpectedStatus(response.status, this.options.expectedStatus)) {
|
|
67
|
+
throwHealthCheckError('HTTP health check failed.', createDownResult(indicatorKey, `Unexpected status code ${String(response.status)} from ${this.options.url}.`, {
|
|
68
|
+
responseTimeMs,
|
|
69
|
+
statusCode: response.status,
|
|
70
|
+
url: this.options.url
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
return createUpResult(indicatorKey, {
|
|
74
|
+
responseTimeMs,
|
|
75
|
+
statusCode: response.status,
|
|
76
|
+
url: this.options.url
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error instanceof HealthCheckError) {
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
throwHealthCheckError('HTTP health check failed.', createDownResult(indicatorKey, error instanceof Error ? error.message : `HTTP health check failed for ${this.options.url}.`));
|
|
83
|
+
} finally {
|
|
84
|
+
clearTimeout(timeout);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/indicators/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Provider } from '@fluojs/di';
|
|
2
|
+
import type { HealthIndicator, HealthIndicatorResult } from '../types.js';
|
|
3
|
+
/** Options for checking process heap and RSS thresholds. */
|
|
4
|
+
export interface MemoryHealthIndicatorOptions {
|
|
5
|
+
heapUsedThresholdBytes?: number;
|
|
6
|
+
heapUsedThresholdRatio?: number;
|
|
7
|
+
key?: string;
|
|
8
|
+
rssThresholdBytes?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create a process-memory health indicator.
|
|
12
|
+
*
|
|
13
|
+
* @param options Optional heap and RSS thresholds plus an indicator key override.
|
|
14
|
+
* @returns A health indicator backed by `process.memoryUsage()`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createMemoryHealthIndicator(options?: MemoryHealthIndicatorOptions): HealthIndicator;
|
|
17
|
+
/**
|
|
18
|
+
* Create a provider that registers a `MemoryHealthIndicator` instance.
|
|
19
|
+
*
|
|
20
|
+
* @param options Optional heap and RSS thresholds plus an indicator key override.
|
|
21
|
+
* @returns A value provider that exposes `MemoryHealthIndicator` from the DI container.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createMemoryHealthIndicatorProvider(options?: MemoryHealthIndicatorOptions): Provider;
|
|
24
|
+
/** Health indicator that checks local process heap and RSS usage. */
|
|
25
|
+
export declare class MemoryHealthIndicator implements HealthIndicator {
|
|
26
|
+
private readonly options;
|
|
27
|
+
readonly key: string | undefined;
|
|
28
|
+
constructor(options?: MemoryHealthIndicatorOptions);
|
|
29
|
+
check(key: string): Promise<HealthIndicatorResult>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/indicators/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAE1E,4DAA4D;AAC5D,MAAM,WAAW,4BAA4B;IAC3C,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAYD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,GAAE,4BAAiC,GAAG,eAAe,CAEvG;AAED;;;;;GAKG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,GAAE,4BAAiC,GAAG,QAAQ,CAKxG;AAED,qEAAqE;AACrE,qBAAa,qBAAsB,YAAW,eAAe;IAG/C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEJ,OAAO,GAAE,4BAAiC;IAIjE,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAiCzD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createDownResult, createUpResult, resolveIndicatorKey, throwHealthCheckError } from './utils.js';
|
|
2
|
+
|
|
3
|
+
/** Options for checking process heap and RSS thresholds. */
|
|
4
|
+
|
|
5
|
+
const DEFAULT_HEAP_RATIO_THRESHOLD = 0.95;
|
|
6
|
+
function exceedsRatioThreshold(used, total, threshold) {
|
|
7
|
+
if (total <= 0) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return used / total >= threshold;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create a process-memory health indicator.
|
|
15
|
+
*
|
|
16
|
+
* @param options Optional heap and RSS thresholds plus an indicator key override.
|
|
17
|
+
* @returns A health indicator backed by `process.memoryUsage()`.
|
|
18
|
+
*/
|
|
19
|
+
export function createMemoryHealthIndicator(options = {}) {
|
|
20
|
+
return new MemoryHealthIndicator(options);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Create a provider that registers a `MemoryHealthIndicator` instance.
|
|
25
|
+
*
|
|
26
|
+
* @param options Optional heap and RSS thresholds plus an indicator key override.
|
|
27
|
+
* @returns A value provider that exposes `MemoryHealthIndicator` from the DI container.
|
|
28
|
+
*/
|
|
29
|
+
export function createMemoryHealthIndicatorProvider(options = {}) {
|
|
30
|
+
return {
|
|
31
|
+
provide: MemoryHealthIndicator,
|
|
32
|
+
useValue: new MemoryHealthIndicator(options)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Health indicator that checks local process heap and RSS usage. */
|
|
37
|
+
export class MemoryHealthIndicator {
|
|
38
|
+
key;
|
|
39
|
+
constructor(options = {}) {
|
|
40
|
+
this.options = options;
|
|
41
|
+
this.key = options.key;
|
|
42
|
+
}
|
|
43
|
+
async check(key) {
|
|
44
|
+
const indicatorKey = resolveIndicatorKey('memory', this.options.key ?? key);
|
|
45
|
+
const heapRatioThreshold = this.options.heapUsedThresholdRatio ?? DEFAULT_HEAP_RATIO_THRESHOLD;
|
|
46
|
+
const usage = process.memoryUsage();
|
|
47
|
+
const usageDetails = {
|
|
48
|
+
arrayBuffers: usage.arrayBuffers,
|
|
49
|
+
external: usage.external,
|
|
50
|
+
heapTotal: usage.heapTotal,
|
|
51
|
+
heapUsed: usage.heapUsed,
|
|
52
|
+
rss: usage.rss
|
|
53
|
+
};
|
|
54
|
+
if (this.options.heapUsedThresholdBytes !== undefined && usage.heapUsed >= this.options.heapUsedThresholdBytes) {
|
|
55
|
+
throwHealthCheckError('Memory health check failed.', createDownResult(indicatorKey, 'Heap usage exceeded the configured byte threshold.', usageDetails));
|
|
56
|
+
}
|
|
57
|
+
if (this.options.rssThresholdBytes !== undefined && usage.rss >= this.options.rssThresholdBytes) {
|
|
58
|
+
throwHealthCheckError('Memory health check failed.', createDownResult(indicatorKey, 'RSS usage exceeded the configured byte threshold.', usageDetails));
|
|
59
|
+
}
|
|
60
|
+
if (exceedsRatioThreshold(usage.heapUsed, usage.heapTotal, heapRatioThreshold)) {
|
|
61
|
+
throwHealthCheckError('Memory health check failed.', createDownResult(indicatorKey, 'Heap usage exceeded the configured ratio threshold.', {
|
|
62
|
+
...usageDetails,
|
|
63
|
+
heapUsedRatio: usage.heapTotal > 0 ? usage.heapUsed / usage.heapTotal : 0
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
return createUpResult(indicatorKey, usageDetails);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Provider } from '@fluojs/di';
|
|
2
|
+
import type { HealthIndicator, HealthIndicatorResult } from '../types.js';
|
|
3
|
+
interface PrismaClientLike {
|
|
4
|
+
$executeRaw?: (...args: unknown[]) => Promise<unknown>;
|
|
5
|
+
$executeRawUnsafe?: (query: string) => Promise<unknown>;
|
|
6
|
+
$queryRaw?: (...args: unknown[]) => Promise<unknown>;
|
|
7
|
+
$queryRawUnsafe?: (query: string) => Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
/** Options for probing Prisma-backed database connectivity. */
|
|
10
|
+
export interface PrismaHealthIndicatorOptions {
|
|
11
|
+
client?: PrismaClientLike;
|
|
12
|
+
key?: string;
|
|
13
|
+
ping?: () => Promise<unknown> | unknown;
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a Prisma health indicator.
|
|
18
|
+
*
|
|
19
|
+
* @param options Optional Prisma client, ping callback, timeout, and key override.
|
|
20
|
+
* @returns A health indicator that executes a lightweight Prisma round trip.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createPrismaHealthIndicator(options?: PrismaHealthIndicatorOptions): HealthIndicator;
|
|
23
|
+
/**
|
|
24
|
+
* Create a provider that resolves a Prisma client from DI and wraps it as an indicator.
|
|
25
|
+
*
|
|
26
|
+
* @param options Optional timeout, key override, or custom ping callback.
|
|
27
|
+
* @returns A factory provider that exposes `PrismaHealthIndicator` from the DI container.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createPrismaHealthIndicatorProvider(options?: Omit<PrismaHealthIndicatorOptions, 'client'>): Provider;
|
|
30
|
+
/** Health indicator that probes Prisma connectivity with a trivial query. */
|
|
31
|
+
export declare class PrismaHealthIndicator implements HealthIndicator {
|
|
32
|
+
private readonly options;
|
|
33
|
+
readonly key: string | undefined;
|
|
34
|
+
constructor(options?: PrismaHealthIndicatorOptions);
|
|
35
|
+
check(key: string): Promise<HealthIndicatorResult>;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=prisma.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/indicators/prisma.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAI1E,UAAU,gBAAgB;IACxB,WAAW,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACvD,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACxD,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACvD;AAED,+DAA+D;AAC/D,MAAM,WAAW,4BAA4B;IAC3C,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAuCD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,GAAE,4BAAiC,GAAG,eAAe,CAEvG;AAED;;;;;GAKG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,GAAE,IAAI,CAAC,4BAA4B,EAAE,QAAQ,CAAM,GAAG,QAAQ,CAMxH;AAED,6EAA6E;AAC7E,qBAAa,qBAAsB,YAAW,eAAe;IAG/C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEJ,OAAO,GAAE,4BAAiC;IAIjE,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAczD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createDownResult, createUpResult, resolveIndicatorKey, throwHealthCheckError, withIndicatorTimeout } from './utils.js';
|
|
2
|
+
const PRISMA_CLIENT = Symbol.for('fluo.prisma.client');
|
|
3
|
+
|
|
4
|
+
/** Options for probing Prisma-backed database connectivity. */
|
|
5
|
+
|
|
6
|
+
const DEFAULT_PRISMA_TIMEOUT_MS = 2_000;
|
|
7
|
+
async function runPrismaPing(options) {
|
|
8
|
+
if (options.ping) {
|
|
9
|
+
await options.ping();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const client = options.client;
|
|
13
|
+
if (!client) {
|
|
14
|
+
throw new Error('Prisma indicator requires either a client or ping callback.');
|
|
15
|
+
}
|
|
16
|
+
if (typeof client.$queryRawUnsafe === 'function') {
|
|
17
|
+
await client.$queryRawUnsafe('SELECT 1');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (typeof client.$executeRawUnsafe === 'function') {
|
|
21
|
+
await client.$executeRawUnsafe('SELECT 1');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (typeof client.$queryRaw === 'function') {
|
|
25
|
+
await client.$queryRaw('SELECT 1');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (typeof client.$executeRaw === 'function') {
|
|
29
|
+
await client.$executeRaw('SELECT 1');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
throw new Error('Prisma indicator requires a client with query/execute capabilities or a ping callback.');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a Prisma health indicator.
|
|
37
|
+
*
|
|
38
|
+
* @param options Optional Prisma client, ping callback, timeout, and key override.
|
|
39
|
+
* @returns A health indicator that executes a lightweight Prisma round trip.
|
|
40
|
+
*/
|
|
41
|
+
export function createPrismaHealthIndicator(options = {}) {
|
|
42
|
+
return new PrismaHealthIndicator(options);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Create a provider that resolves a Prisma client from DI and wraps it as an indicator.
|
|
47
|
+
*
|
|
48
|
+
* @param options Optional timeout, key override, or custom ping callback.
|
|
49
|
+
* @returns A factory provider that exposes `PrismaHealthIndicator` from the DI container.
|
|
50
|
+
*/
|
|
51
|
+
export function createPrismaHealthIndicatorProvider(options = {}) {
|
|
52
|
+
return {
|
|
53
|
+
inject: [PRISMA_CLIENT],
|
|
54
|
+
provide: PrismaHealthIndicator,
|
|
55
|
+
useFactory: client => new PrismaHealthIndicator({
|
|
56
|
+
...options,
|
|
57
|
+
client: client
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Health indicator that probes Prisma connectivity with a trivial query. */
|
|
63
|
+
export class PrismaHealthIndicator {
|
|
64
|
+
key;
|
|
65
|
+
constructor(options = {}) {
|
|
66
|
+
this.options = options;
|
|
67
|
+
this.key = options.key;
|
|
68
|
+
}
|
|
69
|
+
async check(key) {
|
|
70
|
+
const indicatorKey = resolveIndicatorKey('prisma', this.options.key ?? key);
|
|
71
|
+
const timeoutMs = this.options.timeoutMs ?? DEFAULT_PRISMA_TIMEOUT_MS;
|
|
72
|
+
try {
|
|
73
|
+
await withIndicatorTimeout(runPrismaPing(this.options), timeoutMs, indicatorKey);
|
|
74
|
+
return createUpResult(indicatorKey);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
throwHealthCheckError('Prisma health check failed.', createDownResult(indicatorKey, error instanceof Error ? error.message : 'Prisma health check failed.'));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Provider } from '@fluojs/di';
|
|
2
|
+
import type { HealthIndicator, HealthIndicatorResult } from '../types.js';
|
|
3
|
+
interface RedisClientLike {
|
|
4
|
+
ping?: () => Promise<unknown>;
|
|
5
|
+
}
|
|
6
|
+
/** Options for probing Redis connectivity. */
|
|
7
|
+
export interface RedisHealthIndicatorOptions {
|
|
8
|
+
client?: RedisClientLike;
|
|
9
|
+
clientName?: string;
|
|
10
|
+
key?: string;
|
|
11
|
+
ping?: () => Promise<unknown> | unknown;
|
|
12
|
+
timeoutMs?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a Redis health indicator.
|
|
16
|
+
*
|
|
17
|
+
* @param options Optional Redis client, ping callback, timeout, and key override.
|
|
18
|
+
* @returns A health indicator that checks Redis with `PING` semantics.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createRedisHealthIndicator(options?: RedisHealthIndicatorOptions): HealthIndicator;
|
|
21
|
+
/**
|
|
22
|
+
* Create a provider that resolves a Redis client from DI and wraps it as an indicator.
|
|
23
|
+
*
|
|
24
|
+
* @param options Optional timeout, key override, or custom ping callback.
|
|
25
|
+
* @returns A factory provider that exposes `RedisHealthIndicator` from the DI container.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createRedisHealthIndicatorProvider(options?: Omit<RedisHealthIndicatorOptions, 'client'>): Provider;
|
|
28
|
+
/** Health indicator that checks Redis reachability with a ping-like operation. */
|
|
29
|
+
export declare class RedisHealthIndicator implements HealthIndicator {
|
|
30
|
+
private readonly options;
|
|
31
|
+
readonly key: string | undefined;
|
|
32
|
+
constructor(options?: RedisHealthIndicatorOptions);
|
|
33
|
+
check(key: string): Promise<HealthIndicatorResult>;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=redis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../src/indicators/redis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAE1E,UAAU,eAAe;IACvB,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/B;AAED,8CAA8C;AAC9C,MAAM,WAAW,2BAA2B;IAC1C,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAmBD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,2BAAgC,GAAG,eAAe,CAErG;AAED;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAAC,OAAO,GAAE,IAAI,CAAC,2BAA2B,EAAE,QAAQ,CAAM,GAAG,QAAQ,CAQtH;AAED,kFAAkF;AAClF,qBAAa,oBAAqB,YAAW,eAAe;IAG9C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEJ,OAAO,GAAE,2BAAgC;IAIhE,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAczD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getRedisClientToken } from '@fluojs/redis';
|
|
2
|
+
import { createDownResult, createUpResult, resolveIndicatorKey, throwHealthCheckError, withIndicatorTimeout } from './utils.js';
|
|
3
|
+
|
|
4
|
+
/** Options for probing Redis connectivity. */
|
|
5
|
+
|
|
6
|
+
const DEFAULT_REDIS_TIMEOUT_MS = 2_000;
|
|
7
|
+
async function runRedisPing(options) {
|
|
8
|
+
if (options.ping) {
|
|
9
|
+
await options.ping();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const client = options.client;
|
|
13
|
+
if (!client || typeof client.ping !== 'function') {
|
|
14
|
+
throw new Error('Redis indicator requires a client with ping() or a ping callback.');
|
|
15
|
+
}
|
|
16
|
+
await client.ping();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a Redis health indicator.
|
|
21
|
+
*
|
|
22
|
+
* @param options Optional Redis client, ping callback, timeout, and key override.
|
|
23
|
+
* @returns A health indicator that checks Redis with `PING` semantics.
|
|
24
|
+
*/
|
|
25
|
+
export function createRedisHealthIndicator(options = {}) {
|
|
26
|
+
return new RedisHealthIndicator(options);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a provider that resolves a Redis client from DI and wraps it as an indicator.
|
|
31
|
+
*
|
|
32
|
+
* @param options Optional timeout, key override, or custom ping callback.
|
|
33
|
+
* @returns A factory provider that exposes `RedisHealthIndicator` from the DI container.
|
|
34
|
+
*/
|
|
35
|
+
export function createRedisHealthIndicatorProvider(options = {}) {
|
|
36
|
+
const indicatorProviderToken = Symbol('fluo.terminus.redis-health-indicator');
|
|
37
|
+
return {
|
|
38
|
+
inject: [getRedisClientToken(options.clientName)],
|
|
39
|
+
provide: indicatorProviderToken,
|
|
40
|
+
useFactory: client => new RedisHealthIndicator({
|
|
41
|
+
...options,
|
|
42
|
+
client: client
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Health indicator that checks Redis reachability with a ping-like operation. */
|
|
48
|
+
export class RedisHealthIndicator {
|
|
49
|
+
key;
|
|
50
|
+
constructor(options = {}) {
|
|
51
|
+
this.options = options;
|
|
52
|
+
this.key = options.key;
|
|
53
|
+
}
|
|
54
|
+
async check(key) {
|
|
55
|
+
const indicatorKey = resolveIndicatorKey('redis', this.options.key ?? key);
|
|
56
|
+
const timeoutMs = this.options.timeoutMs ?? DEFAULT_REDIS_TIMEOUT_MS;
|
|
57
|
+
try {
|
|
58
|
+
await withIndicatorTimeout(runRedisPing(this.options), timeoutMs, indicatorKey);
|
|
59
|
+
return createUpResult(indicatorKey);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
throwHealthCheckError('Redis health check failed.', createDownResult(indicatorKey, error instanceof Error ? error.message : 'Redis health check failed.'));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|