Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Ratelimit module #34

Merged
merged 7 commits into from
Aug 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
comments
Signed-off-by: José Ulises Niño Rivera <junr03@users.noreply.github.com>
  • Loading branch information
junr03 committed Aug 8, 2024
commit 867e304e563ef71e69f42384b52b896d31ae4ab8
11 changes: 10 additions & 1 deletion envoyfilter/src/ratelimit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ pub fn ratelimits(ratelimits_config: Option<Vec<Ratelimit>>) -> &'static Ratelim
})
}

// The Data Structure is laid out in the following way:
// Provider -> Hash { Header -> Limit }.
// If the Header used to configure the given Limit:
// a) Has None value, then there will be N Limit keyed by the Header value.
// b) Has Some() value, then there will be 1 Limit keyed by the empty string.
// It would have been nicer to use a non-keyed limit for b). However, the type system made that option a nightmare.
pub struct RatelimitMap {
datastore: HashMap<String, HashMap<configuration::Header, DefaultKeyedRateLimiter<String>>>,
}

// This version of Header demands that the user passes a header value to match on.
#[allow(unused)]
pub struct Header {
key: String,
value: String,
}

impl Header {
pub fn into_config(self) -> configuration::Header {
fn into_config(self) -> configuration::Header {
configuration::Header {
key: self.key,
value: Some(self.value),
Expand Down Expand Up @@ -69,6 +77,7 @@ impl RatelimitMap {
new_ratelimit_map
}

#[allow(unused)]
pub fn check_limit(
&self,
provider: String,
Expand Down