@seta-labs/nestjs-health 0.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 +90 -0
- package/dist/check.util.d.ts +6 -0
- package/dist/check.util.js +36 -0
- package/dist/check.util.js.map +1 -0
- package/dist/dto/event-loop-delay.dto.d.ts +6 -0
- package/dist/dto/event-loop-delay.dto.js +41 -0
- package/dist/dto/event-loop-delay.dto.js.map +1 -0
- package/dist/dto/health-check-response.dto.d.ts +8 -0
- package/dist/dto/health-check-response.dto.js +43 -0
- package/dist/dto/health-check-response.dto.js.map +1 -0
- package/dist/dto/health-check-result.dto.d.ts +8 -0
- package/dist/dto/health-check-result.dto.js +52 -0
- package/dist/dto/health-check-result.dto.js.map +1 -0
- package/dist/dto/health-report-response.dto.d.ts +15 -0
- package/dist/dto/health-report-response.dto.js +66 -0
- package/dist/dto/health-report-response.dto.js.map +1 -0
- package/dist/dto/memory-usage.dto.d.ts +11 -0
- package/dist/dto/memory-usage.dto.js +72 -0
- package/dist/dto/memory-usage.dto.js.map +1 -0
- package/dist/enums/health-status.enum.d.ts +10 -0
- package/dist/enums/health-status.enum.js +15 -0
- package/dist/enums/health-status.enum.js.map +1 -0
- package/dist/health.constants.d.ts +4 -0
- package/dist/health.constants.js +8 -0
- package/dist/health.constants.js.map +1 -0
- package/dist/health.controller.d.ts +6 -0
- package/dist/health.controller.js +87 -0
- package/dist/health.controller.js.map +1 -0
- package/dist/health.mapper.d.ts +7 -0
- package/dist/health.mapper.js +58 -0
- package/dist/health.mapper.js.map +1 -0
- package/dist/health.module.d.ts +10 -0
- package/dist/health.module.js +44 -0
- package/dist/health.module.js.map +1 -0
- package/dist/health.service.d.ts +33 -0
- package/dist/health.service.js +133 -0
- package/dist/health.service.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.util.d.ts +11 -0
- package/dist/memory.util.js +51 -0
- package/dist/memory.util.js.map +1 -0
- package/dist/types/health-indicator.type.d.ts +21 -0
- package/dist/types/health-indicator.type.js +3 -0
- package/dist/types/health-indicator.type.js.map +1 -0
- package/dist/types/health-options.type.d.ts +29 -0
- package/dist/types/health-options.type.js +3 -0
- package/dist/types/health-options.type.js.map +1 -0
- package/dist/types/health-report-input.type.d.ts +14 -0
- package/dist/types/health-report-input.type.js +3 -0
- package/dist/types/health-report-input.type.js.map +1 -0
- package/dist/types/memory-snapshot.type.d.ts +14 -0
- package/dist/types/memory-snapshot.type.js +3 -0
- package/dist/types/memory-snapshot.type.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @seta-labs/nestjs-health
|
|
2
|
+
|
|
3
|
+
Health endpoints for NestJS APIs, as `BLUEPRINT.md` → Health requires: a liveness probe that checks nothing, a readiness probe on memory pressure and the app's critical dependencies, a diagnostic status report, and readiness failing as soon as shutdown starts.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @seta-labs/nestjs-health
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies: `@nestjs/common`, `@nestjs/core`, `@nestjs/swagger` (the DTOs are part of the app's OpenAPI contract).
|
|
12
|
+
|
|
13
|
+
## Wire it
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// src/prisma/database.indicator.ts: the probe lives with the dependency
|
|
17
|
+
import { Injectable } from '@nestjs/common';
|
|
18
|
+
import type { HealthIndicator } from '@seta-labs/nestjs-health';
|
|
19
|
+
|
|
20
|
+
import { PrismaService } from './prisma.service';
|
|
21
|
+
|
|
22
|
+
@Injectable()
|
|
23
|
+
export class DatabaseHealthIndicator implements HealthIndicator {
|
|
24
|
+
readonly name = 'database';
|
|
25
|
+
|
|
26
|
+
constructor(private readonly prisma: PrismaService) {}
|
|
27
|
+
|
|
28
|
+
async check(): Promise<void> {
|
|
29
|
+
await this.prisma.$queryRaw`SELECT 1`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
// app.module.ts
|
|
36
|
+
import { HealthModule } from '@seta-labs/nestjs-health';
|
|
37
|
+
|
|
38
|
+
@Module({
|
|
39
|
+
imports: [
|
|
40
|
+
HealthModule.forRoot({
|
|
41
|
+
service: 'my-api',
|
|
42
|
+
version: process.env.APP_VERSION,
|
|
43
|
+
imports: [PrismaModule], // exports DatabaseHealthIndicator
|
|
44
|
+
indicators: [DatabaseHealthIndicator],
|
|
45
|
+
probeDecorators: [Public()], // only with a global guard
|
|
46
|
+
}),
|
|
47
|
+
],
|
|
48
|
+
})
|
|
49
|
+
export class AppModule {}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// main.ts
|
|
54
|
+
app.enableShutdownHooks();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```yaml
|
|
58
|
+
# k8s: probes
|
|
59
|
+
startupProbe:
|
|
60
|
+
httpGet: { path: /api/health/ready, port: http }
|
|
61
|
+
periodSeconds: 5
|
|
62
|
+
failureThreshold: 24
|
|
63
|
+
readinessProbe:
|
|
64
|
+
httpGet: { path: /api/health/ready, port: http }
|
|
65
|
+
periodSeconds: 5
|
|
66
|
+
timeoutSeconds: 2
|
|
67
|
+
livenessProbe:
|
|
68
|
+
httpGet: { path: /api/health, port: http }
|
|
69
|
+
periodSeconds: 10
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Endpoints
|
|
73
|
+
|
|
74
|
+
| Route | For | Behaviour |
|
|
75
|
+
| -------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
76
|
+
| `GET /health` | liveness | `{ status: 'ok', service, timestamp }`, no check: a failing dependency must not make the kubelet restart every pod. |
|
|
77
|
+
| `GET /health/ready` | readiness | Runs the memory check and every indicator in parallel. `down` (503) when a critical check fails or shutdown started; `degraded` (200) when only a non-critical one fails. No error messages: the probe is public. |
|
|
78
|
+
| `GET /health/status` | people | Always 200: status, version, Node version, uptime, memory in MiB with both limits and ratios, event loop delay p50/p99/max since the previous report, every check with its error. |
|
|
79
|
+
|
|
80
|
+
All three answer `Cache-Control: no-store`. `@seta-labs/nestjs-logging` keeps the two probes out of the request log; `/health/status` stays logged.
|
|
81
|
+
|
|
82
|
+
## Options
|
|
83
|
+
|
|
84
|
+
- `service` (required), `version`: echoed in the responses.
|
|
85
|
+
- `imports`, `indicators`: modules exporting the indicators, and the indicator classes. An indicator is `{ name, critical?, check(): Promise<void> }`; `critical` defaults to `true`.
|
|
86
|
+
- `memory`: `{ heapRatio, rssRatio }`, both `0.9` by default; `false` drops the check. The heap is measured against V8's `heap_size_limit`, which Node sizes from the container limit (about half of it on small pods); the RSS against the cgroup limit (`process.constrainedMemory()`), skipped when the process is not constrained. The two are distinct ways to die: "heap out of memory" versus OOMKill, the latter driven by buffers and native memory outside the heap.
|
|
87
|
+
- `checkTimeoutMs`: per check, `750` by default; keep the probe `timeoutSeconds` above it.
|
|
88
|
+
- `probeDecorators`: decorators applied to `/health` and `/health/ready` only, typically the app's `Public()`.
|
|
89
|
+
|
|
90
|
+
Readiness logs one line per change, not per probe: a `warn` for each failing check (with `err`) when it leaves `ok`, an `info` when it recovers. `HealthService` is exported for apps that need the report elsewhere.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HealthStatus } from './enums/health-status.enum';
|
|
2
|
+
import type { CheckResult, HealthIndicator } from './types/health-indicator.type';
|
|
3
|
+
/** Runs one indicator under a timeout; never throws. */
|
|
4
|
+
export declare function runCheck(indicator: HealthIndicator, timeoutMs: number): Promise<CheckResult>;
|
|
5
|
+
/** `down` when a critical check fails, `degraded` when only non-critical ones do. */
|
|
6
|
+
export declare function overallStatus(results: CheckResult[]): HealthStatus;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCheck = runCheck;
|
|
4
|
+
exports.overallStatus = overallStatus;
|
|
5
|
+
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
6
|
+
const health_status_enum_1 = require("./enums/health-status.enum");
|
|
7
|
+
/** Runs one indicator under a timeout; never throws. */
|
|
8
|
+
async function runCheck(indicator, timeoutMs) {
|
|
9
|
+
const started = node_perf_hooks_1.performance.now();
|
|
10
|
+
const base = { name: indicator.name, critical: indicator.critical ?? true };
|
|
11
|
+
let timer;
|
|
12
|
+
const timeout = new Promise((_, reject) => {
|
|
13
|
+
timer = setTimeout(() => reject(new Error(`timed out after ${timeoutMs} ms`)), timeoutMs);
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
await Promise.race([indicator.check(), timeout]);
|
|
17
|
+
return { ...base, ok: true, durationMs: elapsed(started) };
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
return { ...base, ok: false, durationMs: elapsed(started), err };
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
clearTimeout(timer);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** `down` when a critical check fails, `degraded` when only non-critical ones do. */
|
|
27
|
+
function overallStatus(results) {
|
|
28
|
+
const failed = results.filter((result) => !result.ok);
|
|
29
|
+
if (failed.some((result) => result.critical))
|
|
30
|
+
return health_status_enum_1.HealthStatus.Down;
|
|
31
|
+
return failed.length > 0 ? health_status_enum_1.HealthStatus.Degraded : health_status_enum_1.HealthStatus.Ok;
|
|
32
|
+
}
|
|
33
|
+
function elapsed(started) {
|
|
34
|
+
return Math.round((node_perf_hooks_1.performance.now() - started) * 10) / 10;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=check.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.util.js","sourceRoot":"","sources":["../src/check.util.ts"],"names":[],"mappings":";;AAMA,4BAkBC;AAGD,sCAIC;AA/BD,qDAA8C;AAE9C,mEAA0D;AAG1D,wDAAwD;AACjD,KAAK,UAAU,QAAQ,CAC1B,SAA0B,EAC1B,SAAiB;IAEjB,MAAM,OAAO,GAAG,6BAAW,CAAC,GAAG,EAAE,CAAC;IAClC,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;IAC5E,IAAI,KAAiC,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAC7C,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,SAAS,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAC9F,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACD,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;QACjD,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IACrE,CAAC;YAAS,CAAC;QACP,YAAY,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;AACL,CAAC;AAED,qFAAqF;AACrF,SAAgB,aAAa,CAAC,OAAsB;IAChD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACtD,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC;QAAE,OAAO,iCAAY,CAAC,IAAI,CAAC;IACvE,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,iCAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,iCAAY,CAAC,EAAE,CAAC;AACvE,CAAC;AAED,SAAS,OAAO,CAAC,OAAe;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,6BAAW,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EventLoopDelayDto = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
class EventLoopDelayDto {
|
|
15
|
+
p50Ms;
|
|
16
|
+
p99Ms;
|
|
17
|
+
maxMs;
|
|
18
|
+
windowSec;
|
|
19
|
+
}
|
|
20
|
+
exports.EventLoopDelayDto = EventLoopDelayDto;
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, swagger_1.ApiProperty)({ example: 10.1, type: Number }),
|
|
23
|
+
__metadata("design:type", Number)
|
|
24
|
+
], EventLoopDelayDto.prototype, "p50Ms", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, swagger_1.ApiProperty)({ example: 21.4, type: Number }),
|
|
27
|
+
__metadata("design:type", Number)
|
|
28
|
+
], EventLoopDelayDto.prototype, "p99Ms", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, swagger_1.ApiProperty)({ example: 48.7, type: Number }),
|
|
31
|
+
__metadata("design:type", Number)
|
|
32
|
+
], EventLoopDelayDto.prototype, "maxMs", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, swagger_1.ApiProperty)({
|
|
35
|
+
description: 'Seconds covered: since the previous status report, or since startup.',
|
|
36
|
+
example: 60,
|
|
37
|
+
type: Number,
|
|
38
|
+
}),
|
|
39
|
+
__metadata("design:type", Number)
|
|
40
|
+
], EventLoopDelayDto.prototype, "windowSec", void 0);
|
|
41
|
+
//# sourceMappingURL=event-loop-delay.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-loop-delay.dto.js","sourceRoot":"","sources":["../../src/dto/event-loop-delay.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA8C;AAE9C,MAAa,iBAAiB;IAE1B,KAAK,CAAU;IAGf,KAAK,CAAU;IAGf,KAAK,CAAU;IAOf,SAAS,CAAU;CACtB;AAhBD,8CAgBC;AAdG;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;gDAC9B;AAGf;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;gDAC9B;AAGf;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;gDAC9B;AAOf;IALC,IAAA,qBAAW,EAAC;QACT,WAAW,EAAE,sEAAsE;QACnF,OAAO,EAAE,EAAE;QACX,IAAI,EAAE,MAAM;KACf,CAAC;;oDACiB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HealthStatus } from '../enums/health-status.enum';
|
|
2
|
+
import { HealthCheckResultDto } from './health-check-result.dto';
|
|
3
|
+
export declare class HealthCheckResponseDto {
|
|
4
|
+
status: HealthStatus;
|
|
5
|
+
service: string;
|
|
6
|
+
timestamp: string;
|
|
7
|
+
checks?: HealthCheckResultDto[];
|
|
8
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HealthCheckResponseDto = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const health_status_enum_1 = require("../enums/health-status.enum");
|
|
15
|
+
const health_check_result_dto_1 = require("./health-check-result.dto");
|
|
16
|
+
class HealthCheckResponseDto {
|
|
17
|
+
status;
|
|
18
|
+
service;
|
|
19
|
+
timestamp;
|
|
20
|
+
checks;
|
|
21
|
+
}
|
|
22
|
+
exports.HealthCheckResponseDto = HealthCheckResponseDto;
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, swagger_1.ApiProperty)({ enum: health_status_enum_1.HealthStatus, enumName: 'HealthStatus', example: health_status_enum_1.HealthStatus.Ok }),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], HealthCheckResponseDto.prototype, "status", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, swagger_1.ApiProperty)({ example: 'api', type: String }),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], HealthCheckResponseDto.prototype, "service", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, swagger_1.ApiProperty)({ example: '2026-07-03T10:00:00.000Z', format: 'date-time', type: String }),
|
|
33
|
+
__metadata("design:type", String)
|
|
34
|
+
], HealthCheckResponseDto.prototype, "timestamp", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, swagger_1.ApiPropertyOptional)({
|
|
37
|
+
description: 'Readiness checks; absent on liveness.',
|
|
38
|
+
isArray: true,
|
|
39
|
+
type: health_check_result_dto_1.HealthCheckResultDto,
|
|
40
|
+
}),
|
|
41
|
+
__metadata("design:type", Array)
|
|
42
|
+
], HealthCheckResponseDto.prototype, "checks", void 0);
|
|
43
|
+
//# sourceMappingURL=health-check-response.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health-check-response.dto.js","sourceRoot":"","sources":["../../src/dto/health-check-response.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAmE;AAEnE,oEAA2D;AAC3D,uEAAiE;AAEjE,MAAa,sBAAsB;IAE/B,MAAM,CAAgB;IAGtB,OAAO,CAAU;IAGjB,SAAS,CAAU;IAOnB,MAAM,CAA0B;CACnC;AAhBD,wDAgBC;AAdG;IADC,IAAA,qBAAW,EAAC,EAAE,IAAI,EAAE,iCAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,iCAAY,CAAC,EAAE,EAAE,CAAC;;sDAClE;AAGtB;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;uDAC7B;AAGjB;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,0BAA0B,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yDACrE;AAOnB;IALC,IAAA,6BAAmB,EAAC;QACjB,WAAW,EAAE,uCAAuC;QACpD,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,8CAAoB;KAC7B,CAAC;;sDAC8B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HealthCheckResultDto = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const health_status_enum_1 = require("../enums/health-status.enum");
|
|
15
|
+
class HealthCheckResultDto {
|
|
16
|
+
name;
|
|
17
|
+
status;
|
|
18
|
+
critical;
|
|
19
|
+
durationMs;
|
|
20
|
+
error;
|
|
21
|
+
}
|
|
22
|
+
exports.HealthCheckResultDto = HealthCheckResultDto;
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, swagger_1.ApiProperty)({ example: 'database', type: String }),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], HealthCheckResultDto.prototype, "name", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, swagger_1.ApiProperty)({
|
|
29
|
+
description: 'A check is `ok` or `down`.',
|
|
30
|
+
enum: health_status_enum_1.HealthStatus,
|
|
31
|
+
enumName: 'HealthStatus',
|
|
32
|
+
example: health_status_enum_1.HealthStatus.Ok,
|
|
33
|
+
}),
|
|
34
|
+
__metadata("design:type", String)
|
|
35
|
+
], HealthCheckResultDto.prototype, "status", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, swagger_1.ApiProperty)({ description: 'A failing critical check fails readiness.', type: Boolean }),
|
|
38
|
+
__metadata("design:type", Boolean)
|
|
39
|
+
], HealthCheckResultDto.prototype, "critical", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, swagger_1.ApiProperty)({ example: 3.2, type: Number }),
|
|
42
|
+
__metadata("design:type", Number)
|
|
43
|
+
], HealthCheckResultDto.prototype, "durationMs", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, swagger_1.ApiPropertyOptional)({
|
|
46
|
+
description: 'Failure reason, only in `/health/status`: probes are public.',
|
|
47
|
+
example: 'timed out after 750 ms',
|
|
48
|
+
type: String,
|
|
49
|
+
}),
|
|
50
|
+
__metadata("design:type", String)
|
|
51
|
+
], HealthCheckResultDto.prototype, "error", void 0);
|
|
52
|
+
//# sourceMappingURL=health-check-result.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health-check-result.dto.js","sourceRoot":"","sources":["../../src/dto/health-check-result.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAmE;AAEnE,oEAA2D;AAE3D,MAAa,oBAAoB;IAE7B,IAAI,CAAU;IAQd,MAAM,CAAgB;IAGtB,QAAQ,CAAW;IAGnB,UAAU,CAAU;IAOpB,KAAK,CAAU;CAClB;AAxBD,oDAwBC;AAtBG;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;kDACrC;AAQd;IANC,IAAA,qBAAW,EAAC;QACT,WAAW,EAAE,4BAA4B;QACzC,IAAI,EAAE,iCAAY;QAClB,QAAQ,EAAE,cAAc;QACxB,OAAO,EAAE,iCAAY,CAAC,EAAE;KAC3B,CAAC;;oDACoB;AAGtB;IADC,IAAA,qBAAW,EAAC,EAAE,WAAW,EAAE,2CAA2C,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;sDACtE;AAGnB;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;wDACxB;AAOpB;IALC,IAAA,6BAAmB,EAAC;QACjB,WAAW,EAAE,8DAA8D;QAC3E,OAAO,EAAE,wBAAwB;QACjC,IAAI,EAAE,MAAM;KACf,CAAC;;mDACa"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HealthStatus } from '../enums/health-status.enum';
|
|
2
|
+
import { EventLoopDelayDto } from './event-loop-delay.dto';
|
|
3
|
+
import { HealthCheckResultDto } from './health-check-result.dto';
|
|
4
|
+
import { MemoryUsageDto } from './memory-usage.dto';
|
|
5
|
+
export declare class HealthReportResponseDto {
|
|
6
|
+
status: HealthStatus;
|
|
7
|
+
service: string;
|
|
8
|
+
version?: string;
|
|
9
|
+
node: string;
|
|
10
|
+
uptimeSec: number;
|
|
11
|
+
timestamp: string;
|
|
12
|
+
memory: MemoryUsageDto;
|
|
13
|
+
eventLoop: EventLoopDelayDto;
|
|
14
|
+
checks: HealthCheckResultDto[];
|
|
15
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HealthReportResponseDto = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const health_status_enum_1 = require("../enums/health-status.enum");
|
|
15
|
+
const event_loop_delay_dto_1 = require("./event-loop-delay.dto");
|
|
16
|
+
const health_check_result_dto_1 = require("./health-check-result.dto");
|
|
17
|
+
const memory_usage_dto_1 = require("./memory-usage.dto");
|
|
18
|
+
class HealthReportResponseDto {
|
|
19
|
+
status;
|
|
20
|
+
service;
|
|
21
|
+
version;
|
|
22
|
+
node;
|
|
23
|
+
uptimeSec;
|
|
24
|
+
timestamp;
|
|
25
|
+
memory;
|
|
26
|
+
eventLoop;
|
|
27
|
+
checks;
|
|
28
|
+
}
|
|
29
|
+
exports.HealthReportResponseDto = HealthReportResponseDto;
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, swagger_1.ApiProperty)({ enum: health_status_enum_1.HealthStatus, enumName: 'HealthStatus', example: health_status_enum_1.HealthStatus.Ok }),
|
|
32
|
+
__metadata("design:type", String)
|
|
33
|
+
], HealthReportResponseDto.prototype, "status", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, swagger_1.ApiProperty)({ example: 'api', type: String }),
|
|
36
|
+
__metadata("design:type", String)
|
|
37
|
+
], HealthReportResponseDto.prototype, "service", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, swagger_1.ApiPropertyOptional)({ example: 'v0.4.2', type: String }),
|
|
40
|
+
__metadata("design:type", String)
|
|
41
|
+
], HealthReportResponseDto.prototype, "version", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, swagger_1.ApiProperty)({ example: 'v22.23.2', type: String }),
|
|
44
|
+
__metadata("design:type", String)
|
|
45
|
+
], HealthReportResponseDto.prototype, "node", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, swagger_1.ApiProperty)({ example: 3600, type: Number }),
|
|
48
|
+
__metadata("design:type", Number)
|
|
49
|
+
], HealthReportResponseDto.prototype, "uptimeSec", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, swagger_1.ApiProperty)({ example: '2026-07-03T10:00:00.000Z', format: 'date-time', type: String }),
|
|
52
|
+
__metadata("design:type", String)
|
|
53
|
+
], HealthReportResponseDto.prototype, "timestamp", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, swagger_1.ApiProperty)({ type: memory_usage_dto_1.MemoryUsageDto }),
|
|
56
|
+
__metadata("design:type", memory_usage_dto_1.MemoryUsageDto)
|
|
57
|
+
], HealthReportResponseDto.prototype, "memory", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
(0, swagger_1.ApiProperty)({ type: event_loop_delay_dto_1.EventLoopDelayDto }),
|
|
60
|
+
__metadata("design:type", event_loop_delay_dto_1.EventLoopDelayDto)
|
|
61
|
+
], HealthReportResponseDto.prototype, "eventLoop", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
(0, swagger_1.ApiProperty)({ isArray: true, type: health_check_result_dto_1.HealthCheckResultDto }),
|
|
64
|
+
__metadata("design:type", Array)
|
|
65
|
+
], HealthReportResponseDto.prototype, "checks", void 0);
|
|
66
|
+
//# sourceMappingURL=health-report-response.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health-report-response.dto.js","sourceRoot":"","sources":["../../src/dto/health-report-response.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAmE;AAEnE,oEAA2D;AAC3D,iEAA2D;AAC3D,uEAAiE;AACjE,yDAAoD;AAEpD,MAAa,uBAAuB;IAEhC,MAAM,CAAgB;IAGtB,OAAO,CAAU;IAGjB,OAAO,CAAU;IAGjB,IAAI,CAAU;IAGd,SAAS,CAAU;IAGnB,SAAS,CAAU;IAGnB,MAAM,CAAkB;IAGxB,SAAS,CAAqB;IAG9B,MAAM,CAA0B;CACnC;AA3BD,0DA2BC;AAzBG;IADC,IAAA,qBAAW,EAAC,EAAE,IAAI,EAAE,iCAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,iCAAY,CAAC,EAAE,EAAE,CAAC;;uDAClE;AAGtB;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;wDAC7B;AAGjB;IADC,IAAA,6BAAmB,EAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;wDACxC;AAGjB;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;qDACrC;AAGd;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;0DAC1B;AAGnB;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,0BAA0B,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;0DACrE;AAGnB;IADC,IAAA,qBAAW,EAAC,EAAE,IAAI,EAAE,iCAAc,EAAE,CAAC;8BAC7B,iCAAc;uDAAC;AAGxB;IADC,IAAA,qBAAW,EAAC,EAAE,IAAI,EAAE,wCAAiB,EAAE,CAAC;8BAC7B,wCAAiB;0DAAC;AAG9B;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,8CAAoB,EAAE,CAAC;;uDAC3B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class MemoryUsageDto {
|
|
2
|
+
rssMiB: number;
|
|
3
|
+
heapUsedMiB: number;
|
|
4
|
+
heapTotalMiB: number;
|
|
5
|
+
externalMiB: number;
|
|
6
|
+
arrayBuffersMiB: number;
|
|
7
|
+
heapLimitMiB: number;
|
|
8
|
+
containerLimitMiB: number | null;
|
|
9
|
+
heapRatio: number;
|
|
10
|
+
rssRatio: number | null;
|
|
11
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MemoryUsageDto = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
class MemoryUsageDto {
|
|
15
|
+
rssMiB;
|
|
16
|
+
heapUsedMiB;
|
|
17
|
+
heapTotalMiB;
|
|
18
|
+
externalMiB;
|
|
19
|
+
arrayBuffersMiB;
|
|
20
|
+
heapLimitMiB;
|
|
21
|
+
containerLimitMiB;
|
|
22
|
+
heapRatio;
|
|
23
|
+
rssRatio;
|
|
24
|
+
}
|
|
25
|
+
exports.MemoryUsageDto = MemoryUsageDto;
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, swagger_1.ApiProperty)({ example: 182.4, type: Number }),
|
|
28
|
+
__metadata("design:type", Number)
|
|
29
|
+
], MemoryUsageDto.prototype, "rssMiB", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, swagger_1.ApiProperty)({ example: 96.1, type: Number }),
|
|
32
|
+
__metadata("design:type", Number)
|
|
33
|
+
], MemoryUsageDto.prototype, "heapUsedMiB", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, swagger_1.ApiProperty)({ example: 120.5, type: Number }),
|
|
36
|
+
__metadata("design:type", Number)
|
|
37
|
+
], MemoryUsageDto.prototype, "heapTotalMiB", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, swagger_1.ApiProperty)({ example: 4.2, type: Number }),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], MemoryUsageDto.prototype, "externalMiB", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, swagger_1.ApiProperty)({ example: 1.3, type: Number }),
|
|
44
|
+
__metadata("design:type", Number)
|
|
45
|
+
], MemoryUsageDto.prototype, "arrayBuffersMiB", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, swagger_1.ApiProperty)({ description: 'V8 `heap_size_limit`.', example: 259, type: Number }),
|
|
48
|
+
__metadata("design:type", Number)
|
|
49
|
+
], MemoryUsageDto.prototype, "heapLimitMiB", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, swagger_1.ApiProperty)({
|
|
52
|
+
description: 'cgroup memory limit, `null` when unconstrained.',
|
|
53
|
+
example: 512,
|
|
54
|
+
nullable: true,
|
|
55
|
+
type: Number,
|
|
56
|
+
}),
|
|
57
|
+
__metadata("design:type", Object)
|
|
58
|
+
], MemoryUsageDto.prototype, "containerLimitMiB", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, swagger_1.ApiProperty)({ description: '`heapUsed / heapLimit`.', example: 0.371, type: Number }),
|
|
61
|
+
__metadata("design:type", Number)
|
|
62
|
+
], MemoryUsageDto.prototype, "heapRatio", void 0);
|
|
63
|
+
__decorate([
|
|
64
|
+
(0, swagger_1.ApiProperty)({
|
|
65
|
+
description: '`rss / containerLimit`, `null` when unconstrained.',
|
|
66
|
+
example: 0.356,
|
|
67
|
+
nullable: true,
|
|
68
|
+
type: Number,
|
|
69
|
+
}),
|
|
70
|
+
__metadata("design:type", Object)
|
|
71
|
+
], MemoryUsageDto.prototype, "rssRatio", void 0);
|
|
72
|
+
//# sourceMappingURL=memory-usage.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-usage.dto.js","sourceRoot":"","sources":["../../src/dto/memory-usage.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA8C;AAE9C,MAAa,cAAc;IAEvB,MAAM,CAAU;IAGhB,WAAW,CAAU;IAGrB,YAAY,CAAU;IAGtB,WAAW,CAAU;IAGrB,eAAe,CAAU;IAGzB,YAAY,CAAU;IAQtB,iBAAiB,CAAiB;IAGlC,SAAS,CAAU;IAQnB,QAAQ,CAAiB;CAC5B;AArCD,wCAqCC;AAnCG;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CAC9B;AAGhB;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mDACxB;AAGrB;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;oDACxB;AAGtB;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mDACvB;AAGrB;IADC,IAAA,qBAAW,EAAC,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;uDACnB;AAGzB;IADC,IAAA,qBAAW,EAAC,EAAE,WAAW,EAAE,uBAAuB,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;oDAC5D;AAQtB;IANC,IAAA,qBAAW,EAAC;QACT,WAAW,EAAE,iDAAiD;QAC9D,OAAO,EAAE,GAAG;QACZ,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,MAAM;KACf,CAAC;;yDACgC;AAGlC;IADC,IAAA,qBAAW,EAAC,EAAE,WAAW,EAAE,yBAAyB,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDACnE;AAQnB;IANC,IAAA,qBAAW,EAAC;QACT,WAAW,EAAE,oDAAoD;QACjE,OAAO,EAAE,KAAK;QACd,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,MAAM;KACf,CAAC;;gDACuB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire values of the health contract. `degraded`: a non-critical check fails,
|
|
3
|
+
* the pod keeps serving. `down`: a critical check fails or the app is shutting
|
|
4
|
+
* down, readiness answers 503.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum HealthStatus {
|
|
7
|
+
Ok = "ok",
|
|
8
|
+
Degraded = "degraded",
|
|
9
|
+
Down = "down"
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HealthStatus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Wire values of the health contract. `degraded`: a non-critical check fails,
|
|
6
|
+
* the pod keeps serving. `down`: a critical check fails or the app is shutting
|
|
7
|
+
* down, readiness answers 503.
|
|
8
|
+
*/
|
|
9
|
+
var HealthStatus;
|
|
10
|
+
(function (HealthStatus) {
|
|
11
|
+
HealthStatus["Ok"] = "ok";
|
|
12
|
+
HealthStatus["Degraded"] = "degraded";
|
|
13
|
+
HealthStatus["Down"] = "down";
|
|
14
|
+
})(HealthStatus || (exports.HealthStatus = HealthStatus = {}));
|
|
15
|
+
//# sourceMappingURL=health-status.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health-status.enum.js","sourceRoot":"","sources":["../../src/enums/health-status.enum.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACpB,yBAAS,CAAA;IACT,qCAAqB,CAAA;IACrB,6BAAa,CAAA;AACjB,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_MEMORY_RATIO = exports.DEFAULT_CHECK_TIMEOUT_MS = exports.HEALTH_INDICATORS = exports.HEALTH_OPTIONS = void 0;
|
|
4
|
+
exports.HEALTH_OPTIONS = Symbol('HEALTH_OPTIONS');
|
|
5
|
+
exports.HEALTH_INDICATORS = Symbol('HEALTH_INDICATORS');
|
|
6
|
+
exports.DEFAULT_CHECK_TIMEOUT_MS = 750;
|
|
7
|
+
exports.DEFAULT_MEMORY_RATIO = 0.9;
|
|
8
|
+
//# sourceMappingURL=health.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.constants.js","sourceRoot":"","sources":["../src/health.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAEhD,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAC/B,QAAA,oBAAoB,GAAG,GAAG,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Type } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Built per `forRoot` so the app's probe decorators (`Public()`) land on this
|
|
4
|
+
* app's controller only, without mutating a shared class.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createHealthController(probeDecorators?: MethodDecorator[]): Type<unknown>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createHealthController = createHealthController;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
18
|
+
const health_check_response_dto_1 = require("./dto/health-check-response.dto");
|
|
19
|
+
const health_report_response_dto_1 = require("./dto/health-report-response.dto");
|
|
20
|
+
const health_status_enum_1 = require("./enums/health-status.enum");
|
|
21
|
+
const health_service_1 = require("./health.service");
|
|
22
|
+
/**
|
|
23
|
+
* Built per `forRoot` so the app's probe decorators (`Public()`) land on this
|
|
24
|
+
* app's controller only, without mutating a shared class.
|
|
25
|
+
*/
|
|
26
|
+
function createHealthController(probeDecorators = []) {
|
|
27
|
+
const probe = (0, common_1.applyDecorators)(...probeDecorators);
|
|
28
|
+
let HealthController = class HealthController {
|
|
29
|
+
health;
|
|
30
|
+
constructor(health) {
|
|
31
|
+
this.health = health;
|
|
32
|
+
}
|
|
33
|
+
live() {
|
|
34
|
+
return this.health.live();
|
|
35
|
+
}
|
|
36
|
+
async ready(res) {
|
|
37
|
+
const body = await this.health.ready();
|
|
38
|
+
if (body.status === health_status_enum_1.HealthStatus.Down)
|
|
39
|
+
res.status(common_1.HttpStatus.SERVICE_UNAVAILABLE);
|
|
40
|
+
return body;
|
|
41
|
+
}
|
|
42
|
+
status() {
|
|
43
|
+
return this.health.report();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, common_1.Get)(),
|
|
48
|
+
probe,
|
|
49
|
+
(0, common_1.Header)('Cache-Control', 'no-store'),
|
|
50
|
+
(0, swagger_1.ApiOperation)({ summary: 'Liveness: the process answers; no dependency is checked' }),
|
|
51
|
+
(0, swagger_1.ApiOkResponse)({ type: health_check_response_dto_1.HealthCheckResponseDto }),
|
|
52
|
+
__metadata("design:type", Function),
|
|
53
|
+
__metadata("design:paramtypes", []),
|
|
54
|
+
__metadata("design:returntype", health_check_response_dto_1.HealthCheckResponseDto)
|
|
55
|
+
], HealthController.prototype, "live", null);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, common_1.Get)('ready'),
|
|
58
|
+
probe,
|
|
59
|
+
(0, common_1.Header)('Cache-Control', 'no-store'),
|
|
60
|
+
(0, swagger_1.ApiOperation)({ summary: 'Readiness: memory pressure and critical dependencies' }),
|
|
61
|
+
(0, swagger_1.ApiOkResponse)({ type: health_check_response_dto_1.HealthCheckResponseDto }),
|
|
62
|
+
(0, swagger_1.ApiServiceUnavailableResponse)({ type: health_check_response_dto_1.HealthCheckResponseDto }),
|
|
63
|
+
__param(0, (0, common_1.Res)({ passthrough: true })),
|
|
64
|
+
__metadata("design:type", Function),
|
|
65
|
+
__metadata("design:paramtypes", [Object]),
|
|
66
|
+
__metadata("design:returntype", Promise)
|
|
67
|
+
], HealthController.prototype, "ready", null);
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, common_1.Get)('status'),
|
|
70
|
+
(0, common_1.Header)('Cache-Control', 'no-store'),
|
|
71
|
+
(0, swagger_1.ApiOperation)({
|
|
72
|
+
summary: 'Diagnostics: memory, event loop delay, every check with its error',
|
|
73
|
+
}),
|
|
74
|
+
(0, swagger_1.ApiOkResponse)({ type: health_report_response_dto_1.HealthReportResponseDto }),
|
|
75
|
+
__metadata("design:type", Function),
|
|
76
|
+
__metadata("design:paramtypes", []),
|
|
77
|
+
__metadata("design:returntype", Promise)
|
|
78
|
+
], HealthController.prototype, "status", null);
|
|
79
|
+
HealthController = __decorate([
|
|
80
|
+
(0, swagger_1.ApiTags)('health'),
|
|
81
|
+
(0, common_1.Controller)('health'),
|
|
82
|
+
__param(0, (0, common_1.Inject)(health_service_1.HealthService)),
|
|
83
|
+
__metadata("design:paramtypes", [health_service_1.HealthService])
|
|
84
|
+
], HealthController);
|
|
85
|
+
return HealthController;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=health.controller.js.map
|