Skip to main content

AppState

Struct AppState 

Source
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.

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn stream_client(&self) -> Arc<Client>

The client to proxy a Server-Sent Events request with (#6155).

Trait Implementations§

Source§

impl Clone for AppState

Source§

fn clone(&self) -> AppState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more