refactor(server): classify telemetry exports (#10277)
This commit is contained in:
1 parent
161715b1e4
commit
77d9ffc822
16 files changed
+20
-12
No files matched your search
@@ -120,7 +120,7 @@ function rawDataBytes(data: NodeSocket.NodeWS.RawData): number {
|
||||
return data.byteLength;
|
||||
}
|
||||
|
||||
export function makeWebSocketTransferRecorder(): WebSocketTransferRecorder {
|
||||
function makeWebSocketTransferRecorder(): WebSocketTransferRecorder {
|
||||
let socket: NodeWebSocketWithTransport | null = null;
|
||||
// Held separately from the WebSocket so wire totals survive a close, which
|
||||
// is when a reconnect measurement reads them.
|
||||
@@ -176,7 +176,7 @@ export function transferDelta(
|
||||
};
|
||||
}
|
||||
|
||||
export function countingWsRpcProtocolLayer(input: {
|
||||
function countingWsRpcProtocolLayer(input: {
|
||||
readonly url: string;
|
||||
readonly cookie: string;
|
||||
readonly recorder: WebSocketTransferRecorder;
|
||||
@@ -194,7 +194,7 @@ export function countingWsRpcProtocolLayer(input: {
|
||||
);
|
||||
}
|
||||
|
||||
export const makeCountingWsRpcClient = RpcClient.make(WsRpcGroup);
|
||||
const makeCountingWsRpcClient = RpcClient.make(WsRpcGroup);
|
||||
export type CountingWsRpcClient = Effect.Success<typeof makeCountingWsRpcClient>;
|
||||
|
||||
export interface MeasuredWsClient {
|
||||
|
||||
@@ -56,7 +56,7 @@ const TRANSFER_BUDGET = {
|
||||
measuredTurnWebSocketMessages: 21,
|
||||
} satisfies ProviderTransferBudget;
|
||||
|
||||
export const TRANSFER_BUDGETS: Readonly<Record<string, ProviderTransferBudget>> = {
|
||||
const TRANSFER_BUDGETS: Readonly<Record<string, ProviderTransferBudget>> = {
|
||||
codex: TRANSFER_BUDGET,
|
||||
claudeAgent: TRANSFER_BUDGET,
|
||||
};
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
TRANSFER_HISTORY_TURN_COUNT,
|
||||
} from "./fixtures/transferBudget.ts";
|
||||
|
||||
export const TRANSFER_PROJECT_ID = ProjectId.make("transfer-budget-project");
|
||||
const TRANSFER_PROJECT_ID = ProjectId.make("transfer-budget-project");
|
||||
export const TRANSFER_THREAD_ID = ThreadId.make("transfer-budget-thread");
|
||||
export const TRANSFER_MEASURED_TURN_INDEX = TRANSFER_HISTORY_TURN_COUNT;
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ function canSignalCategory(category: ResourceTelemetryProcessCategory): boolean
|
||||
);
|
||||
}
|
||||
|
||||
/** @public Service construction is part of the canonical Effect module API. */
|
||||
export const make = Effect.fn("makeProcessDiagnostics")(function* () {
|
||||
const telemetry = yield* ResourceTelemetry.ResourceTelemetry;
|
||||
const refreshedTelemetry = telemetry.refresh.pipe(Effect.catch(() => telemetry.latest));
|
||||
|
||||
@@ -28,6 +28,7 @@ function isLegacyBackendCategory(category: ResourceTelemetryProcessCategory): bo
|
||||
);
|
||||
}
|
||||
|
||||
/** @public Service construction is part of the canonical Effect module API. */
|
||||
export const make = Effect.fn("makeProcessResourceMonitor")(function* () {
|
||||
const telemetry = yield* ResourceTelemetry.ResourceTelemetry;
|
||||
const readHistory: ProcessResourceMonitor["Service"]["readHistory"] = (input) =>
|
||||
|
||||
@@ -411,6 +411,7 @@ function readTraceFile(
|
||||
);
|
||||
}
|
||||
|
||||
/** @public Service construction is part of the canonical Effect module API. */
|
||||
export const make = Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
|
||||
|
||||
@@ -327,6 +327,7 @@ export function requireDesktopTelemetryWriteProgress(
|
||||
: Effect.fail(new DesktopTelemetryControlStalled({ fd, remainingBytes }));
|
||||
}
|
||||
|
||||
/** @public Service construction is part of the canonical Effect module API. */
|
||||
export const make = Effect.fn("resourceTelemetry.desktopTelemetryReceiver.make")(function* () {
|
||||
const config = yield* ServerConfig;
|
||||
const serverSettings = yield* ServerSettingsService;
|
||||
|
||||
@@ -68,7 +68,7 @@ export interface MergeProcessesResult {
|
||||
readonly deltas: ReadonlyArray<ProcessDelta>;
|
||||
}
|
||||
|
||||
export const emptyGroupCounters = (): GroupCounters => ({
|
||||
const emptyGroupCounters = (): GroupCounters => ({
|
||||
cpuTimeMs: 0,
|
||||
ioReadBytes: 0,
|
||||
ioWriteBytes: 0,
|
||||
|
||||
@@ -360,6 +360,7 @@ export function canCommandNativeTelemetrySidecar(
|
||||
return hasHandle && (status === "healthy" || status === "degraded");
|
||||
}
|
||||
|
||||
/** @public Service construction is part of the canonical Effect module API. */
|
||||
export const make = Effect.fn("resourceTelemetry.nativeTelemetryClient.make")(function* () {
|
||||
const binary = yield* ResourceMonitorBinary.ResourceMonitorBinary;
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
|
||||
@@ -90,7 +90,7 @@ export const ResourceMonitorHostLinuxLibc = Context.Reference<ResourceMonitorLin
|
||||
},
|
||||
);
|
||||
|
||||
export function resourceMonitorPlatformKey(
|
||||
function resourceMonitorPlatformKey(
|
||||
platform: NodeJS.Platform,
|
||||
architecture: NodeJS.Architecture,
|
||||
): string | undefined {
|
||||
@@ -103,7 +103,7 @@ export function resourceMonitorPlatformKey(
|
||||
return `${platform}-${architecture}`;
|
||||
}
|
||||
|
||||
export function resourceMonitorRustTarget(
|
||||
function resourceMonitorRustTarget(
|
||||
platform: NodeJS.Platform,
|
||||
architecture: NodeJS.Architecture,
|
||||
linuxLibc?: ResourceMonitorLinuxLibc,
|
||||
|
||||
@@ -142,6 +142,7 @@ function buildHealth(input: {
|
||||
};
|
||||
}
|
||||
|
||||
/** @public Service construction is part of the canonical Effect module API. */
|
||||
export const make = Effect.fn("resourceTelemetry.resourceTelemetry.make")(function* () {
|
||||
const nativeClient = yield* NativeTelemetryClient.NativeTelemetryClient;
|
||||
const desktopReceiver = yield* DesktopTelemetryReceiver.DesktopTelemetryReceiver;
|
||||
|
||||
@@ -67,7 +67,7 @@ export class AnalyticsService extends Context.Service<
|
||||
);
|
||||
}
|
||||
|
||||
export function serverOsFromNodePlatform(platform: string): ClientOs {
|
||||
function serverOsFromNodePlatform(platform: string): ClientOs {
|
||||
switch (platform) {
|
||||
case "darwin":
|
||||
return "macOS";
|
||||
@@ -82,6 +82,7 @@ export function serverOsFromNodePlatform(platform: string): ClientOs {
|
||||
}
|
||||
}
|
||||
|
||||
/** @public Service construction is part of the canonical Effect module API. */
|
||||
export const make = Effect.gen(function* () {
|
||||
const telemetryConfig = yield* TelemetryEnvConfig;
|
||||
const httpClient = yield* HttpClient.HttpClient;
|
||||
|
||||
@@ -60,6 +60,7 @@ function sourceLabel(id: string, config: UsageLimitSourceConfig): string {
|
||||
}
|
||||
}
|
||||
|
||||
/** @public Service construction is part of the canonical Effect module API. */
|
||||
export const make = Effect.gen(function* () {
|
||||
const api = yield* makeCliproxyApi;
|
||||
const settingsService = yield* ServerSettingsService;
|
||||
|
||||
@@ -23,7 +23,7 @@ import { cacheSavingsUsd, priceUsage, type RateTable } from "./usagePricing.ts";
|
||||
* `en-CA` yields ISO-ordered parts, which is why it is used here rather than
|
||||
* assembling the day from `Date` getters (those are host-local only).
|
||||
*/
|
||||
export function makeDayFormatter(timeZone: string): (timestampMs: number) => string {
|
||||
function makeDayFormatter(timeZone: string): (timestampMs: number) => string {
|
||||
let format: Intl.DateTimeFormat;
|
||||
try {
|
||||
format = new Intl.DateTimeFormat("en-CA", {
|
||||
|
||||
@@ -26,7 +26,7 @@ import type { CodexScanState, UsageRecord } from "./usageTranscripts.ts";
|
||||
// entries would keep serving double-counted records forever.
|
||||
// v3: entries carry the parse position and reducer state so a grown file
|
||||
// re-parses only its appended bytes instead of starting over.
|
||||
export const USAGE_SCAN_CACHE_VERSION = 3 as const;
|
||||
const USAGE_SCAN_CACHE_VERSION = 3 as const;
|
||||
|
||||
export interface CachedFile {
|
||||
readonly size: number;
|
||||
|
||||
@@ -79,7 +79,7 @@ export function mightCarryUsage(line: string, provider: UsageProviderKind): bool
|
||||
*/
|
||||
export const GROK_COST_USD_TICKS_PER_DOLLAR = 10_000_000_000;
|
||||
|
||||
export function grokCostTicksToUsd(ticks: unknown): number | null {
|
||||
function grokCostTicksToUsd(ticks: unknown): number | null {
|
||||
if (typeof ticks !== "number" || !Number.isFinite(ticks) || ticks < 0) return null;
|
||||
return ticks / GROK_COST_USD_TICKS_PER_DOLLAR;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user