feat: add native resource telemetry
Replace scheduled process shell probes with a persistent native collector, Electron power/process telemetry, Effect services, diagnostics UI, attribution, and release packaging. Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
79ad071184
commit
dbd8a8e09c
62 files changed
+7749
-1965
No files matched your search
@@ -171,6 +171,18 @@ export interface WsRpcClient {
|
||||
readonly getProcessResourceHistory: RpcUnaryMethod<
|
||||
typeof WS_METHODS.serverGetProcessResourceHistory
|
||||
>;
|
||||
readonly getResourceTelemetry: RpcUnaryNoArgMethod<
|
||||
typeof WS_METHODS.serverGetResourceTelemetry
|
||||
>;
|
||||
readonly getResourceTelemetryHistory: RpcUnaryMethod<
|
||||
typeof WS_METHODS.serverGetResourceTelemetryHistory
|
||||
>;
|
||||
readonly retryResourceTelemetry: RpcUnaryNoArgMethod<
|
||||
typeof WS_METHODS.serverRetryResourceTelemetry
|
||||
>;
|
||||
readonly subscribeResourceTelemetry: RpcStreamMethod<
|
||||
typeof WS_METHODS.subscribeResourceTelemetry
|
||||
>;
|
||||
readonly signalProcess: RpcUnaryMethod<typeof WS_METHODS.serverSignalProcess>;
|
||||
readonly reportClientActivity: RpcUnaryMethod<typeof WS_METHODS.serverReportClientActivity>;
|
||||
readonly reportHostPowerState: RpcUnaryMethod<typeof WS_METHODS.serverReportHostPowerState>;
|
||||
@@ -395,6 +407,18 @@ export function createWsRpcClient(
|
||||
transport.request((client) => client[WS_METHODS.serverGetProcessDiagnostics]({})),
|
||||
getProcessResourceHistory: (input) =>
|
||||
transport.request((client) => client[WS_METHODS.serverGetProcessResourceHistory](input)),
|
||||
getResourceTelemetry: () =>
|
||||
transport.request((client) => client[WS_METHODS.serverGetResourceTelemetry]({})),
|
||||
getResourceTelemetryHistory: (input) =>
|
||||
transport.request((client) => client[WS_METHODS.serverGetResourceTelemetryHistory](input)),
|
||||
retryResourceTelemetry: () =>
|
||||
transport.request((client) => client[WS_METHODS.serverRetryResourceTelemetry]({})),
|
||||
subscribeResourceTelemetry: (listener, options) =>
|
||||
transport.subscribe(
|
||||
(client) => client[WS_METHODS.subscribeResourceTelemetry]({}),
|
||||
listener,
|
||||
subscriptionOptions(options, WS_METHODS.subscribeResourceTelemetry),
|
||||
),
|
||||
signalProcess: (input) =>
|
||||
transport.request((client) => client[WS_METHODS.serverSignalProcess](input)),
|
||||
reportClientActivity: (input) =>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import { PortSchema } from "./baseSchemas.ts";
|
||||
import { PortSchema, PositiveInt, TrimmedNonEmptyString } from "./baseSchemas.ts";
|
||||
|
||||
export const DesktopBackendBootstrap = Schema.Struct({
|
||||
mode: Schema.Literal("desktop"),
|
||||
@@ -13,6 +13,8 @@ export const DesktopBackendBootstrap = Schema.Struct({
|
||||
tailscaleServePort: PortSchema,
|
||||
otlpTracesUrl: Schema.optional(Schema.String),
|
||||
otlpMetricsUrl: Schema.optional(Schema.String),
|
||||
desktopTelemetryFd: Schema.optionalKey(PositiveInt),
|
||||
resourceMonitorPath: Schema.optionalKey(TrimmedNonEmptyString),
|
||||
});
|
||||
|
||||
export type DesktopBackendBootstrap = typeof DesktopBackendBootstrap.Type;
|
||||
@@ -26,4 +26,5 @@ export * from "./assets.ts";
|
||||
export * from "./review.ts";
|
||||
export * from "./preview.ts";
|
||||
export * from "./previewAutomation.ts";
|
||||
export * from "./resourceTelemetry.ts";
|
||||
export * from "./rpc.ts";
|
||||
@@ -32,6 +32,12 @@ import type {
|
||||
ProjectWriteFileResult,
|
||||
} from "./project.ts";
|
||||
import type { ProviderInstanceId } from "./providerInstance.ts";
|
||||
import type {
|
||||
ResourceTelemetryHistory,
|
||||
ResourceTelemetryHistoryInput,
|
||||
ResourceTelemetryRetryResult,
|
||||
ResourceTelemetrySnapshot,
|
||||
} from "./resourceTelemetry.ts";
|
||||
import type {
|
||||
ServerConfig,
|
||||
ServerProcessDiagnosticsResult,
|
||||
@@ -1078,6 +1084,11 @@ export interface LocalApi {
|
||||
getProcessResourceHistory: (
|
||||
input: ServerProcessResourceHistoryInput,
|
||||
) => Promise<ServerProcessResourceHistoryResult>;
|
||||
getResourceTelemetry: () => Promise<ResourceTelemetrySnapshot>;
|
||||
getResourceTelemetryHistory: (
|
||||
input: ResourceTelemetryHistoryInput,
|
||||
) => Promise<ResourceTelemetryHistory>;
|
||||
retryResourceTelemetry: () => Promise<ResourceTelemetryRetryResult>;
|
||||
signalProcess: (input: ServerSignalProcessInput) => Promise<ServerSignalProcessResult>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,365 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import { NonNegativeInt, PositiveInt, TrimmedNonEmptyString } from "./baseSchemas.ts";
|
||||
import { HostPowerSnapshot } from "./background.ts";
|
||||
|
||||
export const RESOURCE_MONITOR_PROTOCOL_VERSION = 1 as const;
|
||||
|
||||
export const ResourceTelemetryIoSemantics = Schema.Literals([
|
||||
"storage",
|
||||
"logical",
|
||||
"all-io",
|
||||
"unavailable",
|
||||
]);
|
||||
export type ResourceTelemetryIoSemantics = typeof ResourceTelemetryIoSemantics.Type;
|
||||
|
||||
export const ResourceTelemetryProcessCategory = Schema.Literals([
|
||||
"server",
|
||||
"server-child",
|
||||
"provider-root",
|
||||
"terminal-root",
|
||||
"electron-main",
|
||||
"electron-renderer",
|
||||
"electron-gpu",
|
||||
"electron-utility",
|
||||
"resource-monitor",
|
||||
"unknown-t3",
|
||||
]);
|
||||
export type ResourceTelemetryProcessCategory = typeof ResourceTelemetryProcessCategory.Type;
|
||||
|
||||
export const ResourceTelemetrySourceStatus = Schema.Literals([
|
||||
"starting",
|
||||
"healthy",
|
||||
"degraded",
|
||||
"unavailable",
|
||||
"stopped",
|
||||
]);
|
||||
export type ResourceTelemetrySourceStatus = typeof ResourceTelemetrySourceStatus.Type;
|
||||
|
||||
export const ResourceTelemetryProcessIdentity = Schema.Struct({
|
||||
pid: PositiveInt,
|
||||
startTimeMs: NonNegativeInt,
|
||||
});
|
||||
export type ResourceTelemetryProcessIdentity = typeof ResourceTelemetryProcessIdentity.Type;
|
||||
|
||||
export const ResourceMonitorExternalProcess = Schema.Struct({
|
||||
pid: PositiveInt,
|
||||
startTimeMs: Schema.optionalKey(NonNegativeInt),
|
||||
});
|
||||
export type ResourceMonitorExternalProcess = typeof ResourceMonitorExternalProcess.Type;
|
||||
|
||||
export const ResourceMonitorCapabilities = Schema.Struct({
|
||||
cumulativeCpuTime: Schema.Boolean,
|
||||
currentCpuPercent: Schema.Boolean,
|
||||
residentMemory: Schema.Boolean,
|
||||
virtualMemory: Schema.Boolean,
|
||||
ioBytes: Schema.Boolean,
|
||||
processStartTime: Schema.Boolean,
|
||||
processTree: Schema.Boolean,
|
||||
});
|
||||
export type ResourceMonitorCapabilities = typeof ResourceMonitorCapabilities.Type;
|
||||
|
||||
export const ResourceMonitorProcessSample = Schema.Struct({
|
||||
pid: PositiveInt,
|
||||
ppid: NonNegativeInt,
|
||||
startTimeMs: NonNegativeInt,
|
||||
runTimeMs: NonNegativeInt,
|
||||
name: Schema.String,
|
||||
command: Schema.String,
|
||||
status: Schema.String,
|
||||
cpuPercent: Schema.Number,
|
||||
cpuTimeMs: NonNegativeInt,
|
||||
residentBytes: NonNegativeInt,
|
||||
virtualBytes: NonNegativeInt,
|
||||
ioReadBytes: NonNegativeInt,
|
||||
ioWriteBytes: NonNegativeInt,
|
||||
ioSemantics: Schema.Literals(["storage", "all-io"]),
|
||||
});
|
||||
export type ResourceMonitorProcessSample = typeof ResourceMonitorProcessSample.Type;
|
||||
|
||||
export const ResourceMonitorConfigureCommand = Schema.Struct({
|
||||
version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
|
||||
type: Schema.Literal("configure"),
|
||||
rootPid: PositiveInt,
|
||||
sampleIntervalMs: NonNegativeInt,
|
||||
externalProcesses: Schema.Array(ResourceMonitorExternalProcess),
|
||||
});
|
||||
export type ResourceMonitorConfigureCommand = typeof ResourceMonitorConfigureCommand.Type;
|
||||
|
||||
export const ResourceMonitorSetExternalProcessesCommand = Schema.Struct({
|
||||
version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
|
||||
type: Schema.Literal("setExternalProcesses"),
|
||||
processes: Schema.Array(ResourceMonitorExternalProcess),
|
||||
});
|
||||
export type ResourceMonitorSetExternalProcessesCommand =
|
||||
typeof ResourceMonitorSetExternalProcessesCommand.Type;
|
||||
|
||||
export const ResourceMonitorSampleNowCommand = Schema.Struct({
|
||||
version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
|
||||
type: Schema.Literal("sampleNow"),
|
||||
requestId: TrimmedNonEmptyString,
|
||||
});
|
||||
export type ResourceMonitorSampleNowCommand = typeof ResourceMonitorSampleNowCommand.Type;
|
||||
|
||||
export const ResourceMonitorShutdownCommand = Schema.Struct({
|
||||
version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
|
||||
type: Schema.Literal("shutdown"),
|
||||
});
|
||||
export type ResourceMonitorShutdownCommand = typeof ResourceMonitorShutdownCommand.Type;
|
||||
|
||||
export const ResourceMonitorCommand = Schema.Union([
|
||||
ResourceMonitorConfigureCommand,
|
||||
ResourceMonitorSetExternalProcessesCommand,
|
||||
ResourceMonitorSampleNowCommand,
|
||||
ResourceMonitorShutdownCommand,
|
||||
]);
|
||||
export type ResourceMonitorCommand = typeof ResourceMonitorCommand.Type;
|
||||
|
||||
export const ResourceMonitorHelloEvent = Schema.Struct({
|
||||
version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
|
||||
type: Schema.Literal("hello"),
|
||||
sidecarVersion: TrimmedNonEmptyString,
|
||||
sidecarPid: PositiveInt,
|
||||
platform: TrimmedNonEmptyString,
|
||||
arch: TrimmedNonEmptyString,
|
||||
capabilities: ResourceMonitorCapabilities,
|
||||
});
|
||||
export type ResourceMonitorHelloEvent = typeof ResourceMonitorHelloEvent.Type;
|
||||
|
||||
export const ResourceMonitorSnapshotEvent = Schema.Struct({
|
||||
version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
|
||||
type: Schema.Literal("snapshot"),
|
||||
sequence: NonNegativeInt,
|
||||
sampledAtUnixMs: NonNegativeInt,
|
||||
collectionDurationMicros: NonNegativeInt,
|
||||
scannedProcessCount: NonNegativeInt,
|
||||
retainedProcessCount: NonNegativeInt,
|
||||
inaccessibleProcessCount: NonNegativeInt,
|
||||
requestId: Schema.optionalKey(TrimmedNonEmptyString),
|
||||
processes: Schema.Array(ResourceMonitorProcessSample),
|
||||
});
|
||||
export type ResourceMonitorSnapshotEvent = typeof ResourceMonitorSnapshotEvent.Type;
|
||||
|
||||
export const ResourceMonitorErrorEvent = Schema.Struct({
|
||||
version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
|
||||
type: Schema.Literal("error"),
|
||||
code: TrimmedNonEmptyString,
|
||||
message: TrimmedNonEmptyString,
|
||||
recoverable: Schema.Boolean,
|
||||
});
|
||||
export type ResourceMonitorErrorEvent = typeof ResourceMonitorErrorEvent.Type;
|
||||
|
||||
export const ResourceMonitorEvent = Schema.Union([
|
||||
ResourceMonitorHelloEvent,
|
||||
ResourceMonitorSnapshotEvent,
|
||||
ResourceMonitorErrorEvent,
|
||||
]);
|
||||
export type ResourceMonitorEvent = typeof ResourceMonitorEvent.Type;
|
||||
|
||||
export const DesktopElectronProcessType = Schema.Literals([
|
||||
"Browser",
|
||||
"Tab",
|
||||
"Utility",
|
||||
"Zygote",
|
||||
"Sandbox helper",
|
||||
"GPU",
|
||||
"Pepper Plugin",
|
||||
"Pepper Plugin Broker",
|
||||
"Unknown",
|
||||
]);
|
||||
export type DesktopElectronProcessType = typeof DesktopElectronProcessType.Type;
|
||||
|
||||
export const DesktopElectronProcessMetric = Schema.Struct({
|
||||
pid: PositiveInt,
|
||||
creationTimeMs: NonNegativeInt,
|
||||
type: DesktopElectronProcessType,
|
||||
name: Schema.optionalKey(Schema.String),
|
||||
serviceName: Schema.optionalKey(Schema.String),
|
||||
cpuPercent: Schema.Number,
|
||||
cumulativeCpuSeconds: Schema.optionalKey(Schema.Number),
|
||||
idleWakeupsPerSecond: Schema.Number,
|
||||
workingSetBytes: NonNegativeInt,
|
||||
peakWorkingSetBytes: NonNegativeInt,
|
||||
});
|
||||
export type DesktopElectronProcessMetric = typeof DesktopElectronProcessMetric.Type;
|
||||
|
||||
export const DesktopHostTelemetrySnapshot = Schema.Struct({
|
||||
version: Schema.Literal(1),
|
||||
type: Schema.Literal("desktopTelemetry"),
|
||||
sequence: NonNegativeInt,
|
||||
sampledAtUnixMs: NonNegativeInt,
|
||||
power: HostPowerSnapshot,
|
||||
speedLimitPercent: Schema.Option(Schema.Number),
|
||||
electronProcesses: Schema.Array(DesktopElectronProcessMetric),
|
||||
});
|
||||
export type DesktopHostTelemetrySnapshot = typeof DesktopHostTelemetrySnapshot.Type;
|
||||
|
||||
export const DesktopHostTelemetryHello = Schema.Struct({
|
||||
version: Schema.Literal(1),
|
||||
type: Schema.Literal("desktopTelemetryHello"),
|
||||
electronPid: PositiveInt,
|
||||
});
|
||||
export type DesktopHostTelemetryHello = typeof DesktopHostTelemetryHello.Type;
|
||||
|
||||
export const DesktopHostTelemetryMessage = Schema.Union([
|
||||
DesktopHostTelemetryHello,
|
||||
DesktopHostTelemetrySnapshot,
|
||||
]);
|
||||
export type DesktopHostTelemetryMessage = typeof DesktopHostTelemetryMessage.Type;
|
||||
|
||||
export const ResourceTelemetryProcess = Schema.Struct({
|
||||
identity: ResourceTelemetryProcessIdentity,
|
||||
ppid: NonNegativeInt,
|
||||
childPids: Schema.Array(PositiveInt),
|
||||
depth: NonNegativeInt,
|
||||
name: Schema.String,
|
||||
command: Schema.String,
|
||||
status: Schema.String,
|
||||
category: ResourceTelemetryProcessCategory,
|
||||
electronType: Schema.optionalKey(DesktopElectronProcessType),
|
||||
electronServiceName: Schema.optionalKey(Schema.String),
|
||||
cpuPercent: Schema.Number,
|
||||
cpuTimeMs: NonNegativeInt,
|
||||
residentBytes: NonNegativeInt,
|
||||
peakResidentBytes: NonNegativeInt,
|
||||
virtualBytes: NonNegativeInt,
|
||||
ioReadBytes: NonNegativeInt,
|
||||
ioWriteBytes: NonNegativeInt,
|
||||
ioReadBytesPerSecond: Schema.Number,
|
||||
ioWriteBytesPerSecond: Schema.Number,
|
||||
ioSemantics: ResourceTelemetryIoSemantics,
|
||||
idleWakeupsPerSecond: Schema.optionalKey(Schema.Number),
|
||||
runTimeMs: NonNegativeInt,
|
||||
firstSeenAt: Schema.DateTimeUtc,
|
||||
lastSeenAt: Schema.DateTimeUtc,
|
||||
});
|
||||
export type ResourceTelemetryProcess = typeof ResourceTelemetryProcess.Type;
|
||||
|
||||
export const ResourceTelemetryAggregate = Schema.Struct({
|
||||
processCount: NonNegativeInt,
|
||||
currentCpuPercent: Schema.Number,
|
||||
cpuTimeMs: NonNegativeInt,
|
||||
currentRssBytes: NonNegativeInt,
|
||||
peakRssBytes: NonNegativeInt,
|
||||
ioReadBytes: NonNegativeInt,
|
||||
ioWriteBytes: NonNegativeInt,
|
||||
ioReadBytesPerSecond: Schema.Number,
|
||||
ioWriteBytesPerSecond: Schema.Number,
|
||||
processStarts: NonNegativeInt,
|
||||
processExits: NonNegativeInt,
|
||||
});
|
||||
export type ResourceTelemetryAggregate = typeof ResourceTelemetryAggregate.Type;
|
||||
|
||||
export const ResourceTelemetryGroups = Schema.Struct({
|
||||
backend: ResourceTelemetryAggregate,
|
||||
electron: ResourceTelemetryAggregate,
|
||||
monitor: ResourceTelemetryAggregate,
|
||||
allT3: ResourceTelemetryAggregate,
|
||||
});
|
||||
export type ResourceTelemetryGroups = typeof ResourceTelemetryGroups.Type;
|
||||
|
||||
export const ResourceTelemetrySourceHealth = Schema.Struct({
|
||||
status: ResourceTelemetrySourceStatus,
|
||||
lastSampleAt: Schema.Option(Schema.DateTimeUtc),
|
||||
lastError: Schema.Option(TrimmedNonEmptyString),
|
||||
});
|
||||
export type ResourceTelemetrySourceHealth = typeof ResourceTelemetrySourceHealth.Type;
|
||||
|
||||
export const ResourceTelemetryHealth = Schema.Struct({
|
||||
native: ResourceTelemetrySourceHealth,
|
||||
desktop: ResourceTelemetrySourceHealth,
|
||||
sidecarVersion: Schema.Option(TrimmedNonEmptyString),
|
||||
sidecarPid: Schema.Option(PositiveInt),
|
||||
restartCount: NonNegativeInt,
|
||||
collectionDurationMicros: NonNegativeInt,
|
||||
scannedProcessCount: NonNegativeInt,
|
||||
retainedProcessCount: NonNegativeInt,
|
||||
inaccessibleProcessCount: NonNegativeInt,
|
||||
});
|
||||
export type ResourceTelemetryHealth = typeof ResourceTelemetryHealth.Type;
|
||||
|
||||
export const ResourceAttributionEntry = Schema.Struct({
|
||||
component: TrimmedNonEmptyString,
|
||||
operation: TrimmedNonEmptyString,
|
||||
logicalReadBytes: NonNegativeInt,
|
||||
logicalWriteBytes: NonNegativeInt,
|
||||
count: NonNegativeInt,
|
||||
durationMs: NonNegativeInt,
|
||||
});
|
||||
export type ResourceAttributionEntry = typeof ResourceAttributionEntry.Type;
|
||||
|
||||
export const ResourceAttributionSnapshot = Schema.Struct({
|
||||
readAt: Schema.DateTimeUtc,
|
||||
entries: Schema.Array(ResourceAttributionEntry),
|
||||
});
|
||||
export type ResourceAttributionSnapshot = typeof ResourceAttributionSnapshot.Type;
|
||||
|
||||
export const ResourceTelemetrySnapshot = Schema.Struct({
|
||||
readAt: Schema.DateTimeUtc,
|
||||
sampleIntervalMs: NonNegativeInt,
|
||||
processes: Schema.Array(ResourceTelemetryProcess),
|
||||
groups: ResourceTelemetryGroups,
|
||||
power: HostPowerSnapshot,
|
||||
speedLimitPercent: Schema.Option(Schema.Number),
|
||||
attribution: ResourceAttributionSnapshot,
|
||||
health: ResourceTelemetryHealth,
|
||||
});
|
||||
export type ResourceTelemetrySnapshot = typeof ResourceTelemetrySnapshot.Type;
|
||||
|
||||
export const ResourceTelemetryHistoryInput = Schema.Struct({
|
||||
windowMs: NonNegativeInt,
|
||||
bucketMs: NonNegativeInt,
|
||||
});
|
||||
export type ResourceTelemetryHistoryInput = typeof ResourceTelemetryHistoryInput.Type;
|
||||
|
||||
export const ResourceTelemetryHistoryBucket = Schema.Struct({
|
||||
startedAt: Schema.DateTimeUtc,
|
||||
endedAt: Schema.DateTimeUtc,
|
||||
avgCpuPercent: Schema.Number,
|
||||
maxCpuPercent: Schema.Number,
|
||||
maxRssBytes: NonNegativeInt,
|
||||
ioReadBytes: NonNegativeInt,
|
||||
ioWriteBytes: NonNegativeInt,
|
||||
maxProcessCount: NonNegativeInt,
|
||||
});
|
||||
export type ResourceTelemetryHistoryBucket = typeof ResourceTelemetryHistoryBucket.Type;
|
||||
|
||||
export const ResourceTelemetryProcessSummary = Schema.Struct({
|
||||
identity: ResourceTelemetryProcessIdentity,
|
||||
ppid: NonNegativeInt,
|
||||
depth: NonNegativeInt,
|
||||
name: Schema.String,
|
||||
command: Schema.String,
|
||||
category: ResourceTelemetryProcessCategory,
|
||||
firstSeenAt: Schema.DateTimeUtc,
|
||||
lastSeenAt: Schema.DateTimeUtc,
|
||||
currentCpuPercent: Schema.Number,
|
||||
avgCpuPercent: Schema.Number,
|
||||
maxCpuPercent: Schema.Number,
|
||||
cpuTimeMs: NonNegativeInt,
|
||||
currentRssBytes: NonNegativeInt,
|
||||
peakRssBytes: NonNegativeInt,
|
||||
ioReadBytes: NonNegativeInt,
|
||||
ioWriteBytes: NonNegativeInt,
|
||||
ioSemantics: ResourceTelemetryIoSemantics,
|
||||
sampleCount: NonNegativeInt,
|
||||
});
|
||||
export type ResourceTelemetryProcessSummary = typeof ResourceTelemetryProcessSummary.Type;
|
||||
|
||||
export const ResourceTelemetryHistory = Schema.Struct({
|
||||
readAt: Schema.DateTimeUtc,
|
||||
windowMs: NonNegativeInt,
|
||||
bucketMs: NonNegativeInt,
|
||||
sampleIntervalMs: NonNegativeInt,
|
||||
retainedSampleCount: NonNegativeInt,
|
||||
buckets: Schema.Array(ResourceTelemetryHistoryBucket),
|
||||
topProcesses: Schema.Array(ResourceTelemetryProcessSummary),
|
||||
health: ResourceTelemetryHealth,
|
||||
});
|
||||
export type ResourceTelemetryHistory = typeof ResourceTelemetryHistory.Type;
|
||||
|
||||
export const ResourceTelemetryRetryResult = Schema.Struct({
|
||||
accepted: Schema.Boolean,
|
||||
snapshot: ResourceTelemetrySnapshot,
|
||||
});
|
||||
export type ResourceTelemetryRetryResult = typeof ResourceTelemetryRetryResult.Type;
|
||||
@@ -134,6 +134,12 @@ import {
|
||||
ServerUpsertKeybindingInput,
|
||||
ServerUpsertKeybindingResult,
|
||||
} from "./server.ts";
|
||||
import {
|
||||
ResourceTelemetryHistory,
|
||||
ResourceTelemetryHistoryInput,
|
||||
ResourceTelemetryRetryResult,
|
||||
ResourceTelemetrySnapshot,
|
||||
} from "./resourceTelemetry.ts";
|
||||
import { ServerSettings, ServerSettingsError, ServerSettingsPatch } from "./settings.ts";
|
||||
import {
|
||||
SourceControlCloneRepositoryInput,
|
||||
@@ -215,6 +221,9 @@ export const WS_METHODS = {
|
||||
serverGetTraceDiagnostics: "server.getTraceDiagnostics",
|
||||
serverGetProcessDiagnostics: "server.getProcessDiagnostics",
|
||||
serverGetProcessResourceHistory: "server.getProcessResourceHistory",
|
||||
serverGetResourceTelemetry: "server.getResourceTelemetry",
|
||||
serverGetResourceTelemetryHistory: "server.getResourceTelemetryHistory",
|
||||
serverRetryResourceTelemetry: "server.retryResourceTelemetry",
|
||||
serverSignalProcess: "server.signalProcess",
|
||||
serverReportClientActivity: "server.reportClientActivity",
|
||||
serverReportHostPowerState: "server.reportHostPowerState",
|
||||
@@ -239,6 +248,7 @@ export const WS_METHODS = {
|
||||
subscribeServerLifecycle: "subscribeServerLifecycle",
|
||||
subscribeAuthAccess: "subscribeAuthAccess",
|
||||
subscribeBackgroundPolicy: "subscribeBackgroundPolicy",
|
||||
subscribeResourceTelemetry: "subscribeResourceTelemetry",
|
||||
} as const;
|
||||
|
||||
export const WsServerUpsertKeybindingRpc = Rpc.make(WS_METHODS.serverUpsertKeybinding, {
|
||||
@@ -318,6 +328,27 @@ export const WsServerGetProcessResourceHistoryRpc = Rpc.make(
|
||||
},
|
||||
);
|
||||
|
||||
export const WsServerGetResourceTelemetryRpc = Rpc.make(WS_METHODS.serverGetResourceTelemetry, {
|
||||
payload: Schema.Struct({}),
|
||||
success: ResourceTelemetrySnapshot,
|
||||
error: EnvironmentAuthorizationError,
|
||||
});
|
||||
|
||||
export const WsServerGetResourceTelemetryHistoryRpc = Rpc.make(
|
||||
WS_METHODS.serverGetResourceTelemetryHistory,
|
||||
{
|
||||
payload: ResourceTelemetryHistoryInput,
|
||||
success: ResourceTelemetryHistory,
|
||||
error: EnvironmentAuthorizationError,
|
||||
},
|
||||
);
|
||||
|
||||
export const WsServerRetryResourceTelemetryRpc = Rpc.make(WS_METHODS.serverRetryResourceTelemetry, {
|
||||
payload: Schema.Struct({}),
|
||||
success: ResourceTelemetryRetryResult,
|
||||
error: EnvironmentAuthorizationError,
|
||||
});
|
||||
|
||||
export const WsServerSignalProcessRpc = Rpc.make(WS_METHODS.serverSignalProcess, {
|
||||
payload: ServerSignalProcessInput,
|
||||
success: ServerSignalProcessResult,
|
||||
@@ -710,6 +741,13 @@ export const WsSubscribeBackgroundPolicyRpc = Rpc.make(WS_METHODS.subscribeBackg
|
||||
stream: true,
|
||||
});
|
||||
|
||||
export const WsSubscribeResourceTelemetryRpc = Rpc.make(WS_METHODS.subscribeResourceTelemetry, {
|
||||
payload: Schema.Struct({}),
|
||||
success: ResourceTelemetrySnapshot,
|
||||
error: EnvironmentAuthorizationError,
|
||||
stream: true,
|
||||
});
|
||||
|
||||
export const WsRpcGroup = RpcGroup.make(
|
||||
WsServerGetConfigRpc,
|
||||
WsServerRefreshProvidersRpc,
|
||||
@@ -722,6 +760,9 @@ export const WsRpcGroup = RpcGroup.make(
|
||||
WsServerGetTraceDiagnosticsRpc,
|
||||
WsServerGetProcessDiagnosticsRpc,
|
||||
WsServerGetProcessResourceHistoryRpc,
|
||||
WsServerGetResourceTelemetryRpc,
|
||||
WsServerGetResourceTelemetryHistoryRpc,
|
||||
WsServerRetryResourceTelemetryRpc,
|
||||
WsServerSignalProcessRpc,
|
||||
WsServerReportClientActivityRpc,
|
||||
WsServerReportHostPowerStateRpc,
|
||||
@@ -776,6 +817,7 @@ export const WsRpcGroup = RpcGroup.make(
|
||||
WsSubscribeServerLifecycleRpc,
|
||||
WsSubscribeAuthAccessRpc,
|
||||
WsSubscribeBackgroundPolicyRpc,
|
||||
WsSubscribeResourceTelemetryRpc,
|
||||
WsOrchestrationDispatchCommandRpc,
|
||||
WsOrchestrationGetTurnDiffRpc,
|
||||
WsOrchestrationGetFullThreadDiffRpc,
|
||||
|
||||
@@ -302,6 +302,7 @@ export type ServerProcessSignal = typeof ServerProcessSignal.Type;
|
||||
|
||||
export const ServerProcessDiagnosticsEntry = Schema.Struct({
|
||||
pid: PositiveInt,
|
||||
startTimeMs: NonNegativeInt,
|
||||
ppid: NonNegativeInt,
|
||||
pgid: Schema.Option(Schema.Int),
|
||||
status: TrimmedNonEmptyString,
|
||||
@@ -383,6 +384,7 @@ export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHis
|
||||
|
||||
export const ServerSignalProcessInput = Schema.Struct({
|
||||
pid: PositiveInt,
|
||||
startTimeMs: NonNegativeInt,
|
||||
signal: ServerProcessSignal,
|
||||
});
|
||||
export type ServerSignalProcessInput = typeof ServerSignalProcessInput.Type;
|
||||
|
||||
@@ -8,6 +8,7 @@ import * as Layer from "effect/Layer";
|
||||
import * as Logger from "effect/Logger";
|
||||
import * as Order from "effect/Order";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as References from "effect/References";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Tracer from "effect/Tracer";
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
makeLocalFileTracer,
|
||||
makeTraceSink,
|
||||
type TraceRecord,
|
||||
type TraceSinkFlushStats,
|
||||
} from "./observability.ts";
|
||||
|
||||
describe("causeErrorTag", () => {
|
||||
@@ -167,6 +169,34 @@ describe("observability", () => {
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("reports successful logical trace writes", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const tempDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-trace-sink-" });
|
||||
const tracePath = path.join(tempDir, "shared.trace.ndjson");
|
||||
const reported = yield* Ref.make<ReadonlyArray<TraceSinkFlushStats>>([]);
|
||||
|
||||
const sink = yield* makeTraceSink({
|
||||
filePath: tracePath,
|
||||
maxBytes: 1024,
|
||||
maxFiles: 2,
|
||||
batchWindowMs: 10_000,
|
||||
onFlush: (stats) => Ref.update(reported, (current) => [...current, stats]),
|
||||
});
|
||||
|
||||
sink.push(makeRecord("attributed"));
|
||||
yield* sink.flush;
|
||||
|
||||
const stats = yield* Ref.get(reported);
|
||||
assert.equal(stats.length, 1);
|
||||
assert.equal(stats[0]?.count, 1);
|
||||
assert.isAbove(stats[0]?.logicalWriteBytes ?? 0, 0);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("rotates the trace file when the configured max size is exceeded", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
|
||||
@@ -9,6 +9,7 @@ import { OtlpResource, OtlpTracer } from "effect/unstable/observability";
|
||||
import { RotatingFileSink } from "./logging.ts";
|
||||
|
||||
const FLUSH_BUFFER_THRESHOLD = 32;
|
||||
const textEncoder = new TextEncoder();
|
||||
|
||||
export type TraceAttributes = Readonly<Record<string, unknown>>;
|
||||
|
||||
@@ -94,6 +95,13 @@ export interface TraceSinkOptions {
|
||||
readonly maxBytes: number;
|
||||
readonly maxFiles: number;
|
||||
readonly batchWindowMs: number;
|
||||
readonly onFlush?: (stats: TraceSinkFlushStats) => Effect.Effect<void>;
|
||||
}
|
||||
|
||||
export interface TraceSinkFlushStats {
|
||||
readonly logicalWriteBytes: number;
|
||||
readonly count: number;
|
||||
readonly durationMs: number;
|
||||
}
|
||||
|
||||
export interface TraceSink {
|
||||
@@ -263,23 +271,50 @@ export const makeTraceSink = Effect.fn("makeTraceSink")(function* (options: Trac
|
||||
});
|
||||
|
||||
let buffer: Array<string> = [];
|
||||
let pendingFlushStats: TraceSinkFlushStats = {
|
||||
logicalWriteBytes: 0,
|
||||
count: 0,
|
||||
durationMs: 0,
|
||||
};
|
||||
|
||||
const flushUnsafe = () => {
|
||||
if (buffer.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const chunk = buffer.join("");
|
||||
const records = buffer;
|
||||
const chunk = records.join("");
|
||||
buffer = [];
|
||||
const startedAt = performance.now();
|
||||
|
||||
try {
|
||||
sink.write(chunk);
|
||||
pendingFlushStats = {
|
||||
logicalWriteBytes:
|
||||
pendingFlushStats.logicalWriteBytes + textEncoder.encode(chunk).byteLength,
|
||||
count: pendingFlushStats.count + records.length,
|
||||
durationMs: pendingFlushStats.durationMs + Math.max(0, performance.now() - startedAt),
|
||||
};
|
||||
} catch {
|
||||
buffer.unshift(chunk);
|
||||
buffer.unshift(...records);
|
||||
}
|
||||
};
|
||||
|
||||
const flush = Effect.sync(flushUnsafe).pipe(Effect.withTracerEnabled(false));
|
||||
const flush = Effect.sync(() => {
|
||||
flushUnsafe();
|
||||
const stats = pendingFlushStats;
|
||||
pendingFlushStats = {
|
||||
logicalWriteBytes: 0,
|
||||
count: 0,
|
||||
durationMs: 0,
|
||||
};
|
||||
return stats;
|
||||
}).pipe(
|
||||
Effect.flatMap((stats) =>
|
||||
stats.count > 0 && options.onFlush ? options.onFlush(stats).pipe(Effect.ignore) : Effect.void,
|
||||
),
|
||||
Effect.withTracerEnabled(false),
|
||||
);
|
||||
|
||||
yield* Effect.addFinalizer(() => flush.pipe(Effect.ignore));
|
||||
yield* Effect.forkScoped(
|
||||
|
||||
Reference in new issue
Block a user