/** * SloCollector, collects SLO duration measurements from runtime events. * * Listens to the RuntimeEventBus and tracks four critical path latencies: * - turn_start_ms: TURN_SUBMITTED → first STREAM_DELTA * - cancel_ms: TURN_CANCEL → TURN_COMPLETED or TURN_ERROR * - reconnect_recovery_ms: TRANSPORT_RECONNECTING → TRANSPORT_CONNECTED * - permission_decision_ms: PERMISSION_REQUESTED → DECISION_EMITTED * * Maintains a capped rolling window of measurements per SLO and exposes * p95 values for PerfMonitor integration via `getMetrics()`. */ import type { RuntimeEventBus } from '../events/index.js'; import type { PerfMetric } from './types.js'; /** Metric key constants for each SLO measurement. */ export declare const SLO_METRICS: { readonly TURN_START: "slo.turn_start.p95"; readonly CANCEL: "slo.cancel.p95"; readonly RECONNECT_RECOVERY: "slo.reconnect_recovery.p95"; readonly PERMISSION_DECISION: "slo.permission_decision.p95"; }; /** * SloCollector subscribes to RuntimeEventBus events and tracks per-SLO * duration samples in rolling windows. Call `getMetrics()` to retrieve * current p95 values for ComponentHealthMonitor extra metrics. * * @example * ```ts * const collector = new SloCollector(bus); * const metrics = collector.getMetrics(); * const report = monitor.evaluate({ uiPerf, extraMetrics: Object.fromEntries( * metrics.map(m => [m.name, m.value]) * )}); * collector.dispose(); * ``` */ export declare class SloCollector { /** Rolling window of turn_start_ms samples (TURN_SUBMITTED → first STREAM_DELTA). */ private readonly _turnStartSamples; /** Rolling window of cancel_ms samples (TURN_CANCEL → TURN_COMPLETED/ERROR). */ private readonly _cancelSamples; /** Rolling window of reconnect_recovery_ms samples (TRANSPORT_RECONNECTING → TRANSPORT_CONNECTED). */ private readonly _reconnectSamples; /** Rolling window of permission_decision_ms samples (PERMISSION_REQUESTED → DECISION_EMITTED). */ private readonly _permissionSamples; /** Pending turn start timestamps keyed by turnId. */ private readonly _pendingTurnStart; /** Tracks which turnIds have received their first STREAM_DELTA. */ private readonly _seenFirstDelta; /** Pending cancel timestamps keyed by turnId (set on TURN_CANCEL). */ private readonly _pendingCancel; /** Pending reconnect start timestamp. Only the most recent reconnect attempt is tracked. */ private _pendingReconnectAt; /** Pending permission request timestamps keyed by callId. */ private readonly _pendingPermission; /** Registered unsubscribe functions. */ private readonly _unsubs; /** Timer handle for the periodic stale-entry sweep. */ private _sweepTimer; constructor(bus: RuntimeEventBus); /** * Attach all event listeners to the bus. */ private _subscribe; /** * Sweep all pending maps and evict entries older than PENDING_TTL_MS. * * Called periodically by the sweep timer to prevent unbounded memory growth * when expected follow-up events (e.g. TURN_COMPLETED after TURN_CANCEL) * never arrive due to connection drops or unexpected process termination. */ private _sweepPending; /** * Returns current p95 values for all four SLO metrics as PerfMetric entries. * Metrics with no samples return a value of 0. * * Intended for use with `PerfMonitor.evaluate()` via the `extraMetrics` field: * ```ts * const extras = Object.fromEntries(collector.getMetrics().map(m => [m.name, m.value])); * monitor.evaluate({ uiPerf, extraMetrics: extras }); * ``` */ getMetrics(): PerfMetric[]; /** * Returns the number of samples collected for each SLO metric. * Useful for diagnostics to distinguish "no data yet" from an actual 0ms result. */ getSampleCounts(): Readonly>; /** * Unsubscribes all event listeners and releases resources. * The collector should not be used after disposal. */ dispose(): void; } //# sourceMappingURL=slo-collector.d.ts.map