use serde::Serialize;
use crate::db::ObservabilityReport;
pub(crate) struct Check {
pub name: &'static str,
pub status: Status,
pub detail: String,
pub duration_ms: u64,
}
#[derive(Clone, Copy, Eq, PartialEq)]
pub(crate) enum Status {
Ok,
Warn,
Fail,
}
impl Status {
pub(crate) fn icon(&self) -> &'static str {
match self {
Status::Ok => "ok",
Status::Warn => "WARN",
Status::Fail => "FAIL",
}
}
pub(crate) fn as_json_tag(&self) -> &'static str {
match self {
Status::Ok => "ok",
Status::Warn => "warn",
Status::Fail => "fail",
}
}
}
impl Check {
pub(crate) fn new(name: &'static str, status: Status, detail: impl Into<String>) -> Self {
Self {
name,
status,
detail: detail.into(),
duration_ms: 0,
}
}
pub(crate) fn with_duration_ms(mut self, duration_ms: u64) -> Self {
self.duration_ms = duration_ms;
self
}
pub(crate) fn icon(&self) -> &'static str {
self.status.icon()
}
}
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct DoctorOutcome {
pub fails: usize,
pub warns: usize,
}
impl DoctorOutcome {
pub(crate) fn exit_code(&self) -> i32 {
if self.fails > 0 {
2
} else if self.warns > 0 {
1
} else {
0
}
}
}
pub(crate) const REPORT_SCHEMA_VERSION: u32 = 3;
#[derive(Serialize)]
pub(crate) struct CheckJson<'a> {
pub name: &'a str,
pub status: &'a str,
pub detail: &'a str,
pub duration_ms: u64,
}
#[derive(Serialize)]
pub(crate) struct ReportJson<'a> {
pub schema_version: u32,
pub version: &'a str,
pub binary_schema_version: i64,
pub status: &'a str,
pub fails: usize,
pub warns: usize,
pub elapsed_ms: u64,
pub checks: Vec<CheckJson<'a>>,
pub observability: ObservabilityReport,
}