Skip to content

Commit 3e8798e

Browse files
committed
Feat: Live API includes the sankey/tree data as a live option.
1 parent 624ae59 commit 3e8798e

2 files changed

Lines changed: 88 additions & 1 deletion

File tree

src/rust/lqosd/src/lts2_sys/control_channel.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ async fn persistent_connection(
328328
};
329329
});
330330
}
331+
messages::WsMessage::StartShaperTreeStreaming { request_id } => {
332+
let socket_sender_tx = socket_sender_tx.clone();
333+
tokio::spawn(async move {
334+
let Ok(()) = tree_snapshot_streaming(request_id, socket_sender_tx).await else {
335+
error!("Tree snapshot streaming failed");
336+
return;
337+
};
338+
});
339+
}
331340
_ => {}
332341
}
333342
}
@@ -919,3 +928,73 @@ async fn circuit_snapshot_streaming(
919928
}
920929
Ok(())
921930
}
931+
932+
async fn tree_snapshot_streaming(
933+
request_id: u64,
934+
reply: tokio::sync::mpsc::Sender<Message>,
935+
) -> anyhow::Result<()> {
936+
#[derive(Serialize, Deserialize)]
937+
struct LiveNetworkTransport {
938+
name: String,
939+
max_throughput: (u32, u32),
940+
current_throughput: (u64, u64),
941+
current_packets: (u64, u64),
942+
current_tcp_packets: (u64, u64),
943+
current_udp_packets: (u64, u64),
944+
current_icmp_packets: (u64, u64),
945+
current_retransmits: (u64, u64),
946+
current_marks: (u64, u64),
947+
current_drops: (u64, u64),
948+
rtts: Vec<f32>,
949+
parents: Vec<usize>,
950+
immediate_parent: Option<usize>,
951+
#[serde(rename = "type")]
952+
node_type: Option<String>,
953+
}
954+
955+
// Use the same data source as local_api::network_tree
956+
let net_json = crate::shaped_devices_tracker::NETWORK_JSON.read().unwrap();
957+
let result: Vec<(usize, LiveNetworkTransport)> = net_json
958+
.get_nodes_when_ready()
959+
.iter()
960+
.enumerate()
961+
.map(|(i, n)| {
962+
let t = n.clone_to_transit();
963+
let mapped = LiveNetworkTransport {
964+
name: t.name,
965+
max_throughput: t.max_throughput,
966+
current_throughput: t.current_throughput,
967+
current_packets: t.current_packets,
968+
current_tcp_packets: t.current_tcp_packets,
969+
current_udp_packets: t.current_udp_packets,
970+
current_icmp_packets: t.current_icmp_packets,
971+
current_retransmits: t.current_retransmits,
972+
current_marks: t.current_marks,
973+
current_drops: t.current_drops,
974+
rtts: t.rtts,
975+
parents: t.parents,
976+
immediate_parent: t.immediate_parent,
977+
node_type: t.node_type,
978+
};
979+
(i, mapped)
980+
})
981+
.collect();
982+
983+
let Ok(bytes) = serde_cbor::to_vec(&result) else {
984+
error!("Failed to serialize LiveNetworkTransport payload");
985+
return Ok(());
986+
};
987+
988+
let message = messages::WsMessage::StreamingShaperTree { request_id, data: bytes };
989+
let Ok((_, _, ws_bytes)) = message.to_bytes() else {
990+
error!("Failed to serialize StreamingShaperTree message");
991+
return Ok(());
992+
};
993+
if let Err(e) = reply.try_send(Message::Binary(ws_bytes.into())) {
994+
match e {
995+
TrySendError::Full(_) => warn!("Send unavailable: StreamingShaperTree queue full; dropping reply"),
996+
TrySendError::Closed(_) => error!("Failed to send StreamingShaperTree: channel closed"),
997+
}
998+
}
999+
Ok(())
1000+
}

src/rust/lqosd/src/lts2_sys/control_channel/messages.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ pub enum WsMessage {
9191
StartShaperStreaming {
9292
request_id: u64,
9393
},
94+
// Request a one-shot shaper tree snapshot
95+
StartShaperTreeStreaming {
96+
request_id: u64,
97+
},
9498
StreamingCircuit {
9599
request_id: u64,
96100
circuit_hash: i64,
@@ -102,10 +106,14 @@ pub enum WsMessage {
102106
bytes_up: u64,
103107
shaped_bytes_down: u64,
104108
shaped_bytes_up: u64,
105-
// Packets per second (down, up)
106109
packets_down: u64,
107110
packets_up: u64,
108111
},
112+
// Reply containing a one-shot shaper tree snapshot (CBOR encoded payload)
113+
StreamingShaperTree {
114+
request_id: u64,
115+
data: Vec<u8>,
116+
},
109117
HistoryQuery {
110118
request_id: u64,
111119
query: RemoteInsightRequest,

0 commit comments

Comments
 (0)