relay_quotas

Struct RedisRateLimiter

source
pub struct RedisRateLimiter { /* private fields */ }
Expand description

A service that executes quotas and checks for rate limits in a shared cache.

Quotas handle tracking a project’s usage and respond whether or not a project has been configured to throttle incoming data if they go beyond the specified quota.

Quotas can specify a window to be tracked in, such as per minute or per hour. Additionally, quotas allow to specify the data categories they apply to, for example error events or attachments. For more information on quota parameters, see QuotaConfig.

Requires the redis feature.

Implementations§

source§

impl RedisRateLimiter

source

pub fn new(pool: RedisPool) -> Self

Creates a new RedisRateLimiter instance.

source

pub fn max_limit(self, max_limit: Option<u64>) -> Self

Sets the maximum rate limit in seconds.

By default, this rate limiter will return rate limits based on the quotas’ window fields. If a maximum rate limit is set, this limit is bounded.

source

pub fn is_rate_limited<'a>( &self, quotas: impl IntoIterator<Item = &'a Quota>, item_scoping: ItemScoping<'_>, quantity: usize, over_accept_once: bool, ) -> Result<RateLimits, RateLimitingError>

Checks whether any of the quotas in effect for the given project and project key has been exceeded and records consumption of the quota.

By invoking this method, the caller signals that data is being ingested and needs to be counted against the quota. This increment happens atomically if none of the quotas have been exceeded. Otherwise, a rate limit is returned and data is not counted against the quotas.

If no key is specified, then only organization-wide and project-wide quotas are checked. If a key is specified, then key-quotas are also checked.

If the current consumed quotas are still under the limit and the current quantity would put it over the limit, which normaly would return the rejection, setting over_accept_once to true will allow accept the incoming data even if the limit is exceeded once.

The passed quantity may be 0. In this case, the rate limiter will check if the quota limit has been reached or exceeded without incrementing it in the success case. This can be useful to check for required quotas in a different data category.

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.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T