Skip to main content

envoy/rate_limit/
config.rs

1//! Rate limit configuration.
2
3use serde::{Deserialize, Serialize};
4
5/// Rate limit configuration.
6///
7/// Can be loaded from config file or constructed programmatically.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct RateLimitConfig {
10    /// Maximum tokens per agent (capacity).
11    pub max_tokens: u64,
12
13    /// Tokens replenished per second.
14    pub replenish_rate: u64,
15
16    /// Burst capacity (short-term allowance above max_tokens).
17    pub burst_size: u64,
18}
19
20impl Default for RateLimitConfig {
21    fn default() -> Self {
22        Self {
23            max_tokens: 100_000,
24            replenish_rate: 50_000,
25            burst_size: 200_000,
26        }
27    }
28}
29
30impl RateLimitConfig {
31    pub fn new(max_tokens: u64, replenish_rate: u64, burst_size: u64) -> Self {
32        Self {
33            max_tokens,
34            replenish_rate,
35            burst_size,
36        }
37    }
38}