pingora_load_balancing

Struct Backends

Source
pub struct Backends { /* private fields */ }
Expand description

Backends is a collection of Backends.

It includes a service discovery method (static or dynamic) to discover all the available backends as well as an optional health check method to probe the liveness of each backend.

Implementations§

Source§

impl Backends

Source

pub fn new(discovery: Box<dyn ServiceDiscovery + Send + Sync + 'static>) -> Self

Create a new Backends with the given ServiceDiscovery implementation.

The health check method is by default empty.

Source

pub fn set_health_check( &mut self, hc: Box<dyn HealthCheck + Send + Sync + 'static>, )

Set the health check method. See health_check for the methods provided.

Source

pub fn ready(&self, backend: &Backend) -> bool

Whether a certain Backend is ready to serve traffic.

This function returns true when the backend is both healthy and enabled. This function returns true when the health check is unset but the backend is enabled. When the health check is set, this function will return false for the backend it doesn’t know.

Source

pub fn set_enable(&self, backend: &Backend, enabled: bool)

Manually set if a Backend is ready to serve traffic.

This method does not override the health of the backend. It is meant to be used to stop a backend from accepting traffic when it is still healthy.

This method is noop when the given backend doesn’t exist in the service discovery.

Source

pub fn get_backend(&self) -> Arc<BTreeSet<Backend>>

Return the collection of the backends.

Source

pub async fn update<F>(&self, callback: F) -> Result<()>
where F: Fn(Arc<BTreeSet<Backend>>),

Call the service discovery method to update the collection of backends.

The callback will be invoked when the new set of backend is different from the current one so that the caller can update the selector accordingly.

Source

pub async fn run_health_check(&self, parallel: bool)

Run health check on all backends if it is set.

When parallel: true, all backends are checked in parallel instead of sequentially

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more