Skip to content

Commit

Permalink
chore(boundary): adapt rate-limit rule definition (#2678)
Browse files Browse the repository at this point in the history
This definition would allow to `rate-limit` on multiple request types:
```
pub struct RateLimitRule {
   ...
    pub request_types: Option<Vec<RequestType>>,
   ...
}
```

Co-authored-by: IDX GitLab Automation <[email protected]>
  • Loading branch information
nikolay-komarevskiy and IDX GitLab Automation authored Nov 19, 2024
1 parent 2f00d68 commit 9b4497b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rs/boundary_node/rate_limits/api/src/schema_versions/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct RateLimitRule {
pub canister_id: Option<Principal>,
pub subnet_id: Option<Principal>,
pub methods_regex: Option<String>,
pub request_type: Option<RequestType>,
pub request_types: Option<Vec<RequestType>>,
pub limit: String,
}

Expand Down
16 changes: 8 additions & 8 deletions rs/boundary_node/rate_limits/canister_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,31 @@ async fn add_config_1(agent: &Agent, canister_id: Principal) {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_1)$".to_string()),
request_type: Some(RequestType::Call),
request_types: Some(vec![RequestType::Call]),
limit: "1req/s".to_string(),
};

let rule_2 = RateLimitRule {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_2)$".to_string()),
request_type: Some(RequestType::Query),
request_types: Some(vec![RequestType::Query]),
limit: "2req/s".to_string(),
};

let rule_3 = RateLimitRule {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_3)$".to_string()),
request_type: None,
request_types: None,
limit: "3req/s".to_string(),
};

let rule_4 = RateLimitRule {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_4)$".to_string()),
request_type: Some(RequestType::ReadState),
request_types: Some(vec![RequestType::ReadState]),
limit: "4req/s".to_string(),
};

Expand Down Expand Up @@ -160,15 +160,15 @@ async fn add_config_2(agent: &Agent, canister_id: Principal) {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_1)$".to_string()),
request_type: Some(RequestType::Call),
request_types: Some(vec![RequestType::Call]),
limit: "1req/s".to_string(),
};

let rule_2 = RateLimitRule {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_2)$".to_string()),
request_type: Some(RequestType::Query),
request_types: Some(vec![RequestType::Query]),
limit: "2req/s".to_string(),
};

Expand All @@ -177,15 +177,15 @@ async fn add_config_2(agent: &Agent, canister_id: Principal) {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_33)$".to_string()),
request_type: None,
request_types: None,
limit: "33req/s".to_string(),
};

let rule_4 = RateLimitRule {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_4)$".to_string()),
request_type: Some(RequestType::ReadState),
request_types: Some(vec![RequestType::ReadState]),
limit: "4req/s".to_string(),
};

Expand Down
16 changes: 8 additions & 8 deletions rs/tests/boundary_nodes/rate_limit_canister_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,31 +167,31 @@ async fn add_config_1(logger: Logger, agent: &Agent, canister_id: Principal) {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_1)$".to_string()),
request_type: Some(RequestType::Call),
request_types: Some(vec![RequestType::Call]),
limit: "1req/s".to_string(),
};

let rule_2 = RateLimitRule {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_2)$".to_string()),
request_type: Some(RequestType::Query),
request_types: Some(vec![RequestType::Query]),
limit: "2req/s".to_string(),
};

let rule_3 = RateLimitRule {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_3)$".to_string()),
request_type: None,
request_types: None,
limit: "3req/s".to_string(),
};

let rule_4 = RateLimitRule {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_4)$".to_string()),
request_type: Some(RequestType::ReadState),
request_types: Some(vec![RequestType::ReadState]),
limit: "4req/s".to_string(),
};

Expand Down Expand Up @@ -244,15 +244,15 @@ async fn add_config_2(logger: Logger, agent: &Agent, canister_id: Principal) {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_1)$".to_string()),
request_type: Some(RequestType::Call),
request_types: Some(vec![RequestType::Call]),
limit: "1req/s".to_string(),
};

let rule_2 = RateLimitRule {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_2)$".to_string()),
request_type: Some(RequestType::Query),
request_types: Some(vec![RequestType::Query]),
limit: "2req/s".to_string(),
};

Expand All @@ -261,15 +261,15 @@ async fn add_config_2(logger: Logger, agent: &Agent, canister_id: Principal) {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_33)$".to_string()),
request_type: None,
request_types: None,
limit: "33req/s".to_string(),
};

let rule_4 = RateLimitRule {
canister_id: Some(canister_id),
subnet_id: None,
methods_regex: Some(r"^(method_4)$".to_string()),
request_type: Some(RequestType::ReadState),
request_types: Some(vec![RequestType::ReadState]),
limit: "4req/s".to_string(),
};

Expand Down

0 comments on commit 9b4497b

Please sign in to comment.