pub struct AppState { /* private fields */ }Expand description
Shared application state injected into every route handler.
Why: Connectors, the poller cache, metrics caches, and HTTP client are
created once at startup and reused for every request so there is no per-
request allocation. A separate MetricsCache is maintained for each
stdio-MCP-polled service (analyze, memory, search, review) so they can be
updated independently and served without coupling. analyze_handle is held
in Arc so the on-demand visualize/index routes can call the analyze stdio MCP
without going through the /proxy path.
mcp_handles maps each service id to its McpServiceHandle so the
services route can overlay the connector-reported status with the actual
tools/list probe result (Degraded when console_metrics is absent).
What: Wraps the connector list, poller cache, per-service metrics caches,
reqwest client, the analyze MCP handle, and the full handle map in Arcs
for cheap cloning.
Test: Constructed in build_router; exercised by the integration tests.
Implementations§
Source§impl AppState
Resolve trusty-search’s socket for the routes and the connector alike.
impl AppState
Resolve trusty-search’s socket for the routes and the connector alike.
Why on AppState rather than a free call: the integration tests bind their
own stub socket and need the router to dial it, and the alternative —
TRUSTY_DATA_DIR_OVERRIDE — is process-global in a test binary that runs
six connectors in parallel. The same argument detect::AnalyzeConnector
records for taking a socket override.
Test: tests/search_uds_bridge.rs drives every case through it.
Sourcepub fn with_search_socket(self, socket: PathBuf) -> Self
pub fn with_search_socket(self, socket: PathBuf) -> Self
Dial socket for trusty-search instead of the resolved path.
Why: see the AppState::search_socket field doc — the alternative is a
process-global env var this crate’s test binary cannot use safely.
Test: tests/search_uds_bridge.rs sets it on every case.
Source§impl AppState
impl AppState
Sourcepub fn new(connectors: Vec<Box<dyn ServiceConnector>>) -> Self
pub fn new(connectors: Vec<Box<dyn ServiceConnector>>) -> Self
Create a new AppState from a list of connectors.
Why: Lets tests inject a custom connector list and fresh caches.
What: Wraps connectors in Arc; initialises empty PollerCache,
three MetricsCache instances (analyze / memory / search), and a
reqwest::Client with idle-connection pooling disabled (#1984 — see the
builder comment below). Creates the analyze stdio MCP handle that is
shared between the background metrics poller and on-demand routes.
Populates mcp_handles with all three per-service handles so the
services route can read their degraded state.
Test: Used in build_router and directly in tests.
Sourcepub fn mcp_handles(&self) -> Arc<HashMap<String, Arc<McpServiceHandle>>> ⓘ
pub fn mcp_handles(&self) -> Arc<HashMap<String, Arc<McpServiceHandle>>> ⓘ
Access the per-service MCP handle map.
Why: The services route reads handles from this map to overlay connector
statuses with the tools/list probe result.
What: Returns a clone of the Arc<HashMap> (cheap).
Test: Used by apply_handle_overrides and the services handler.
Sourcepub fn analyze_handle(&self) -> Arc<McpServiceHandle> ⓘ
pub fn analyze_handle(&self) -> Arc<McpServiceHandle> ⓘ
Access the shared analyze MCP handle.
Why: On-demand routes (/api/console/metrics/analyze/indexes,
/api/console/metrics/analyze/visualize) call the analyze stdio MCP
without touching the analyze daemon HTTP directly (architecture: console
is a stdio MCP client only, per #1104).
What: Returns a clone of the Arc<McpServiceHandle> (cheap).
Test: Exercised by the analyze index and visualize route tests.
Sourcepub fn connectors(&self) -> Arc<Vec<Box<dyn ServiceConnector>>> ⓘ
pub fn connectors(&self) -> Arc<Vec<Box<dyn ServiceConnector>>> ⓘ
Access the shared connector list.
Why: The background poller and the fallback spawn_blocking path both
need the connector list.
What: Returns a clone of the Arc (cheap).
Test: Used by run_serve in main.rs.
Sourcepub fn poller_cache(&self) -> &PollerCache
pub fn poller_cache(&self) -> &PollerCache
Access the background poll cache.
Why: Routes read from the cache; the background task writes to it.
What: Returns a clone of the PollerCache handle (cheap — it’s an Arc).
Test: Used by services_handler and proxy_handler.
Sourcepub fn metrics_cache(&self) -> &MetricsCache
pub fn metrics_cache(&self) -> &MetricsCache
Access the metrics cache for the trusty-analyze stdio MCP poller.
Why: The metrics poller writes ConsoleMetricsReports here; the
/api/console/metrics/analyze route reads from it.
What: Returns a reference to the MetricsCache handle.
Test: test_metrics_analyze_route_cold_cache_returns_503.
Sourcepub fn memory_metrics_cache(&self) -> &MetricsCache
pub fn memory_metrics_cache(&self) -> &MetricsCache
Access the metrics cache for the trusty-memory stdio MCP poller.
Why: Separate cache per service so memory and analyze reports can be
updated and served independently.
What: Returns a reference to the MetricsCache handle for memory.
Test: test_metrics_memory_route_cold_cache_returns_503.
Sourcepub fn search_metrics_cache(&self) -> &MetricsCache
pub fn search_metrics_cache(&self) -> &MetricsCache
Access the metrics cache for the trusty-search stdio MCP poller.
Why: Separate cache per service so search and analyze reports can be
updated and served independently.
What: Returns a reference to the MetricsCache handle for search.
Test: test_metrics_search_route_cold_cache_returns_503.
Sourcepub fn review_metrics_cache(&self) -> &MetricsCache
pub fn review_metrics_cache(&self) -> &MetricsCache
Access the metrics cache for the trusty-review stdio MCP poller.
Why: Separate cache per service so review reports can be updated and
served independently from the other service caches.
What: Returns a reference to the MetricsCache handle for review.
Test: test_metrics_review_route_cold_cache_returns_503.
Sourcepub fn mpm_metrics_cache(&self) -> &MetricsCache
pub fn mpm_metrics_cache(&self) -> &MetricsCache
Access the metrics cache for the trusty-mpm stdio MCP poller (#1222).
Why: separate cache per service so the mpm session/supervisor report can
be updated and served independently from the other service caches.
What: returns a reference to the MetricsCache handle for mpm.
Test: test_metrics_mpm_route_cold_cache_returns_503.
Sourcepub fn host_metrics_cache(&self) -> &HostMetricsCache
pub fn host_metrics_cache(&self) -> &HostMetricsCache
Access the whole-machine host-metrics cache (#6517).
Why: the background host sampler writes here; the machine-status route
reads it. run_serve clones it to start the sampler.
What: returns a reference to the HostMetricsCache handle.
Test: machine_status_route_cold_cache_returns_503.
Sourcepub async fn collect_service_reports(&self) -> Vec<ConsoleMetricsReport>
pub async fn collect_service_reports(&self) -> Vec<ConsoleMetricsReport>
Gather whichever per-service ConsoleMetricsReports are currently cached
(#6517).
Why: the machine-status rollup counts and lists every service that has a
warm report. A service whose cache is still None (binary absent or not
yet polled) is simply omitted — the rollup describes what is reachable.
What: reads all five per-service metrics caches and collects the Some
reports into a Vec in a stable service order.
Test: machine_status_route_warm_cache_returns_json.
Sourcepub fn http_client(&self) -> Arc<Client> ⓘ
pub fn http_client(&self) -> Arc<Client> ⓘ
Access the shared reqwest::Client.
Why: Re-using one client enables connection pooling across proxy requests.
What: Returns a clone of the Arc<reqwest::Client> (cheap).
Test: Used by proxy_handler.
Sourcepub fn stream_client(&self) -> Arc<Client> ⓘ
pub fn stream_client(&self) -> Arc<Client> ⓘ
The client to proxy a Server-Sent Events request with (#6155).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AppState
impl !UnwindSafe for AppState
impl Freeze for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more