pub struct ControlState<H>where
H: LifecycleHandle + Clone,{
pub project: String,
pub handle: H,
/* private fields */
}Expand description
Shared state injected into every route of the control plane.
Constructed once and cloned into the axum router via
axum::Router::with_state. All fields that route handlers need are
either pub or exposed through the constructors below.
Use ControlState::new for tests and embedders that do not need
Prometheus metrics, and ControlState::with_metrics for production
use where GET /metrics must return live data.
Fields§
§project: StringProject name as declared in the manifest.
Shown in the dashboard title and returned by GET /healthz.
handle: HLifecycle handle backing the resource endpoints.
Handlers call lightshuttle_runtime::LifecycleHandle::list,
lightshuttle_runtime::LifecycleHandle::get,
lightshuttle_runtime::LifecycleHandle::restart,
lightshuttle_runtime::LifecycleHandle::logs, and
lightshuttle_runtime::LifecycleHandle::subscribe_events through
this field.
Implementations§
Source§impl<H> ControlState<H>where
H: LifecycleHandle + Clone,
impl<H> ControlState<H>where
H: LifecycleHandle + Clone,
Sourcepub fn new(project: impl Into<String>, handle: H) -> Self
pub fn new(project: impl Into<String>, handle: H) -> Self
Build state with a non-installing crate::Metrics handle.
The attached crate::Metrics does not install a global recorder, so
the metrics! macros write nowhere and GET /metrics renders an
empty snapshot. This constructor is intended for tests and for embedders
that do not need to serve metrics. In production, install the recorder
once with crate::Metrics::install and use Self::with_metrics
to pass the live handle.
Sourcepub fn with_metrics(
project: impl Into<String>,
handle: H,
metrics: Arc<Metrics>,
) -> Self
pub fn with_metrics( project: impl Into<String>, handle: H, metrics: Arc<Metrics>, ) -> Self
Build state bound to an existing crate::Metrics renderer.
Use this constructor in production when you have already called
crate::Metrics::install and wrapped the result in an Arc.
GET /metrics will then render live counters and gauges.
The Arc is cheap to clone across axum route handlers.
Trait Implementations§
Source§impl<H> Clone for ControlState<H>
impl<H> Clone for ControlState<H>
Source§fn clone(&self) -> ControlState<H>
fn clone(&self) -> ControlState<H>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<H> Freeze for ControlState<H>where
H: Freeze,
impl<H> RefUnwindSafe for ControlState<H>where
H: RefUnwindSafe,
impl<H> Send for ControlState<H>
impl<H> Sync for ControlState<H>
impl<H> Unpin for ControlState<H>where
H: Unpin,
impl<H> UnsafeUnpin for ControlState<H>where
H: UnsafeUnpin,
impl<H> UnwindSafe for ControlState<H>where
H: UnwindSafe,
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,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request