fix(relay): export tunnel cleanup counters to Axiom (#13528)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
46f3c2ca2c
commit
d23eab13d9
3 files changed
+68
-2
No files matched your search
@@ -4,6 +4,7 @@ import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Redacted from "effect/Redacted";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
import * as Tracer from "effect/Tracer";
|
||||
|
||||
import * as RelayConfiguration from "../Config.ts";
|
||||
import * as ManagedEndpointAllocations from "./ManagedEndpointAllocations.ts";
|
||||
@@ -574,6 +575,54 @@ describe("ManagedEndpointReaper", () => {
|
||||
}).pipe(Effect.provide(state.layer));
|
||||
});
|
||||
|
||||
it.effect("records dry-run counters on the sweep span", () => {
|
||||
const spans: Array<Tracer.NativeSpan> = [];
|
||||
const tracer = Tracer.make({
|
||||
span: (options) => {
|
||||
const span = new Tracer.NativeSpan(options);
|
||||
spans.push(span);
|
||||
return span;
|
||||
},
|
||||
});
|
||||
const expired = [
|
||||
tunnel({
|
||||
id: "recoverable",
|
||||
suffix: "aaaaaaaaaaaaaaaa",
|
||||
status: "down",
|
||||
timestamp: "2026-08-25T11:00:00.000Z",
|
||||
}),
|
||||
tunnel({
|
||||
id: "legacy",
|
||||
suffix: "bbbbbbbbbbbbbbbb",
|
||||
status: "down",
|
||||
timestamp: "2026-08-25T11:00:00.000Z",
|
||||
}),
|
||||
];
|
||||
const state = harness({
|
||||
cleanupMode: "dry-run",
|
||||
tunnels: expired,
|
||||
allocations: [
|
||||
allocation({ tunnelId: "recoverable", recoveryEnabled: true }),
|
||||
allocation({ tunnelId: "legacy", recoveryEnabled: false }),
|
||||
],
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
yield* TestClock.setTime(NOW_MILLIS);
|
||||
const reaper = yield* ManagedEndpointReaper.ManagedEndpointReaper;
|
||||
yield* reaper.sweep;
|
||||
const sweepSpan = spans.find((span) => span.name === "relay.managed_endpoint_reaper.sweep");
|
||||
expect(Object.fromEntries(sweepSpan?.attributes ?? [])).toMatchObject({
|
||||
"relay.managed_endpoint_reaper.mode": "dry-run",
|
||||
"relay.managed_endpoint_reaper.scanned": 2,
|
||||
"relay.managed_endpoint_reaper.wouldDelete": 1,
|
||||
"relay.managed_endpoint_reaper.skippedLegacy": 1,
|
||||
"relay.managed_endpoint_reaper.deleted": 0,
|
||||
});
|
||||
expect(state.deleted).toEqual([]);
|
||||
}).pipe(Effect.provide(state.layer), Effect.withTracer(tracer));
|
||||
});
|
||||
|
||||
it.effect("does no Cloudflare work while cleanup is off", () => {
|
||||
const state = harness({
|
||||
cleanupMode: "off",
|
||||
|
||||
@@ -287,7 +287,20 @@ export const make = Effect.gen(function* () {
|
||||
failed,
|
||||
truncated,
|
||||
};
|
||||
}).pipe(Effect.withSpan("relay.managed_endpoint_reaper.sweep"));
|
||||
}).pipe(
|
||||
// Dry-run rollout reads these counters from the exported span.
|
||||
Effect.tap((result) =>
|
||||
Effect.annotateCurrentSpan(
|
||||
Object.fromEntries(
|
||||
Object.entries(result).map(([key, value]) => [
|
||||
`relay.managed_endpoint_reaper.${key}`,
|
||||
value,
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
Effect.withSpan("relay.managed_endpoint_reaper.sweep"),
|
||||
);
|
||||
|
||||
return ManagedEndpointReaper.of({ sweep });
|
||||
});
|
||||
|
||||
@@ -358,7 +358,11 @@ export const ApiLive = Api.make(
|
||||
),
|
||||
],
|
||||
{ concurrency: 2, discard: true },
|
||||
).pipe(Effect.withSpan("relay.cron.prune_expired_state"), Effect.provide(runtimeLayer)),
|
||||
).pipe(
|
||||
Effect.withSpan("relay.cron.prune_expired_state"),
|
||||
// Export cron spans to Axiom like HTTP spans; the scope flushes them before the run ends.
|
||||
Effect.provide(Layer.merge(runtimeLayer, relayTraceLayer)),
|
||||
),
|
||||
);
|
||||
|
||||
const fetch = Layer.merge(
|
||||
|
||||
Reference in new issue
Block a user