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 @@...@@ -1,6 +1,5 @@
1import type { HostPowerSnapshot } from "@t3tools/contracts";1import type { HostPowerSnapshot } from "@t3tools/contracts";
2import { describe, expect, it } from "@effect/vitest";2import { describe, expect, it } from "@effect/vitest";
3import * as Cause from "effect/Cause";
4import * as DateTime from "effect/DateTime";3import * as DateTime from "effect/DateTime";
5import * as Deferred from "effect/Deferred";4import * as Deferred from "effect/Deferred";
6import * as Effect from "effect/Effect";5import * as Effect from "effect/Effect";
...@@ -9,12 +8,9 @@ import * as Ref from "effect/Ref";...@@ -9,12 +8,9 @@ import * as Ref from "effect/Ref";
9import * as Semaphore from "effect/Semaphore";8import * as Semaphore from "effect/Semaphore";
109
11import {10import {
12 NativeTelemetryRequestTimedOut,
13 NativeTelemetryStreamClosed,
14 canCommandNativeTelemetrySidecar,11 canCommandNativeTelemetrySidecar,
15 canRequestNativeTelemetryRetry,12 canRequestNativeTelemetryRetry,
16 commitCollectionControlUpdate,13 commitCollectionControlUpdate,
17 nativeTelemetrySupervisorFailureMessage,
18 retainRecentNativeTelemetryFailures,14 retainRecentNativeTelemetryFailures,
19 resolveNativeSampleIntervalMs,15 resolveNativeSampleIntervalMs,
20 synchronizeCollectionControlOnStart,16 synchronizeCollectionControlOnStart,
...@@ -82,44 +78,6 @@ describe("canCommandNativeTelemetrySidecar", () => {...@@ -82,44 +78,6 @@ describe("canCommandNativeTelemetrySidecar", () => {
82 });78 });
83});79});
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
123describe("retainRecentNativeTelemetryFailures", () => {81describe("retainRecentNativeTelemetryFailures", () => {
124 it("expires old failures so an isolated crash restarts from the initial backoff", () => {82 it("expires old failures so an isolated crash restarts from the initial backoff", () => {
125 expect(retainRecentNativeTelemetryFailures([0, 30_000], 90_001)).toEqual([]);83 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...@@ -73,7 +73,7 @@ export class NativeTelemetryHandshakeTimedOut extends Schema.TaggedErrorClass<Na
73 }73 }
74}74}
7575
76export class NativeTelemetryRequestTimedOut extends Schema.TaggedErrorClass<NativeTelemetryRequestTimedOut>()(76class NativeTelemetryRequestTimedOut extends Schema.TaggedErrorClass<NativeTelemetryRequestTimedOut>()(
77 "NativeTelemetryRequestTimedOut",77 "NativeTelemetryRequestTimedOut",
78 {78 {
79 operation: Schema.Literals(["readHistory", "sampleNow"]),79 operation: Schema.Literals(["readHistory", "sampleNow"]),
...@@ -131,7 +131,7 @@ export class NativeTelemetryExited extends Schema.TaggedErrorClass<NativeTelemet...@@ -131,7 +131,7 @@ export class NativeTelemetryExited extends Schema.TaggedErrorClass<NativeTelemet
131 }131 }
132}132}
133133
134export class NativeTelemetryStreamClosed extends Schema.TaggedErrorClass<NativeTelemetryStreamClosed>()(134class NativeTelemetryStreamClosed extends Schema.TaggedErrorClass<NativeTelemetryStreamClosed>()(
135 "NativeTelemetryStreamClosed",135 "NativeTelemetryStreamClosed",
136 {},136 {},
137) {137) {
...@@ -340,10 +340,6 @@ function errorMessage(error: NativeTelemetryClientError): string {...@@ -340,10 +340,6 @@ function errorMessage(error: NativeTelemetryClientError): string {
340 return error.message;340 return error.message;
341}341}
342342
343export function nativeTelemetrySupervisorFailureMessage(_cause: Cause.Cause<unknown>): string {
344 return "Resource monitor supervisor stopped unexpectedly.";
345}
346
347export function canRequestNativeTelemetryRetry(343export function canRequestNativeTelemetryRetry(
348 status: ResourceTelemetrySourceStatus,344 status: ResourceTelemetrySourceStatus,
349 hasHandle: boolean,345 hasHandle: boolean,
...@@ -734,7 +730,7 @@ export const make = Effect.fn("resourceTelemetry.nativeTelemetryClient.make")(fu...@@ -734,7 +730,7 @@ export const make = Effect.fn("resourceTelemetry.nativeTelemetryClient.make")(fu
734 ...current,730 ...current,
735 status: "unavailable" as const,731 status: "unavailable" as const,
736 hello: Option.none(),732 hello: Option.none(),
737 lastError: Option.some(nativeTelemetrySupervisorFailureMessage(cause)),733 lastError: Option.some("Resource monitor supervisor stopped unexpectedly."),
738 })).pipe(734 })).pipe(
739 Effect.andThen(publishHealth),735 Effect.andThen(publishHealth),
740 Effect.andThen(736 Effect.andThen(