//! The shared per-node telemetry emitter. //! //! Both the generic `swactor` node and the pipeline-parallel GPU worker emit //! the same datastream through this one type. A caller extracts only the few //! node-specific values each tick (SWIM members, runtime counts, relay flags) //! and hands them in via [`TickInput`]; the emitter owns the mux, the host/CPU //! sampler, and the membership differ, and ships every assembled [`Frame`] //! through a pluggable [`FrameSink`]. //! //! The emitter is transport-agnostic: it never depends on iroh. A node ships //! over the swactor cluster ([`ClusterFrameSink`]); a raw demo or test ships //! over UDP or collects in memory. Swapping the sink does not change a byte of //! emission logic. use std::sync::Arc; use std::sync::OnceLock; use swactor::actor::ActorAddress; use swactor::process_observer::ProcessOutputObserver; use swactor::runtime::Runtime; use super::catalog::{ self, ActorRuntimeDetail, DatastoreState, DistributionState, IdentityRecord, ProcStream, Record, RuntimeStats, TransportInternals, }; use super::frame::{Frame, Lifetime, NodeId, StreamId}; use super::mux::Mux; use super::source::{self, CpuSampler, MembershipTracker}; use super::wire::{encode_delivery, DatastreamFrame}; /// Where assembled frames go once the mux has ordered them. A sink is the only /// place transport lives; the emitter knows nothing about it. pub trait FrameSink: Send { /// Ship one ordered frame for `stream`. Best-effort: a sink may drop. fn ship(&mut self, stream: &StreamId, frame: &Frame); } /// Static identity a node needs to build its emitter. pub struct EmitterConfig { pub node_hex: String, pub life: u64, pub mux_capacity: usize, } /// The node-specific values a caller extracts each tick. Everything else the /// emitter samples itself. pub struct TickInput<'a> { /// `(node_id, swim_state)` for every known peer, keyed by stable id. pub members: &'a [(String, String)], /// Actor-runtime metrics this tick. pub runtime: RuntimeStats, pub relay_connected: bool, pub relay_peers: u32, } /// Forwards managed-process output into a node's mux as `proc.