#[cfg(not(loom))]
use std::time::Duration;
#[cfg(all(feature = "metrics", not(loom)))]
use ::metrics::{counter, histogram};
pub const SERVER_STARTUP_FAILURES: &str = "wireframe_server_startup_failures_total";
pub const SERVER_STARTUP_DURATION: &str = "wireframe_server_startup_duration_seconds";
#[cfg(not(loom))]
#[derive(Clone, Copy)]
pub(crate) enum ServerStartupFailureStage {
FactoryBuild,
Preparation,
}
#[cfg(not(loom))]
impl ServerStartupFailureStage {
pub(crate) const fn as_str(self) -> &'static str {
match self {
Self::FactoryBuild => "factory_build",
Self::Preparation => "preparation",
}
}
}
#[cfg(not(loom))]
#[derive(Clone, Copy)]
pub(crate) enum ServerStartupOutcome {
Success,
FactoryBuild,
Preparation,
Cancelled,
}
#[cfg(all(feature = "metrics", not(loom)))]
impl ServerStartupOutcome {
pub(crate) const fn as_str(self) -> &'static str {
match self {
Self::Success => "success",
Self::FactoryBuild => "factory_build",
Self::Preparation => "preparation",
Self::Cancelled => "cancelled",
}
}
}
#[cfg(all(feature = "metrics", not(loom)))]
pub(crate) fn inc_server_startup_failure(stage: ServerStartupFailureStage) {
counter!(SERVER_STARTUP_FAILURES, "stage" => stage.as_str()).increment(1);
}
#[cfg(all(feature = "metrics", not(loom)))]
pub(crate) fn record_server_startup_duration(outcome: ServerStartupOutcome, elapsed: Duration) {
histogram!(SERVER_STARTUP_DURATION, "outcome" => outcome.as_str())
.record(elapsed.as_secs_f64());
}
#[cfg(all(not(feature = "metrics"), not(loom)))]
pub(crate) fn record_server_startup_duration(_outcome: ServerStartupOutcome, _elapsed: Duration) {}
#[cfg(all(not(feature = "metrics"), not(loom)))]
pub(crate) fn inc_server_startup_failure(_stage: ServerStartupFailureStage) {}