(store: &Store, timeout: Duration)
| 180 | } |
| 181 | |
| 182 | async fn run_check(store: &Store, timeout: Duration) -> HealthState { |
| 183 | let started = Instant::now(); |
| 184 | match tokio::time::timeout(timeout, store.ping()).await { |
| 185 | Ok(Ok(())) => HealthState::Healthy { |
| 186 | latency_ms: elapsed_ms(started.elapsed()), |
| 187 | }, |
| 188 | Ok(Err(err)) => { |
| 189 | let latency_ms = elapsed_ms(started.elapsed()); |
| 190 | warn!(error = %err, latency_ms, "database health check failed"); |
| 191 | HealthState::Unhealthy(HealthError::Unavailable { latency_ms }) |
| 192 | } |
| 193 | Err(_) => { |
| 194 | warn!( |
| 195 | timeout_ms = u64::try_from(timeout.as_millis()).unwrap_or(u64::MAX), |
| 196 | "database health check timed out" |
| 197 | ); |
| 198 | HealthState::Unhealthy(HealthError::Timeout) |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | fn record_metrics(state: &HealthState) { |
| 204 | let (healthy, outcome_label, latency_seconds) = match state { |
no test coverage detected