(state: &HealthState)
| 201 | } |
| 202 | |
| 203 | fn record_metrics(state: &HealthState) { |
| 204 | let (healthy, outcome_label, latency_seconds) = match state { |
| 205 | HealthState::Initializing => return, |
| 206 | HealthState::Healthy { latency_ms } => { |
| 207 | (true, "success", duration_seconds_from_ms(*latency_ms)) |
| 208 | } |
| 209 | HealthState::Unhealthy(HealthError::Unavailable { latency_ms }) => { |
| 210 | (false, "db_error", duration_seconds_from_ms(*latency_ms)) |
| 211 | } |
| 212 | HealthState::Unhealthy(HealthError::Timeout) => { |
| 213 | (false, "timeout", DEFAULT_CHECK_TIMEOUT.as_secs_f64()) |
| 214 | } |
| 215 | }; |
| 216 | |
| 217 | gauge!(METRIC_READINESS_DATABASE_HEALTHY).set(if healthy { 1.0 } else { 0.0 }); |
| 218 | histogram!( |
| 219 | METRIC_READINESS_DATABASE_PROBE_DURATION_SECONDS, |
| 220 | METRIC_OUTCOME_LABEL => outcome_label |
| 221 | ) |
| 222 | .record(latency_seconds); |
| 223 | } |
| 224 | |
| 225 | fn duration_seconds_from_ms(ms: u64) -> f64 { |
| 226 | #[allow(clippy::cast_precision_loss)] |
no test coverage detected