pharos/threshold_eval
Evaluate a Threshold against a decoded Measurement.
Returns a three-way verdict so callers can branch without reaching
for nested case over the cartesian product of measurements and
thresholds. Helper functions match every measurement variant
exhaustively, so adding a new measurement kind surfaces as a
compiler warning here.
Types
Three-way verdict for a (measurement, threshold) pair.
pub type Verdict {
NotApplicable
Healthy
Breached
}
Constructors
-
NotApplicableThe threshold doesn’t apply to this measurement kind. Caller should do nothing (don’t fire
recoverfor unrelated measurements). -
HealthyThe threshold applies and is currently within limits.
-
BreachedThe threshold applies and is currently breached.
Values
pub fn evaluate(
measurement: measurement.Measurement,
threshold: config.Threshold,
) -> Verdict
Evaluate threshold against measurement and return a Verdict.
pub fn evaluate_probe(
sample: dict.Dict(String, Float),
threshold: probe.ProbeThreshold,
) -> Verdict
Evaluate a probe threshold against a decoded probe sample, returning
the same Verdict as evaluate/2. A NotApplicable verdict means the
threshold’s field is absent from this sample, so the caller should neither
breach nor recover.
pub fn metric_name(threshold: config.Threshold) -> String
The flattened metric name a threshold compares against (see
metric.from_measurement).
pub fn sample_value(
measurement: measurement.Measurement,
threshold: config.Threshold,
) -> Result(Float, Nil)
Extract the current value of the metric threshold compares, by name, from
the measurement’s flattened metrics. Returns Error(Nil) when the
measurement doesn’t carry that metric (wrong kind, or an Unimplemented
host probe, which flattens to no metrics), so such ticks contribute no
sample to a window.
pub fn threshold_limit(threshold: config.Threshold) -> Float
The threshold’s comparison limit as a Float (integer limits are widened).