authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 01:47:36-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 01:47:36-07:00
log45f5a5ffb3257d510f249b14c36a514beff2868a
tree2de38440e26c06a44a000d2b24879e207c7cb926
parent4631000f5a7666c88402ce11a9ebb8cdef7a7dad
signature Signed by PGP key B5690EEEBB952194

refactor(server): simplify native telemetry error internals (#10057)


2 files changed, 3 insertions(+), 49 deletions(-)

apps/server/src/resourceTelemetry/NativeTelemetryClient.test.ts-42
......@@ -1,6 +1,5 @@
11import type { HostPowerSnapshot } from "@t3tools/contracts";
22import { describe, expect, it } from "@effect/vitest";
3import * as Cause from "effect/Cause";
43import * as DateTime from "effect/DateTime";
54import * as Deferred from "effect/Deferred";
65import * as Effect from "effect/Effect";
......@@ -9,12 +8,9 @@ import * as Ref from "effect/Ref";
98import * as Semaphore from "effect/Semaphore";
109
1110import {
12 NativeTelemetryRequestTimedOut,
13 NativeTelemetryStreamClosed,
1411 canCommandNativeTelemetrySidecar,
1512 canRequestNativeTelemetryRetry,
1613 commitCollectionControlUpdate,
17 nativeTelemetrySupervisorFailureMessage,
1814 retainRecentNativeTelemetryFailures,
1915 resolveNativeSampleIntervalMs,
2016 synchronizeCollectionControlOnStart,
......@@ -82,44 +78,6 @@ describe("canCommandNativeTelemetrySidecar", () => {
8278 });
8379});
8480
85describe("NativeTelemetryRequestTimedOut", () => {
86 it("models history and sample request deadlines without a fabricated cause", () => {
87 const historyTimeout = new NativeTelemetryRequestTimedOut({
88 operation: "readHistory",
89 timeoutMs: 15_000,
90 });
91 const sampleTimeout = new NativeTelemetryRequestTimedOut({
92 operation: "sampleNow",
93 timeoutMs: 5_000,
94 });
95
96 expect(historyTimeout.message).toBe(
97 "Resource monitor 'readHistory' request timed out after 15000ms.",
98 );
99 expect(sampleTimeout.message).toBe(
100 "Resource monitor 'sampleNow' request timed out after 5000ms.",
101 );
102 expect("cause" in historyTimeout).toBe(false);
103 expect("cause" in sampleTimeout).toBe(false);
104 });
105});
106
107describe("native telemetry supervisor failures", () => {
108 it("distinguishes a closed event stream from a process exit", () => {
109 expect(new NativeTelemetryStreamClosed().message).toBe(
110 "Resource monitor event stream closed unexpectedly.",
111 );
112 });
113
114 it("keeps defect details out of the caller-visible health message", () => {
115 const secret = "credential=do-not-expose";
116 const message = nativeTelemetrySupervisorFailureMessage(Cause.die(new Error(secret)));
117
118 expect(message).toBe("Resource monitor supervisor stopped unexpectedly.");
119 expect(message).not.toContain(secret);
120 });
121});
122
12381describe("retainRecentNativeTelemetryFailures", () => {
12482 it("expires old failures so an isolated crash restarts from the initial backoff", () => {
12583 expect(retainRecentNativeTelemetryFailures([0, 30_000], 90_001)).toEqual([]);
apps/server/src/resourceTelemetry/NativeTelemetryClient.ts+3-7
......@@ -73,7 +73,7 @@ export class NativeTelemetryHandshakeTimedOut extends Schema.TaggedErrorClass<Na
7373 }
7474}
7575
76export class NativeTelemetryRequestTimedOut extends Schema.TaggedErrorClass<NativeTelemetryRequestTimedOut>()(
76class NativeTelemetryRequestTimedOut extends Schema.TaggedErrorClass<NativeTelemetryRequestTimedOut>()(
7777 "NativeTelemetryRequestTimedOut",
7878 {
7979 operation: Schema.Literals(["readHistory", "sampleNow"]),
......@@ -131,7 +131,7 @@ export class NativeTelemetryExited extends Schema.TaggedErrorClass<NativeTelemet
131131 }
132132}
133133
134export class NativeTelemetryStreamClosed extends Schema.TaggedErrorClass<NativeTelemetryStreamClosed>()(
134class NativeTelemetryStreamClosed extends Schema.TaggedErrorClass<NativeTelemetryStreamClosed>()(
135135 "NativeTelemetryStreamClosed",
136136 {},
137137) {
......@@ -340,10 +340,6 @@ function errorMessage(error: NativeTelemetryClientError): string {
340340 return error.message;
341341}
342342
343export function nativeTelemetrySupervisorFailureMessage(_cause: Cause.Cause<unknown>): string {
344 return "Resource monitor supervisor stopped unexpectedly.";
345}
346
347343export function canRequestNativeTelemetryRetry(
348344 status: ResourceTelemetrySourceStatus,
349345 hasHandle: boolean,
......@@ -734,7 +730,7 @@ export const make = Effect.fn("resourceTelemetry.nativeTelemetryClient.make")(fu
734730 ...current,
735731 status: "unavailable" as const,
736732 hello: Option.none(),
737 lastError: Option.some(nativeTelemetrySupervisorFailureMessage(cause)),
733 lastError: Option.some("Resource monitor supervisor stopped unexpectedly."),
738734 })).pipe(
739735 Effect.andThen(publishHealth),
740736 Effect.andThen(