use std::time::Duration;
#[cfg(feature = "metrics")]
use metrics::{counter, gauge, histogram};
mod app_response_sends;
mod client_pool;
#[cfg(all(feature = "pool", not(loom)))]
pub(crate) use client_pool::{
PoolAcquisitionMode,
PoolAcquisitionOutcome,
PoolPermitRaceGuard,
inc_pool_acquisition,
};
mod decode_rejections;
mod pool_scheduler;
mod preamble_rejections;
mod push_writes;
mod response_delivery;
#[cfg(not(loom))]
mod server_cancellation;
#[cfg(not(loom))]
pub(crate) use server_cancellation::ServerCancellationReason;
mod server_startup;
mod server_supervisor;
mod streaming_bodies;
pub use app_response_sends::APP_RESPONSE_SENDS;
pub(crate) use app_response_sends::{AppResponseSendOutcome, inc_app_response_send};
pub use client_pool::{
POOL_ACQUISITIONS,
POOL_CONNECTION_DISCARDS,
POOL_PERMIT_RACE_DURATION,
POOL_PERMIT_RACES,
POOL_PERMIT_RACES_STARTED,
};
#[cfg(all(feature = "pool", not(loom)))]
pub(crate) use client_pool::{
inc_pool_incomplete_operation_discard,
inc_pool_pending_response_discard,
};
pub use decode_rejections::DECODE_REJECTIONS;
pub(crate) use decode_rejections::{
DecodeRejectionPath,
DecodeRejectionReason,
inc_decode_rejection,
};
pub use pool_scheduler::POOL_SCHEDULER_FAILURES;
#[cfg(all(feature = "pool", not(loom)))]
pub(crate) use pool_scheduler::inc_pool_scheduler_failure;
pub use preamble_rejections::PREAMBLE_REJECTIONS;
pub(crate) use preamble_rejections::{PreambleRejectionReason, inc_preamble_rejection};
pub use push_writes::{PUSH_DROPS, PUSH_RATE_LIMITED, PUSH_WRITES_ABANDONED};
pub(crate) use push_writes::{PushDropOutcome, PushWriteAbandonReason, inc_push_rate_limited};
pub use response_delivery::RESPONSE_CANCELLATIONS;
pub(crate) use response_delivery::ResponseCancellationReason;
pub use server_startup::{SERVER_STARTUP_DURATION, SERVER_STARTUP_FAILURES};
#[cfg(not(loom))]
pub(crate) use server_startup::{
ServerStartupFailureStage,
ServerStartupOutcome,
inc_server_startup_failure,
record_server_startup_duration,
};
pub use server_supervisor::SERVER_SUPERVISOR_ABNORMAL_TERMINATIONS;
#[cfg(not(loom))]
pub(crate) use server_supervisor::inc_server_supervisor_abnormal_termination;
pub use streaming_bodies::{
STREAMING_BODIES_PARKED,
STREAMING_BODY_BYTES_QUEUED,
STREAMING_BODY_OUTCOMES,
};
pub(crate) use streaming_bodies::{
StreamingBodyOutcome,
add_parked_body,
add_queued_body_bytes,
release_parked_bodies,
release_queued_body_bytes,
};
pub const CONNECTIONS_ACTIVE: &str = "wireframe_connections_active";
pub const FRAMES_PROCESSED: &str = "wireframe_frames_processed_total";
pub const ERRORS_TOTAL: &str = "wireframe_errors_total";
pub const CONNECTION_PANICS: &str = "wireframe_connection_panics_total";
pub const POOL_BOOKKEEPING_POISON_RECOVERIES: &str =
"wireframe_pool_bookkeeping_poison_recoveries_total";
pub const CODEC_ERRORS: &str = "wireframe_codec_errors_total";
pub const APPLICATION_PREPARATIONS: &str = "wireframe_application_preparations_total";
pub const PREPARED_CONNECTION_USES: &str = "wireframe_prepared_connection_uses_total";
pub const APPLICATION_PREPARATION_DURATION: &str =
"wireframe_application_preparation_duration_seconds";
pub const SERVER_SUPERVISOR_CANCELLATIONS: &str = "wireframe_server_supervisor_cancellations_total";
pub const SERVER_ACCEPT_LOOPS_EXITED: &str = "wireframe_server_accept_loops_exited_total";
#[derive(Clone, Copy)]
pub(crate) enum PreparationOutcome {
Success,
Failure,
}
#[cfg(feature = "metrics")]
impl PreparationOutcome {
pub(crate) const fn as_str(self) -> &'static str {
match self {
Self::Success => "success",
Self::Failure => "failure",
}
}
}
#[derive(Clone, Copy)]
pub enum Direction {
Inbound,
Outbound,
}
#[cfg(feature = "metrics")]
impl Direction {
const fn as_str(self) -> &'static str {
match self {
Self::Inbound => "inbound",
Self::Outbound => "outbound",
}
}
}
#[cfg(feature = "metrics")]
pub fn inc_connections() { gauge!(CONNECTIONS_ACTIVE).increment(1.0); }
#[cfg(not(feature = "metrics"))]
pub fn inc_connections() {}
#[cfg(feature = "metrics")]
pub fn dec_connections() { gauge!(CONNECTIONS_ACTIVE).decrement(1.0); }
#[cfg(not(feature = "metrics"))]
pub fn dec_connections() {}
#[cfg(feature = "metrics")]
pub fn inc_frames(direction: Direction) {
counter!(FRAMES_PROCESSED, "direction" => direction.as_str()).increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn inc_frames(_direction: Direction) {}
#[cfg(feature = "metrics")]
pub fn inc_deser_errors() { counter!(ERRORS_TOTAL, "kind" => "deserialization").increment(1); }
#[cfg(not(feature = "metrics"))]
pub fn inc_deser_errors() {}
#[cfg(feature = "metrics")]
pub fn inc_handler_errors() { counter!(ERRORS_TOTAL, "kind" => "handler").increment(1); }
#[cfg(not(feature = "metrics"))]
pub fn inc_handler_errors() {}
#[cfg(feature = "metrics")]
pub fn inc_connection_panics() { counter!(CONNECTION_PANICS).increment(1); }
#[cfg(not(feature = "metrics"))]
pub fn inc_connection_panics() {}
#[cfg(feature = "metrics")]
pub fn inc_pool_bookkeeping_poison_recoveries() {
counter!(POOL_BOOKKEEPING_POISON_RECOVERIES).increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn inc_pool_bookkeeping_poison_recoveries() {}
#[cfg(feature = "metrics")]
pub fn inc_codec_error(error_type: &'static str, recovery_policy: &'static str) {
counter!(
CODEC_ERRORS,
"error_type" => error_type,
"recovery_policy" => recovery_policy
)
.increment(1);
}
#[cfg(not(feature = "metrics"))]
pub fn inc_codec_error(_error_type: &'static str, _recovery_policy: &'static str) {}
#[cfg(feature = "metrics")]
pub(crate) fn record_application_preparation(outcome: PreparationOutcome, elapsed: Duration) {
counter!(APPLICATION_PREPARATIONS, "outcome" => outcome.as_str()).increment(1);
histogram!(APPLICATION_PREPARATION_DURATION, "outcome" => outcome.as_str())
.record(elapsed.as_secs_f64());
}
#[cfg(not(feature = "metrics"))]
pub(crate) fn record_application_preparation(_outcome: PreparationOutcome, _elapsed: Duration) {}
#[cfg(feature = "metrics")]
pub(crate) fn inc_prepared_connection_uses() { counter!(PREPARED_CONNECTION_USES).increment(1); }
#[cfg(not(feature = "metrics"))]
pub(crate) fn inc_prepared_connection_uses() {}
#[cfg(all(feature = "metrics", not(loom)))]
pub(crate) fn inc_server_supervisor_cancellation(reason: ServerCancellationReason) {
counter!(SERVER_SUPERVISOR_CANCELLATIONS, "reason" => reason.as_str()).increment(1);
}
#[cfg(all(not(feature = "metrics"), not(loom)))]
pub(crate) fn inc_server_supervisor_cancellation(_reason: ServerCancellationReason) {}
#[cfg(all(feature = "metrics", not(loom)))]
pub(crate) fn inc_server_accept_loop_exit(reason: ServerCancellationReason) {
counter!(SERVER_ACCEPT_LOOPS_EXITED, "reason" => reason.as_str()).increment(1);
}
#[cfg(all(not(feature = "metrics"), not(loom)))]
pub(crate) fn inc_server_accept_loop_exit(_reason: ServerCancellationReason) {}