soma_gateway/gateway/
projection.rs1use crate::upstream::UpstreamHealth;
2
3use super::manager::{GatewayManager, GatewayManagerError};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct GatewayProjection {
7 pub upstream_count: usize,
8 pub connected_count: usize,
9 pub discovered_tool_count: usize,
10 pub exposed_tool_count: usize,
11 pub likely_stale_count: usize,
12}
13
14impl GatewayProjection {
15 pub async fn from_manager(manager: &GatewayManager) -> Result<Self, GatewayManagerError> {
16 let snapshots = manager.discover().await?;
17 let upstream_count = snapshots.len();
18 let connected_count = snapshots
19 .iter()
20 .filter(|snapshot| snapshot.health == UpstreamHealth::Connected)
21 .count();
22 let discovered_tool_count = snapshots
23 .iter()
24 .map(|snapshot| snapshot.tools.len())
25 .sum::<usize>();
26 let exposed_tool_count = manager.exposed_tool_count()?;
27 let likely_stale_count = snapshots.iter().filter(|snapshot| snapshot.stale).count();
28 Ok(Self {
29 upstream_count,
30 connected_count,
31 discovered_tool_count,
32 exposed_tool_count,
33 likely_stale_count,
34 })
35 }
36}
37
38#[cfg(test)]
39#[path = "projection_tests.rs"]
40mod tests;