use std::time::Duration;
use crate::origin::{OriginKey, Protocol};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ConnectPhase {
Dns,
Tcp,
Tls,
}
impl ConnectPhase {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Dns => "dns",
Self::Tcp => "tcp",
Self::Tls => "tls",
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ScaleReason {
Saturated,
Waiters,
Min,
Idle,
Underused,
Expired,
Replace,
}
impl ScaleReason {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Saturated => "saturated",
Self::Waiters => "waiters",
Self::Min => "min",
Self::Idle => "idle",
Self::Underused => "underused",
Self::Expired => "expired",
Self::Replace => "replace",
}
}
}
#[allow(unused_variables, reason = "default no-op bodies")]
pub trait Observer: Send + Sync + 'static {
fn enabled(&self) -> bool {
false
}
fn request_queued(&self, o: &OriginKey, wait: Duration) {}
fn request_dispatched(&self, o: &OriginKey, delay: Duration) {}
fn connect_phase(&self, o: &OriginKey, phase: ConnectPhase, d: Duration, ok: bool) {}
fn connection_opened(&self, o: &OriginKey, p: Protocol) {}
fn connection_closed(&self, o: &OriginKey, p: Protocol, lifetime: Duration) {}
fn write_batch(&self, o: &OriginKey, bytes: usize, iovecs: usize) {}
fn bytes_read(&self, o: &OriginKey, n: usize) {}
fn actor_tick(&self, o: &OriginKey, busy: Duration, queue_depth: usize) {}
fn flow_control_stall(&self, o: &OriginKey, d: Duration) {}
fn h2_goaway(&self, o: &OriginKey, code: u32) {}
fn h2_rst_stream(&self, o: &OriginKey, code: u32, sent: bool) {}
fn pool_waiters(&self, o: &OriginKey, n: usize) {}
fn pool_scaled(&self, o: &OriginKey, conns: usize, reason: ScaleReason) {}
}
#[derive(Clone, Copy, Debug, Default)]
pub struct NoopObserver;
impl Observer for NoopObserver {}