Skip to main content

HealthPolicy

Struct HealthPolicy 

Source
pub struct HealthPolicy { /* private fields */ }
Expand description

Explicit mapping from task states to aggregate health impacts.

The built-in policies are conveniences rather than hidden monitor behavior. Callers may override any state with HealthPolicy::with_impact.

Implementations§

Source§

impl HealthPolicy

Source

pub const fn readiness() -> Self

A readiness-oriented policy.

Starting and learning tasks are degraded, healthy tasks are nominal, and late or stopped retained tasks are unhealthy.

Examples found in repository?
examples/health_report.rs (line 12)
5fn main() -> Result<(), Box<dyn Error>> {
6    let monitor = Monitor::new();
7    let heartbeat = monitor.register(TaskConfig::new(
8        "api-worker",
9        Timing::fixed(Duration::from_secs(1)),
10    ))?;
11
12    let starting = monitor.summary(HealthPolicy::readiness());
13    println!(
14        "before first beat: verdict={:?}, starting={}",
15        starting.verdict, starting.counts.starting,
16    );
17
18    heartbeat.beat()?;
19
20    let report = monitor.report(HealthPolicy::liveness());
21    println!(
22        "after first beat: verdict={:?}, healthy={}",
23        report.summary.verdict, report.summary.counts.healthy,
24    );
25    for task in report.tasks.iter() {
26        println!("{}: {:?}", task.name, task.health);
27    }
28
29    Ok(())
30}
Source

pub const fn liveness() -> Self

A liveness-oriented policy.

Starting, learning, and healthy tasks are nominal. Late tasks are unhealthy. Stopped retained tasks are ignored because they are no longer expected to produce heartbeats.

Examples found in repository?
examples/health_report.rs (line 20)
5fn main() -> Result<(), Box<dyn Error>> {
6    let monitor = Monitor::new();
7    let heartbeat = monitor.register(TaskConfig::new(
8        "api-worker",
9        Timing::fixed(Duration::from_secs(1)),
10    ))?;
11
12    let starting = monitor.summary(HealthPolicy::readiness());
13    println!(
14        "before first beat: verdict={:?}, starting={}",
15        starting.verdict, starting.counts.starting,
16    );
17
18    heartbeat.beat()?;
19
20    let report = monitor.report(HealthPolicy::liveness());
21    println!(
22        "after first beat: verdict={:?}, healthy={}",
23        report.summary.verdict, report.summary.counts.healthy,
24    );
25    for task in report.tasks.iter() {
26        println!("{}: {:?}", task.name, task.health);
27    }
28
29    Ok(())
30}
Source

pub const fn strict() -> Self

A strict policy that accepts only healthy tasks as nominal.

Source

pub const fn with_impact(self, state: HealthState, impact: HealthImpact) -> Self

Overrides the impact assigned to one stable task state.

Source

pub const fn impact(self, state: HealthState) -> HealthImpact

Returns the impact assigned to a stable task state.

Trait Implementations§

Source§

impl Clone for HealthPolicy

Source§

fn clone(&self) -> Self

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

impl Copy for HealthPolicy

Source§

impl Debug for HealthPolicy

Source§

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

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

impl Default for HealthPolicy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for HealthPolicy

Source§

impl Hash for HealthPolicy

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for HealthPolicy

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HealthPolicy

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, 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> 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, !>

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.