use super::*;
#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
pub struct RateLimitConfig {
#[get(type(copy))]
pub(crate) requests_per_second: u64,
#[get(type(copy))]
pub(crate) burst: u64,
}
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct UpstreamTarget {
pub(crate) url: String,
#[get(type(copy))]
pub(crate) weight: u32,
}
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct GatewayRoute {
pub(crate) prefix: String,
#[get(type(copy))]
pub(crate) strip_prefix: bool,
#[get(type(clone))]
pub(crate) host: Option<String>,
pub(crate) upstreams: Vec<UpstreamTarget>,
#[get(type(copy))]
pub(crate) strategy: LoadBalanceStrategy,
#[get(type(copy))]
pub(crate) timeout_ms: u64,
#[get(type(copy))]
pub(crate) max_retries: usize,
#[get(type(copy))]
pub(crate) rate_limit: Option<RateLimitConfig>,
#[get(type(copy))]
pub(crate) use_http2: bool,
}
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct GatewayConfig {
pub(crate) routes: Vec<GatewayRoute>,
#[get(type(copy))]
pub(crate) max_body_size: usize,
#[get(type(copy))]
pub(crate) circuit_failure_threshold: u32,
#[get(type(copy))]
pub(crate) circuit_reset_ms: u64,
}
pub(crate) struct UpstreamRuntime {
pub(crate) base_url: String,
pub(crate) weight: u32,
pub(crate) active_conns: AtomicUsize,
pub(crate) consecutive_failures: AtomicU32,
pub(crate) open_until_ms: AtomicU64,
}
pub(crate) struct TokenBucket {
pub(crate) emission_interval_ns: u64,
pub(crate) burst_tolerance_ns: u64,
pub(crate) epoch: Instant,
pub(crate) tat_ns: AtomicU64,
}
pub(crate) struct CompiledRoute {
pub(crate) route: GatewayRoute,
pub(crate) normalized_prefix: String,
pub(crate) normalized_host: Option<String>,
pub(crate) upstreams: Vec<Arc<UpstreamRuntime>>,
pub(crate) weighted_ring: Vec<usize>,
pub(crate) cursor: AtomicUsize,
pub(crate) limiter: Option<TokenBucket>,
}
#[derive(Clone)]
pub struct GatewayRuntime {
pub(crate) config: GatewayConfig,
pub(crate) routes: Arc<Vec<CompiledRoute>>,
pub(crate) interceptors: Arc<Vec<SharedGatewayInterceptor>>,
pub(crate) any_host_route: bool,
}
#[derive(Clone)]
pub struct GatewayPlugin {
pub(crate) runtime: GatewayRuntime,
}
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::request_middleware(-50)]
pub struct GatewayHook;