feat(gateway): add observability sources, series, and service log RPCs

This commit is contained in:
William Valentin
2026-02-22 20:54:37 -08:00
parent cbc880c12a
commit ca463d5ca2
5 changed files with 1403 additions and 0 deletions
+18
View File
@@ -36,6 +36,7 @@ import { discoverServices } from './handlers/services.js';
import { createModelCatalogFetcher } from './modelCatalog.js';
import { listLocalBackendStatuses, controlLocalBackend } from './handlers/localBackends.js';
import { listDockerDependencyStatuses, controlDockerDependency } from './handlers/dockerDependencies.js';
import { ObservabilityCollector } from './handlers/observability.js';
import type { TokenUsageEntry, ContextUsageEntry } from './handlers/system.js';
import type { NodeConnectionState } from './handlers/node.js';
import type { SessionManager } from '../session/manager.js';
@@ -172,6 +173,7 @@ export class GatewayServer {
private canvasStore: CanvasStore;
private metrics: MetricsCollector;
private discoveryHandle: GatewayDiscoveryHandle | null = null;
private observabilityCollector: ObservabilityCollector | null = null;
private connectionMap: Map<WebSocket, string> = new Map();
private connectionRateMap: Map<string, {
tokens: number;
@@ -209,6 +211,10 @@ export class GatewayServer {
private registerHandlers(): void {
const channelRegistry = this.config.channelRegistry;
const runtimeConfig = this.config.config;
this.observabilityCollector = runtimeConfig
? new ObservabilityCollector({ config: runtimeConfig })
: null;
const observabilityCollector = this.observabilityCollector;
const modelCatalogFetcher = runtimeConfig ? createModelCatalogFetcher(runtimeConfig) : undefined;
const systemHandlers = createSystemHandlers({
startTime: this.startTime,
@@ -244,6 +250,15 @@ export class GatewayServer {
controlDockerDependency: runtimeConfig
? (dependency, action) => controlDockerDependency(runtimeConfig, dependency, action)
: undefined,
getObservabilitySources: observabilityCollector
? () => observabilityCollector.listSources()
: undefined,
getObservabilitySeries: observabilityCollector
? (opts) => observabilityCollector.getSeries(opts)
: undefined,
getServiceLogs: observabilityCollector
? (opts) => observabilityCollector.getServiceLogs(opts)
: undefined,
getPresence: channelRegistry
? (opts) => channelRegistry.getPresence(opts)
: undefined,
@@ -547,6 +562,7 @@ export class GatewayServer {
const { port } = this.config;
return new Promise((resolve) => {
this.observabilityCollector?.start();
// Create HTTP server first — handles static file requests
this.httpServer = createServer((req: IncomingMessage, res: ServerResponse) => {
this.handleHttpRequest(req, res);
@@ -584,6 +600,8 @@ export class GatewayServer {
}
async stop(): Promise<void> {
this.observabilityCollector?.stop();
if (this.discoveryHandle) {
try {
await this.discoveryHandle.stop();