pub struct UpstreamPool { /* private fields */ }Expand description
Upstream pool managing multiple backend servers
Implementations§
Source§impl UpstreamPool
impl UpstreamPool
Sourcepub async fn new(config: UpstreamConfig) -> ZentinelResult<Self>
pub async fn new(config: UpstreamConfig) -> ZentinelResult<Self>
Create new upstream pool from configuration
Sourcepub fn discovery_refresh_interval(&self) -> Option<Duration>
pub fn discovery_refresh_interval(&self) -> Option<Duration>
How often this pool’s discovery source should be re-resolved, if at all.
Sourcepub async fn refreshed(&self) -> Option<UpstreamPool>
pub async fn refreshed(&self) -> Option<UpstreamPool>
Re-resolve discovery and, when the target set has changed, build the pool that should replace this one.
Returns None when there is nothing to do — no discovery source, the
source failed, or it resolved to the same targets the pool already has.
Callers install the returned pool in place of this one; the two share
their circuit breakers and statistics, so a backend that was failing
before the refresh is still failing after it.
§Errors
Never fails: a discovery source that cannot be reached leaves the pool serving its current targets rather than emptying it.
Sourcepub async fn select_peer_with_metadata(
&self,
context: Option<&RequestContext>,
) -> ZentinelResult<(HttpPeer, HashMap<String, String>)>
pub async fn select_peer_with_metadata( &self, context: Option<&RequestContext>, ) -> ZentinelResult<(HttpPeer, HashMap<String, String>)>
Select next upstream peer with selection metadata
Returns the selected peer along with optional metadata from the load balancer. The metadata can contain sticky session information that should be passed to the response filter.
Sourcepub async fn select_peer(
&self,
context: Option<&RequestContext>,
) -> ZentinelResult<HttpPeer>
pub async fn select_peer( &self, context: Option<&RequestContext>, ) -> ZentinelResult<HttpPeer>
Select next upstream peer
Sourcepub async fn report_result(&self, target: &str, success: bool)
pub async fn report_result(&self, target: &str, success: bool)
Report connection result for a target
On failure, the circuit breaker records the failure but the load balancer health status is only updated when the circuit breaker transitions to Open. This prevents a single connection error (e.g., a stale pooled connection reset) from permanently removing a target from the healthy pool.
Sourcepub async fn report_result_with_latency(
&self,
target: &str,
success: bool,
latency: Option<Duration>,
)
pub async fn report_result_with_latency( &self, target: &str, success: bool, latency: Option<Duration>, )
Report request result with latency for adaptive load balancing
This method passes latency information to the load balancer for adaptive weight adjustment. It updates circuit breakers and health status. On failure, health is only marked down when the circuit breaker transitions to Open, preventing stale connection resets from permanently removing targets.
Sourcepub fn id(&self) -> &UpstreamId
pub fn id(&self) -> &UpstreamId
Get pool ID
Sourcepub async fn circuit_breaker_state(
&self,
target: &str,
) -> Option<CircuitBreakerState>
pub async fn circuit_breaker_state( &self, target: &str, ) -> Option<CircuitBreakerState>
Get target count
Circuit-breaker state for a target, or None when the pool has no
breaker for that address — which for a discovery-backed pool means the
target is not currently in the resolved set.
Sourcepub fn sticky_signing_key(&self) -> Option<[u8; 32]>
pub fn sticky_signing_key(&self) -> Option<[u8; 32]>
The key used to sign sticky-session affinity cookies, when this upstream uses sticky load balancing.
Exposed so tests can assert it survives a pool rebuild; rotating it would invalidate every cookie already issued.
Sourcepub fn target_addresses(&self) -> Vec<String>
pub fn target_addresses(&self) -> Vec<String>
Addresses of the pool’s current targets, in selection order.
pub fn target_count(&self) -> usize
Sourcepub fn pool_config(&self) -> PoolConfigSnapshot
pub fn pool_config(&self) -> PoolConfigSnapshot
Get pool configuration (for metrics/debugging)
Sourcepub async fn has_healthy_targets(&self) -> bool
pub async fn has_healthy_targets(&self) -> bool
Check if the pool has any healthy targets.
Returns true if at least one target is healthy, false if all targets are unhealthy.
Sourcepub async fn select_shadow_target(
&self,
context: Option<&RequestContext>,
) -> ZentinelResult<ShadowTarget>
pub async fn select_shadow_target( &self, context: Option<&RequestContext>, ) -> ZentinelResult<ShadowTarget>
Select a target for shadow traffic (returns URL components)
This is a simplified selection method for shadow requests that don’t need full HttpPeer setup. Returns the target URL scheme, address, and port.
Sourcepub fn is_tls_enabled(&self) -> bool
pub fn is_tls_enabled(&self) -> bool
Check if TLS is enabled for this upstream
Sourcepub fn active_request_count(&self) -> u64
pub fn active_request_count(&self) -> u64
Get the number of currently active (in-flight) requests for this pool.
Used by the drain tracker to determine when a pool has been fully drained after removal from config.
Sourcepub fn increment_active(&self)
pub fn increment_active(&self)
Increment the active request counter. Called when a request is assigned to this pool.
Sourcepub fn decrement_active(&self)
pub fn decrement_active(&self)
Decrement the active request counter. Called when a request completes (success or failure).
Auto Trait Implementations§
impl !RefUnwindSafe for UpstreamPool
impl !UnwindSafe for UpstreamPool
impl Freeze for UpstreamPool
impl Send for UpstreamPool
impl Sync for UpstreamPool
impl Unpin for UpstreamPool
impl UnsafeUnpin for UpstreamPool
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more