@glydeunity/unity-healthcheck-mesh 0.0.0-stage → 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/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +343 -2
- package/dist/cjs/config.js +408 -0
- package/dist/cjs/ids.js +53 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/probe.js +81 -0
- package/dist/cjs/reporters.js +334 -0
- package/dist/cjs/runner.js +234 -0
- package/dist/cjs/schedule.js +23 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/uuid5.js +45 -0
- package/dist/cjs/version.js +10 -0
- package/dist/esm/config.d.ts +85 -0
- package/dist/esm/config.js +402 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/ids.d.ts +47 -0
- package/dist/esm/ids.js +47 -0
- package/dist/esm/ids.js.map +1 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/probe.d.ts +45 -0
- package/dist/esm/probe.js +77 -0
- package/dist/esm/probe.js.map +1 -0
- package/dist/esm/reporters.d.ts +75 -0
- package/dist/esm/reporters.js +330 -0
- package/dist/esm/reporters.js.map +1 -0
- package/dist/esm/runner.d.ts +25 -0
- package/dist/esm/runner.js +230 -0
- package/dist/esm/runner.js.map +1 -0
- package/dist/esm/schedule.d.ts +15 -0
- package/dist/esm/schedule.js +20 -0
- package/dist/esm/schedule.js.map +1 -0
- package/dist/esm/types.d.ts +101 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/uuid5.d.ts +12 -0
- package/dist/esm/uuid5.js +42 -0
- package/dist/esm/uuid5.js.map +1 -0
- package/dist/esm/version.d.ts +7 -0
- package/dist/esm/version.js +8 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +53 -4
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ResolvedHost } from './config.js';
|
|
2
|
+
/** Failure classes a probe reports when no HTTP response arrived. */
|
|
3
|
+
export type FailureClass = 'TIMEOUT' | 'DNS' | 'REFUSED' | 'TLS' | 'RESET' | 'NETWORK' | 'ABORTED';
|
|
4
|
+
/** What one probe saw. */
|
|
5
|
+
export interface ProbeOutcome {
|
|
6
|
+
/** HTTP status as text, or a {@link FailureClass}. */
|
|
7
|
+
result: string;
|
|
8
|
+
healthy: boolean;
|
|
9
|
+
/** HTTP status, or `null` when no response arrived. */
|
|
10
|
+
status: number | null;
|
|
11
|
+
latencyMs: number;
|
|
12
|
+
}
|
|
13
|
+
/** What a probe needs from its caller. */
|
|
14
|
+
export interface ProbeDependencies {
|
|
15
|
+
fetchImpl: typeof globalThis.fetch;
|
|
16
|
+
/** Aborts the probe when the round is cancelled. */
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
userAgent: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Folds a thrown fetch error into the closed failure vocabulary, so the result
|
|
22
|
+
* stays low-cardinality inside `check_id`. Node's fetch wraps the socket error
|
|
23
|
+
* (`TypeError: fetch failed`) and hangs the real cause off `.cause`, so the
|
|
24
|
+
* whole cause chain is read.
|
|
25
|
+
*
|
|
26
|
+
* @param error - Value thrown by `fetch`
|
|
27
|
+
* @returns The failure class
|
|
28
|
+
*/
|
|
29
|
+
export declare function classifyFailure(error: unknown): FailureClass;
|
|
30
|
+
/**
|
|
31
|
+
* Builds the URL a host is probed at.
|
|
32
|
+
* @param host - Resolved host
|
|
33
|
+
* @returns Absolute URL
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildTargetUrl(host: ResolvedHost): string;
|
|
36
|
+
/**
|
|
37
|
+
* GETs a host once. Never throws: a failed attempt is an outcome with a
|
|
38
|
+
* failure class as its result. Redirects are reported, not followed, so a
|
|
39
|
+
* bounce to a login page cannot read as healthy. The body is never read.
|
|
40
|
+
*
|
|
41
|
+
* @param host - Resolved host
|
|
42
|
+
* @param deps - Fetch client, abort signal and user agent
|
|
43
|
+
* @returns What the probe saw
|
|
44
|
+
*/
|
|
45
|
+
export declare function probe(host: ResolvedHost, deps: ProbeDependencies): Promise<ProbeOutcome>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
|
+
const DNS_CODES = ['ENOTFOUND', 'EAI_AGAIN', 'EAI_NONAME', 'EAI_FAIL', 'EAI_NODATA'];
|
|
3
|
+
const MAX_CAUSE_DEPTH = 5;
|
|
4
|
+
/**
|
|
5
|
+
* Folds a thrown fetch error into the closed failure vocabulary, so the result
|
|
6
|
+
* stays low-cardinality inside `check_id`. Node's fetch wraps the socket error
|
|
7
|
+
* (`TypeError: fetch failed`) and hangs the real cause off `.cause`, so the
|
|
8
|
+
* whole cause chain is read.
|
|
9
|
+
*
|
|
10
|
+
* @param error - Value thrown by `fetch`
|
|
11
|
+
* @returns The failure class
|
|
12
|
+
*/
|
|
13
|
+
export function classifyFailure(error) {
|
|
14
|
+
for (let link = error, depth = 0; typeof link === 'object' && link !== null && depth < MAX_CAUSE_DEPTH; depth += 1) {
|
|
15
|
+
const name = 'name' in link && typeof link.name === 'string' ? link.name : '';
|
|
16
|
+
const code = 'code' in link && typeof link.code === 'string' ? link.code.toUpperCase() : '';
|
|
17
|
+
if (name === 'AbortError')
|
|
18
|
+
return 'ABORTED';
|
|
19
|
+
if (name === 'TimeoutError' || code.includes('TIMEOUT'))
|
|
20
|
+
return 'TIMEOUT';
|
|
21
|
+
if (DNS_CODES.includes(code))
|
|
22
|
+
return 'DNS';
|
|
23
|
+
if (code === 'ECONNREFUSED')
|
|
24
|
+
return 'REFUSED';
|
|
25
|
+
if (code.startsWith('ERR_TLS') || code.startsWith('ERR_SSL') || code.includes('CERT'))
|
|
26
|
+
return 'TLS';
|
|
27
|
+
if (code === 'ECONNRESET' || code === 'EPIPE')
|
|
28
|
+
return 'RESET';
|
|
29
|
+
link = 'cause' in link ? link.cause : undefined;
|
|
30
|
+
}
|
|
31
|
+
return 'NETWORK';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Builds the URL a host is probed at.
|
|
35
|
+
* @param host - Resolved host
|
|
36
|
+
* @returns Absolute URL
|
|
37
|
+
*/
|
|
38
|
+
export function buildTargetUrl(host) {
|
|
39
|
+
const authority = host.port === undefined ? host.server : `${host.server}:${host.port}`;
|
|
40
|
+
return `${host.scheme}://${authority}${host.path}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* GETs a host once. Never throws: a failed attempt is an outcome with a
|
|
44
|
+
* failure class as its result. Redirects are reported, not followed, so a
|
|
45
|
+
* bounce to a login page cannot read as healthy. The body is never read.
|
|
46
|
+
*
|
|
47
|
+
* @param host - Resolved host
|
|
48
|
+
* @param deps - Fetch client, abort signal and user agent
|
|
49
|
+
* @returns What the probe saw
|
|
50
|
+
*/
|
|
51
|
+
export async function probe(host, deps) {
|
|
52
|
+
const startedAt = performance.now();
|
|
53
|
+
const timeout = AbortSignal.timeout(host.timeoutMs);
|
|
54
|
+
try {
|
|
55
|
+
const response = await deps.fetchImpl(buildTargetUrl(host), {
|
|
56
|
+
method: 'GET',
|
|
57
|
+
redirect: 'manual',
|
|
58
|
+
headers: { 'user-agent': deps.userAgent },
|
|
59
|
+
signal: deps.signal ? AbortSignal.any([deps.signal, timeout]) : timeout,
|
|
60
|
+
});
|
|
61
|
+
// Releasing the unread body returns the socket to the pool.
|
|
62
|
+
void response.body?.cancel().catch(() => undefined);
|
|
63
|
+
return {
|
|
64
|
+
result: String(response.status),
|
|
65
|
+
healthy: host.expect.includes(response.status),
|
|
66
|
+
status: response.status,
|
|
67
|
+
latencyMs: elapsedMs(startedAt),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return { result: classifyFailure(error), healthy: false, status: null, latencyMs: elapsedMs(startedAt) };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function elapsedMs(startedAt) {
|
|
75
|
+
return Math.max(0, Math.round(performance.now() - startedAt));
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=probe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"probe.js","sourceRoot":"","sources":["../../src/probe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAwB9C,MAAM,SAAS,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;AACrF,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,KAAK,IAAI,IAAI,GAAY,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,GAAG,eAAe,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC5H,MAAM,IAAI,GAAG,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,MAAM,IAAI,GAAG,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5F,IAAI,IAAI,KAAK,YAAY;YAAE,OAAO,SAAS,CAAC;QAC5C,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;QAC1E,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QAC3C,IAAI,IAAI,KAAK,cAAc;YAAE,OAAO,SAAS,CAAC;Q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AAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO;SACxE,CAAC,CAAC;QACH,4DAA4D;QAC5D,KAAK,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACpD,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;YAC/B,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;YAC9C,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC;SAChC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;IAC3G,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,SAAiB;IAClC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type ResolvedMesh, type ResolvedReport } from './config.js';
|
|
2
|
+
import type { ProbeReport } from './types.js';
|
|
3
|
+
/** Everything a reporter takes from its host process. */
|
|
4
|
+
export interface ReporterContext {
|
|
5
|
+
mesh: ResolvedMesh;
|
|
6
|
+
observer: string;
|
|
7
|
+
environment: string;
|
|
8
|
+
env: Record<string, string | undefined>;
|
|
9
|
+
fetchImpl: typeof globalThis.fetch;
|
|
10
|
+
now: () => number;
|
|
11
|
+
/** Receives one JSON line per report for `victorialogs/stdout`. */
|
|
12
|
+
writeLine: (line: string, report: ProbeReport) => void;
|
|
13
|
+
/** Receives a reporter problem; the runner throttles it. */
|
|
14
|
+
warn: (key: string, message: string, detail?: Record<string, unknown>) => void;
|
|
15
|
+
/** Replaces how the `opentelemetry` reporter finds `@opentelemetry/api`. Tests only. */
|
|
16
|
+
loadOtelApi?: () => Promise<OtelApi | undefined>;
|
|
17
|
+
}
|
|
18
|
+
/** Delivers one round of reports to one destination. */
|
|
19
|
+
export interface Reporter {
|
|
20
|
+
/** `payload-format` of the report target this reporter serves. */
|
|
21
|
+
readonly name: string;
|
|
22
|
+
/** @param reports - This round's reports, never empty */
|
|
23
|
+
report(reports: readonly ProbeReport[]): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Builds the reporter a report target asks for.
|
|
27
|
+
* @param context - Host process context for the mesh
|
|
28
|
+
* @param target - Resolved report target
|
|
29
|
+
* @returns The reporter
|
|
30
|
+
*/
|
|
31
|
+
export declare function createReporter(context: ReporterContext, target: ResolvedReport): Reporter;
|
|
32
|
+
/**
|
|
33
|
+
* The slice of `@opentelemetry/api` the `opentelemetry` reporter calls. It is
|
|
34
|
+
* described structurally so the package compiles without OpenTelemetry.
|
|
35
|
+
*/
|
|
36
|
+
export interface OtelApi {
|
|
37
|
+
logs: {
|
|
38
|
+
getLogger(name: string, version?: string): {
|
|
39
|
+
emit(record: OtelLogRecord): void;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
metrics: {
|
|
43
|
+
getMeter(name: string, version?: string): {
|
|
44
|
+
createObservableGauge(name: string, options?: {
|
|
45
|
+
description?: string;
|
|
46
|
+
unit?: string;
|
|
47
|
+
}): {
|
|
48
|
+
addCallback(callback: (result: OtelObservableResult) => void): void;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** A log record as `Logger.emit` takes it. */
|
|
54
|
+
export interface OtelLogRecord {
|
|
55
|
+
timestamp?: Date;
|
|
56
|
+
severityNumber: number;
|
|
57
|
+
severityText: string;
|
|
58
|
+
body: string;
|
|
59
|
+
attributes: Record<string, string | number | boolean>;
|
|
60
|
+
}
|
|
61
|
+
/** What an observable instrument hands its callback at collection time. */
|
|
62
|
+
export interface OtelObservableResult {
|
|
63
|
+
observe(value: number, attributes?: Record<string, string>): void;
|
|
64
|
+
}
|
|
65
|
+
/** Gauge the `opentelemetry` reporter feeds: 1 when the last probe was healthy, else 0. */
|
|
66
|
+
export declare const UP_GAUGE_NAME = "mesh_probe_up";
|
|
67
|
+
/**
|
|
68
|
+
* Loads `@opentelemetry/api`. It is an optional peer dependency: a process
|
|
69
|
+
* without it gets the reason once and sends nothing to OpenTelemetry.
|
|
70
|
+
*
|
|
71
|
+
* @param importer - Performs the dynamic import; tests substitute it
|
|
72
|
+
* @param unavailable - Receives the reason, at most once
|
|
73
|
+
* @returns The API, or `undefined` when it cannot be used
|
|
74
|
+
*/
|
|
75
|
+
export declare function importOtelApi(importer: () => Promise<unknown>, unavailable: (message: string) => void): Promise<OtelApi | undefined>;
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { DEFAULT_BUGSNAG_URL } from './config.js';
|
|
3
|
+
import { uuid5 } from './uuid5.js';
|
|
4
|
+
import { PACKAGE_NAME, PACKAGE_URL, PACKAGE_VERSION } from './version.js';
|
|
5
|
+
/**
|
|
6
|
+
* Builds the reporter a report target asks for.
|
|
7
|
+
* @param context - Host process context for the mesh
|
|
8
|
+
* @param target - Resolved report target
|
|
9
|
+
* @returns The reporter
|
|
10
|
+
*/
|
|
11
|
+
export function createReporter(context, target) {
|
|
12
|
+
switch (target.format) {
|
|
13
|
+
case 'victorialogs/stdout':
|
|
14
|
+
return new StdoutReporter(context);
|
|
15
|
+
case 'victorialogs':
|
|
16
|
+
return new VictoriaLogsReporter(context, target);
|
|
17
|
+
case 'bugsnag':
|
|
18
|
+
return new BugsnagReporter(context, target);
|
|
19
|
+
case 'opentelemetry':
|
|
20
|
+
return new OpenTelemetryReporter(context);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Target URL as a person reads it; the port is always shown. */
|
|
24
|
+
function targetUrl(report) {
|
|
25
|
+
return `${report.scheme}://${report.server}:${report.port}${report.path}`;
|
|
26
|
+
}
|
|
27
|
+
function describeProbe(report) {
|
|
28
|
+
return (`mesh_probe mesh=${report.mesh} observer=${report.observer} target=${targetUrl(report)} ` +
|
|
29
|
+
`result=${report.result} healthy=${report.healthy} latency_ms=${report.latency_ms} check_id=${report.check_id}`);
|
|
30
|
+
}
|
|
31
|
+
function streamValue(value) {
|
|
32
|
+
return value.replace(/["\\]/g, '_');
|
|
33
|
+
}
|
|
34
|
+
async function postOrThrow(request) {
|
|
35
|
+
let response;
|
|
36
|
+
try {
|
|
37
|
+
response = await request.fetchImpl(request.url, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: request.headers,
|
|
40
|
+
body: request.body,
|
|
41
|
+
signal: AbortSignal.timeout(request.timeoutMs),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new Error(`request failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
46
|
+
}
|
|
47
|
+
// The response body is never read; releasing it returns the socket to the pool.
|
|
48
|
+
void response.body?.cancel().catch(() => undefined);
|
|
49
|
+
if (!response.ok)
|
|
50
|
+
throw new Error(`HTTP ${response.status} ${response.statusText}`);
|
|
51
|
+
}
|
|
52
|
+
/** Prints one JSON line per report for a stdout shipper to forward. */
|
|
53
|
+
class StdoutReporter {
|
|
54
|
+
name = 'victorialogs/stdout';
|
|
55
|
+
context;
|
|
56
|
+
constructor(context) {
|
|
57
|
+
this.context = context;
|
|
58
|
+
}
|
|
59
|
+
report(reports) {
|
|
60
|
+
for (const report of reports) {
|
|
61
|
+
const line = JSON.stringify(report);
|
|
62
|
+
this.context.writeLine(line, report);
|
|
63
|
+
}
|
|
64
|
+
return Promise.resolve();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** POSTs one JSON-line batch to a VictoriaLogs `/insert/jsonline` endpoint. */
|
|
68
|
+
class VictoriaLogsReporter {
|
|
69
|
+
name = 'victorialogs';
|
|
70
|
+
context;
|
|
71
|
+
ingestUrl;
|
|
72
|
+
timeoutMs;
|
|
73
|
+
authorization;
|
|
74
|
+
constructor(context, target) {
|
|
75
|
+
this.context = context;
|
|
76
|
+
this.ingestUrl = `${(target.url ?? '').replace(/\/+$/, '')}/insert/jsonline`;
|
|
77
|
+
this.timeoutMs = target.timeoutMs;
|
|
78
|
+
const username = context.env[target.usernameEnv]?.trim();
|
|
79
|
+
const password = context.env[target.passwordEnv]?.trim();
|
|
80
|
+
this.authorization =
|
|
81
|
+
username && password ? `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}` : undefined;
|
|
82
|
+
}
|
|
83
|
+
async report(reports) {
|
|
84
|
+
if (reports.length === 0)
|
|
85
|
+
return;
|
|
86
|
+
const lines = reports.map((report) => JSON.stringify(this.toLine(report)));
|
|
87
|
+
const headers = { 'Content-Type': 'application/stream+json' };
|
|
88
|
+
if (this.authorization)
|
|
89
|
+
headers.Authorization = this.authorization;
|
|
90
|
+
await postOrThrow({
|
|
91
|
+
fetchImpl: this.context.fetchImpl,
|
|
92
|
+
url: this.ingestUrl,
|
|
93
|
+
body: lines.join('\n'),
|
|
94
|
+
headers,
|
|
95
|
+
timeoutMs: this.timeoutMs,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Shapes a report as a VictoriaLogs log entry. `mesh` and `observer` become
|
|
100
|
+
* stream labels; every other field stays a plain, queryable field.
|
|
101
|
+
*/
|
|
102
|
+
toLine(report) {
|
|
103
|
+
const { mesh, observer, ...fields } = report;
|
|
104
|
+
return {
|
|
105
|
+
_time: report.at,
|
|
106
|
+
_msg: describeProbe(report),
|
|
107
|
+
_stream: `{mesh="${streamValue(mesh)}",observer="${streamValue(observer)}"}`,
|
|
108
|
+
...fields,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Reports healthy/unhealthy transitions to Bugsnag.
|
|
114
|
+
*
|
|
115
|
+
* Bugsnag groups events under a `groupingHash`; it does not reject repeats. A
|
|
116
|
+
* per-minute hash would open a new error every minute, so the hash is stable
|
|
117
|
+
* per target and only transitions are sent: one event when a target first
|
|
118
|
+
* fails, one when it recovers. Every server observing the same target lands in
|
|
119
|
+
* the same error, with `user.id` naming which server saw it.
|
|
120
|
+
*/
|
|
121
|
+
class BugsnagReporter {
|
|
122
|
+
name = 'bugsnag';
|
|
123
|
+
context;
|
|
124
|
+
target;
|
|
125
|
+
healthyByTarget = new Map();
|
|
126
|
+
warnedMissingKey = false;
|
|
127
|
+
constructor(context, target) {
|
|
128
|
+
this.context = context;
|
|
129
|
+
this.target = target;
|
|
130
|
+
}
|
|
131
|
+
async report(reports) {
|
|
132
|
+
if (reports.length === 0)
|
|
133
|
+
return;
|
|
134
|
+
const apiKey = this.context.env[this.target.apiKeyEnv]?.trim();
|
|
135
|
+
if (!apiKey) {
|
|
136
|
+
if (!this.warnedMissingKey) {
|
|
137
|
+
this.warnedMissingKey = true;
|
|
138
|
+
this.context.warn(`${this.context.mesh.id}:bugsnag:key`, `Bugsnag reporter is off: ${this.target.apiKeyEnv} is not set, so mesh failures will not reach Bugsnag`);
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const events = reports.flatMap((report) => this.transitions(report));
|
|
143
|
+
if (events.length === 0)
|
|
144
|
+
return;
|
|
145
|
+
await postOrThrow({
|
|
146
|
+
fetchImpl: this.context.fetchImpl,
|
|
147
|
+
url: this.target.url ?? DEFAULT_BUGSNAG_URL,
|
|
148
|
+
body: JSON.stringify({
|
|
149
|
+
apiKey,
|
|
150
|
+
payloadVersion: '5',
|
|
151
|
+
notifier: { name: PACKAGE_NAME, version: PACKAGE_VERSION, url: PACKAGE_URL },
|
|
152
|
+
events,
|
|
153
|
+
}),
|
|
154
|
+
headers: {
|
|
155
|
+
'Content-Type': 'application/json',
|
|
156
|
+
'Bugsnag-Api-Key': apiKey,
|
|
157
|
+
'Bugsnag-Payload-Version': '5',
|
|
158
|
+
'Bugsnag-Sent-At': new Date(this.context.now()).toISOString(),
|
|
159
|
+
},
|
|
160
|
+
timeoutMs: this.target.timeoutMs,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/** Updates the target's state and returns the event its transition warrants, if any. */
|
|
164
|
+
transitions(report) {
|
|
165
|
+
const key = targetUrl(report);
|
|
166
|
+
const previous = this.healthyByTarget.get(key);
|
|
167
|
+
this.healthyByTarget.set(key, report.healthy);
|
|
168
|
+
if (report.healthy) {
|
|
169
|
+
return previous === false ? [this.event(report, 'info', 'MeshProbeRecovered')] : [];
|
|
170
|
+
}
|
|
171
|
+
return previous === false ? [] : [this.event(report, 'error', 'MeshProbeUnhealthy')];
|
|
172
|
+
}
|
|
173
|
+
event(report, severity, errorClass) {
|
|
174
|
+
const request = `GET ${targetUrl(report)} from ${this.context.observer}`;
|
|
175
|
+
const message = severity === 'error'
|
|
176
|
+
? `${request} returned ${report.result} after ${report.latency_ms} ms`
|
|
177
|
+
: `${request} recovered: ${report.result} in ${report.latency_ms} ms`;
|
|
178
|
+
return {
|
|
179
|
+
timestamp: report.at,
|
|
180
|
+
exceptions: [
|
|
181
|
+
{
|
|
182
|
+
errorClass,
|
|
183
|
+
message,
|
|
184
|
+
stacktrace: [{ file: 'unity-mesh/probe', lineNumber: 1, method: 'probe', type: 'node', inProject: false }],
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
severity,
|
|
188
|
+
unhandled: false,
|
|
189
|
+
context: `mesh_probe ${report.mesh}`,
|
|
190
|
+
groupingHash: uuid5(this.context.mesh.namespace, ['bugsnag', report.mesh, report.server, report.path].join('|')),
|
|
191
|
+
user: { id: this.context.observer },
|
|
192
|
+
app: { version: PACKAGE_VERSION, releaseStage: this.context.environment },
|
|
193
|
+
metaData: { mesh: { ...report } },
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/** Gauge the `opentelemetry` reporter feeds: 1 when the last probe was healthy, else 0. */
|
|
198
|
+
export const UP_GAUGE_NAME = 'mesh_probe_up';
|
|
199
|
+
/** Where the OpenTelemetry API keeps the providers registered in the process. */
|
|
200
|
+
const OTEL_GLOBAL_KEY = Symbol.for('opentelemetry.js.api.1');
|
|
201
|
+
const SEVERITY_INFO = 9;
|
|
202
|
+
const SEVERITY_ERROR = 17;
|
|
203
|
+
/**
|
|
204
|
+
* Loads `@opentelemetry/api`. It is an optional peer dependency: a process
|
|
205
|
+
* without it gets the reason once and sends nothing to OpenTelemetry.
|
|
206
|
+
*
|
|
207
|
+
* @param importer - Performs the dynamic import; tests substitute it
|
|
208
|
+
* @param unavailable - Receives the reason, at most once
|
|
209
|
+
* @returns The API, or `undefined` when it cannot be used
|
|
210
|
+
*/
|
|
211
|
+
export async function importOtelApi(importer, unavailable) {
|
|
212
|
+
let loaded;
|
|
213
|
+
try {
|
|
214
|
+
loaded = await importer();
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
unavailable(`is not installed or could not be loaded (${error instanceof Error ? error.message : String(error)})`);
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
const candidate = loaded;
|
|
221
|
+
// An ESM build carries named exports; a CommonJS one arrives as `default`.
|
|
222
|
+
const chosen = candidate.logs && candidate.metrics ? candidate : candidate.default;
|
|
223
|
+
if (!hasLogsAndMeters(chosen)) {
|
|
224
|
+
unavailable('exposed neither logs nor meters');
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
return chosen;
|
|
228
|
+
}
|
|
229
|
+
function hasLogsAndMeters(api) {
|
|
230
|
+
return api?.logs !== undefined && api.metrics !== undefined;
|
|
231
|
+
}
|
|
232
|
+
/** Which OpenTelemetry signals have a provider registered in this process. */
|
|
233
|
+
function registeredOtelSignals() {
|
|
234
|
+
const global = globalThis[OTEL_GLOBAL_KEY];
|
|
235
|
+
return { logs: global?.logs !== undefined, metrics: global?.metrics !== undefined };
|
|
236
|
+
}
|
|
237
|
+
/** Report fields as OpenTelemetry attributes. A null status is left out; null is not an attribute value. */
|
|
238
|
+
function toOtelAttributes(report) {
|
|
239
|
+
const attributes = {};
|
|
240
|
+
for (const [key, value] of Object.entries(report)) {
|
|
241
|
+
if (value !== null)
|
|
242
|
+
attributes[key] = value;
|
|
243
|
+
}
|
|
244
|
+
return attributes;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Emits reports through the process's own OpenTelemetry providers.
|
|
248
|
+
*
|
|
249
|
+
* Every report becomes one log record, INFO when healthy and ERROR otherwise,
|
|
250
|
+
* with the report's fields as attributes. The reporter also feeds the
|
|
251
|
+
* {@link UP_GAUGE_NAME} gauge for each target it has seen. Where the host runs
|
|
252
|
+
* Azure Monitor's OpenTelemetry distro, both reach Application Insights, and
|
|
253
|
+
* through it the Log Analytics workspace, with no further setup.
|
|
254
|
+
*
|
|
255
|
+
* Nothing is sent when `@opentelemetry/api` is absent or no provider is
|
|
256
|
+
* registered; each case is reported once.
|
|
257
|
+
*/
|
|
258
|
+
class OpenTelemetryReporter {
|
|
259
|
+
name = 'opentelemetry';
|
|
260
|
+
context;
|
|
261
|
+
upByTarget = new Map();
|
|
262
|
+
apiPromise;
|
|
263
|
+
logger;
|
|
264
|
+
gauge;
|
|
265
|
+
warnedUnregistered = false;
|
|
266
|
+
constructor(context) {
|
|
267
|
+
this.context = context;
|
|
268
|
+
}
|
|
269
|
+
async report(reports) {
|
|
270
|
+
if (reports.length === 0)
|
|
271
|
+
return;
|
|
272
|
+
this.apiPromise ??= (this.context.loadOtelApi ?? (() => this.importApi()))();
|
|
273
|
+
const api = await this.apiPromise;
|
|
274
|
+
if (!api)
|
|
275
|
+
return;
|
|
276
|
+
const signals = registeredOtelSignals();
|
|
277
|
+
if (!signals.logs && !signals.metrics) {
|
|
278
|
+
if (!this.warnedUnregistered) {
|
|
279
|
+
this.warnedUnregistered = true;
|
|
280
|
+
this.context.warn(`${this.context.mesh.id}:opentelemetry`, 'OpenTelemetry reporter has nowhere to send: no provider is registered in this process. Start telemetry before the probes.');
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
for (const report of reports) {
|
|
285
|
+
this.upByTarget.set(`${report.server}${report.path}`, {
|
|
286
|
+
healthy: report.healthy,
|
|
287
|
+
attributes: { mesh: report.mesh, observer: report.observer, server: report.server, path: report.path },
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
if (signals.logs)
|
|
291
|
+
this.emitLogs(api, reports);
|
|
292
|
+
if (signals.metrics)
|
|
293
|
+
this.recordGauge(api);
|
|
294
|
+
}
|
|
295
|
+
importApi() {
|
|
296
|
+
return importOtelApi(() => import('@opentelemetry/api'), (message) => {
|
|
297
|
+
this.context.warn(`${this.context.mesh.id}:opentelemetry`, `OpenTelemetry reporter is off: @opentelemetry/api ${message}`);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
emitLogs(api, reports) {
|
|
301
|
+
this.logger ??= api.logs.getLogger(PACKAGE_NAME, PACKAGE_VERSION);
|
|
302
|
+
for (const report of reports) {
|
|
303
|
+
this.logger.emit({
|
|
304
|
+
timestamp: new Date(report.at),
|
|
305
|
+
severityNumber: report.healthy ? SEVERITY_INFO : SEVERITY_ERROR,
|
|
306
|
+
severityText: report.healthy ? 'INFO' : 'ERROR',
|
|
307
|
+
body: describeProbe(report),
|
|
308
|
+
attributes: toOtelAttributes(report),
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
recordGauge(api) {
|
|
313
|
+
// Created, and given its single callback, the first time a round reports.
|
|
314
|
+
// A callback per round would make the metric reader observe every target again.
|
|
315
|
+
this.gauge ??= this.createGauge(api);
|
|
316
|
+
}
|
|
317
|
+
createGauge(api) {
|
|
318
|
+
const gauge = api.metrics.getMeter(PACKAGE_NAME, PACKAGE_VERSION).createObservableGauge(UP_GAUGE_NAME, {
|
|
319
|
+
description: "1 when this observer's last probe of the target was healthy, 0 otherwise",
|
|
320
|
+
unit: '1',
|
|
321
|
+
});
|
|
322
|
+
gauge.addCallback((result) => {
|
|
323
|
+
for (const sample of this.upByTarget.values()) {
|
|
324
|
+
result.observe(sample.healthy ? 1 : 0, sample.attributes);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
return gauge;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
//# sourceMappingURL=reporters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporters.js","sourceRoot":"","sources":["../../src/reporters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAA0C,MAAM,aAAa,CAAC;AAE1F,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AA0B1E;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAAwB,EAAE,MAAsB;IAC7E,QAAQ,MAAM,CAAC,MAAM,EAAE,CAAC;QACtB,KAAK,qBAAqB;YACxB,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QACrC,KAAK,cAAc;YACjB,OAAO,IAAI,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACnD,KAAK,SAAS;YACZ,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC9C,KAAK,eAAe;YAClB,OAAO,IAAI,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC;AAED,iEAAiE;AACjE,SAAS,SAAS,CAAC,MAAmB;IACpC,OAAO,GAAG,MAAM,CAAC,MAAM,MAAM,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,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C,KAAK,KAAK,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;IAEO,WAAW,CACjB,GAAY;QAEZ,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,qBAAqB,CAAC,aAAa,EAAE;YACrG,WAAW,EAAE,0EAA0E;YACvF,IAAI,EAAE,GAAG;SACV,CAAC,CAAC;QACH,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,EAAE;YAC3B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC9C,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MeshProbesHandle, MeshProbesOptions, ProbeReport } from './types.js';
|
|
2
|
+
/** How long a reporter problem stays quiet after being logged. */
|
|
3
|
+
export declare const DIAGNOSTIC_INTERVAL_MS: number;
|
|
4
|
+
/**
|
|
5
|
+
* Starts probing: every mesh that applies to this environment runs on its own
|
|
6
|
+
* interval until `stop()` is called. Timers are ordinary ones, so they keep a
|
|
7
|
+
* bare script alive.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Mesh list plus optional overrides. `meshes` may be the raw
|
|
10
|
+
* `unity-mesh` value or the output of `parseMeshConfig`
|
|
11
|
+
* @returns The running meshes
|
|
12
|
+
* @throws MeshConfigError when the mesh list is not usable
|
|
13
|
+
*/
|
|
14
|
+
export declare function startMeshProbes(options: MeshProbesOptions): MeshProbesHandle;
|
|
15
|
+
/**
|
|
16
|
+
* Runs one round on every mesh that applies to this environment, with no
|
|
17
|
+
* timers. Bugsnag's transition memory lives in the process, so a one-shot
|
|
18
|
+
* round reports every failure it sees as a new one.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Mesh list plus optional overrides. `meshes` may be the raw
|
|
21
|
+
* `unity-mesh` value or the output of `parseMeshConfig`
|
|
22
|
+
* @returns This round's reports
|
|
23
|
+
* @throws MeshConfigError when the mesh list is not usable
|
|
24
|
+
*/
|
|
25
|
+
export declare function runProbeRound(options: MeshProbesOptions): Promise<ProbeReport[]>;
|