swactor/apps/myelin/src/observability/provisioning_logs.rs

118 lines
3.5 KiB
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
use serde_json::Value;
use telemetry::{ChannelContent, Lifetime, NodeId, StreamId, TelemetryProducer};
use crate::observability::telemetry::{
MYELIN_PROVISIONING_LOGS, MyelinProvisionLogRecord, myelin_provision_log_channel,
};
refactor: prune public api Collapse mvp-system's public surface to three binary entrypoints and make every domain module private, deleting dead provider/worker/membership implementations and inlining provider config. - lib.rs: expose only run_chat_from_args/run_orchestrator_from_args/run_worker_node_from_env (plus a crate-private in-process helper) and the cached-model consts, and demote chat/node/observability/orchestration/prompt/staging/transport to private mods - orchestration/mod.rs: make app private, gate engine_builder behind cfg(test), drop docker_cluster from provider_adapters, tighten vastai to pub(super), and replace pub re-exports with pub(super) run_from_args/run_in_process_from_args - orchestration/config.rs: inline VastAiConfig/ResolvedVastAiConfig/looks_remote_image (removing provider_adapters/vastai/config.rs) and drop the DEFAULT_PIPELINE_CACHED_MODEL_* consts (hoisted to lib.rs) - orchestration/provider_adapters/vastai: delete the ProviderPlugin impl VastAiProviderPlugin and all client/bootstrap/config accessors; repoint call sites to crate-level #[path] mods for provisioning/node_provisioning/node_actor/gguf_shard/run_fsm/run_plan - delete orchestration/{membership_readiness,token_endpoint,resource_inventory}, node/{boot_lifecycle,data_plane_bridge(-74)}, and the worker crate-internal modules (control/device_bridge/process_adapter) along with their guarantees tests - chat/node: narrow node_image and worker_node_runtime to private and expose only pub(super) run_from_args / run_worker_node_from_env Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-07-29 10:02:50 +00:00
use crate::provisioning::{
NodeProvisionSpec, PluginObservation, PluginSink, ProvisionLogLine, ProvisionLogStream,
};
pub(crate) fn node_stream_id(run_id: u64, node_id: u64) -> StreamId {
StreamId::new(NodeId::new(node_id.to_string()), Lifetime(run_id))
}
#[derive(Clone)]
pub(crate) struct BootstrapTelemetryBridge {
spec: NodeProvisionSpec,
sink: PluginSink,
producer: Option<TelemetryProducer>,
}
impl BootstrapTelemetryBridge {
pub(crate) fn new(
spec: NodeProvisionSpec,
sink: PluginSink,
producer: Option<TelemetryProducer>,
) -> Self {
Self {
spec,
sink,
producer,
}
}
pub(crate) fn spec(&self) -> &NodeProvisionSpec {
&self.spec
}
pub(crate) fn observe_stdout_line(&self, line: impl Into<String>) {
let line = line.into();
if let Some(frame) = parse_stdio_telemetry_frame(&self.spec, &line) {
self.sink.observe(frame);
return;
}
self.submit_log(ProvisionLogStream::Stdout, &line);
self.sink.observe(PluginObservation::StdoutLine {
run_id: self.spec.run_id,
node_id: self.spec.node_id,
line: line.clone(),
});
}
pub(crate) fn observe_stderr_line(&self, line: impl Into<String>) {
let line = line.into();
self.submit_log(ProvisionLogStream::Stderr, &line);
self.sink.observe(PluginObservation::StderrLine {
run_id: self.spec.run_id,
node_id: self.spec.node_id,
line,
});
}
pub(crate) fn observe_provider_line(&self, line: impl Into<String>) {
let line = line.into();
self.submit_log(ProvisionLogStream::Provider, &line);
self.sink.observe(PluginObservation::ProviderLine {
run_id: self.spec.run_id,
node_id: self.spec.node_id,
line,
});
}
fn submit_log(&self, stream: ProvisionLogStream, line: &str) {
let Some(producer) = &self.producer else {
return;
};
let record = MyelinProvisionLogRecord::new(ProvisionLogLine {
run_id: self.spec.run_id,
node_id: self.spec.node_id,
stream,
line: line.to_owned(),
});
let channel = producer.register_channel(
myelin_provision_log_channel(self.spec.node_id, stream),
ChannelContent::JsonRecord {
schema: Some(MYELIN_PROVISIONING_LOGS.to_owned()),
},
);
let payload = serde_json::to_vec(&record).expect("serialize bootstrap log record");
producer.submit_bytes(channel, payload);
}
}
#[derive(Deserialize, Serialize)]
struct StdioTelemetryFrame {
myelin_stdio_event: u32,
kind: String,
channel: String,
payload: Value,
}
pub(crate) fn parse_stdio_telemetry_frame(
spec: &NodeProvisionSpec,
line: &str,
) -> Option<PluginObservation> {
let frame = serde_json::from_str::<StdioTelemetryFrame>(line).ok()?;
if frame.myelin_stdio_event != 1 || frame.kind != "telemetry_frame" {
return None;
}
Some(PluginObservation::TelemetryFrame {
run_id: spec.run_id,
node_id: spec.node_id,
channel: frame.channel,
payload: frame.payload.to_string(),
})
}