Skip to main content

HealthState

Struct HealthState 

Source
pub struct HealthState {
    ticks: AtomicU64,
    last_tick_unix: AtomicI64,
    started_unix: i64,
    certificates: OnceLock<Arc<dyn CertificateAlerts>>,
    data_dir: OnceLock<(PathBuf, DiskWatermarks)>,
    disk_alert: AtomicU8,
}
Expand description

The tick’s pulse, shared with whoever answers GET /health.

Kept separate from HealthTick itself so a caller can hand the state to the HTTP router and the join handle to nothing but the shutdown path — the router has no business awaiting the task or aborting it, only reading the counters.

Fields§

§ticks: AtomicU64

How many ticks have fired since the process started.

§last_tick_unix: AtomicI64

Unix seconds of the most recent tick, or 0 for “never yet” — the first tick fires one interval after startup, by design; see HealthTick::spawn.

§started_unix: i64

Unix seconds this state was created, which is startup for all practical purposes: it is built and handed to HealthTick::spawn in the same breath the tick task is.

§certificates: OnceLock<Arc<dyn CertificateAlerts>>

Whoever can answer for the certificates, once there is one — see HealthState::attach_certificates for why this is filled in after the router is already serving rather than passed to the constructor.

§data_dir: OnceLock<(PathBuf, DiskWatermarks)>

The data directory whose volume HealthState::disk reads, and the watermarks its free space is measured against; see HealthState::attach_data_dir.

§disk_alert: AtomicU8

The DiskAlert the last tick read, as its u8: ok before one has.

Implementations§

Source§

impl HealthState

Source

pub fn new() -> Arc<Self> ⓘ

A fresh state, stamped with the current time as its start.

Source

fn record_tick(&self)

Records that a tick just fired.

Source

pub fn attach_certificates(&self, alerts: Arc<dyn CertificateAlerts>)

Names who can answer for the certificates.

Separate from HealthState::new because of the order the binary builds things in: the router — and this state with it — exists before the ACME fleet does, since the fleet is bootstrapped by the code that is handed the finished router to serve. The first call wins and later ones are ignored, so a second fleet cannot quietly replace the one the listener is actually serving certificates from.

Source

pub fn attach_data_dir(&self, dir: PathBuf, watermarks: DiskWatermarks)

Names the data directory whose volume HealthState::disk reads, and the watermarks its free space is measured against.

The first call wins, as it does for HealthState::attach_certificates. A state nothing names has no volume to read, which is every in-memory run.

Source

pub async fn disk(&self) -> Option<DiskHealth>

The data volume’s free and total bytes, read as this is called.

Read on the blocking pool, because statvfs asks the filesystem, and a volume that has stopped answering must not hold an async worker. None when no data directory was named, and when the read fails, which is logged.

Source

pub(crate) fn watch_disk(&self, disk: &DiskHealth) -> Option<DiskAlert>

Writes a line when disk has crossed a watermark since the last reading: warn going down, info coming back up. A first reading below a watermark is a crossing. Answers the alert it wrote about.

Source

pub async fn certificates(&self) -> CertificateHealth

The certificate half of the health response.

async, and so kept out of HealthState::snapshot: the levels are read from the renewal trackers themselves rather than from a copy something has to remember to refresh, which is what makes a warning in this response and a warning in the log the same fact.

Source

pub fn snapshot(&self) -> HealthSnapshot

A point-in-time read, safe to serialize into an HTTP response.

Trait Implementations§

Source§

impl Debug for HealthState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HealthState

Source§

fn default() -> HealthState

Returns the “default value” for a type. 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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,