Skip to content

Comments

Pr 4#4

Open
devslovecoffee wants to merge 5 commits intopr-3from
pr-4
Open

Pr 4#4
devslovecoffee wants to merge 5 commits intopr-3from
pr-4

Conversation

@devslovecoffee
Copy link
Collaborator

@devslovecoffee devslovecoffee commented Aug 2, 2024

Description by Cal

PR Description

This PR introduces a new rate limiting feature by refactoring the existing rate limiting context and updating the related components to use a new RateLimitKey enum. It replaces the previous RateLimiterContext with a more flexible approach using RateLimitKey for both global and subgraph rate limits.

Key Issues

None

Files Changed

File: /cli/crates/federated-dev/src/dev/gateway_nanny.rs Updated rate limiting logic to use `watch` channel instead of `mpsc`.
File: /engine/crates/engine-v2/config/src/lib.rs Removed unused constant `GLOBAL_RATE_LIMIT_KEY`.
File: /engine/crates/engine-v2/src/engine.rs Updated rate limiting checks to use the new `RateLimitKey` enum.
File: /engine/crates/runtime-local/src/rate_limiting/in_memory/key_based.rs Refactored rate limiting context to use `RateLimitKey`.
File: /gateway/crates/federated-server/src/config.rs Updated rate limit configuration to use `RateLimitKey`.
# Description

Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context.

Type of change

  • 💔 Breaking
  • 🚀 Feature
  • 🐛 Fix
  • 🛠️ Tooling
  • 🔨 Refactoring
  • 🧪 Test
  • 📦 Dependency
  • 📖 Requires documentation update

pimeys and others added 5 commits August 1, 2024 08:07
Refactor the rate limiting configuration to use tokio's `watch` channels
instead of `mpsc` channels.
Previously, the limiter Arc was being cloned instead of downgraded
inside the spawned async task, preventing the Arc from being properly
deallocated when no longer in use.
This change downgrades the limiter Arc before passing it to the async
task to ensure memory is managed correctly.
- Changed various rate limit key representations to use the common `RateLimitKey` enum.
- Updated configuration functions to return `Vec` instead of `HashMap`.
for (name, config) in config.rate_limiting_configs {
let Some(limiter) = create_limiter(config) else {
for (name, config) in updates.borrow_and_update().iter() {
let Some(limiter) = create_limiter(*config) else {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion
Ensure that the create_limiter function handles the case where config might be invalid or not as expected, to avoid potential runtime errors.

Self {
config_path,
rate_limit_sender: rate_limit_sender.into(),
rate_limit_sender,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion
Ensure that the rate_limit_sender is properly validated or checked for errors when being passed to the ConfigWatcher constructor to avoid potential runtime issues.

}

RedisRateLimiter::runtime(global_config, rx)
RedisRateLimiter::runtime(global_config, rate_limit_rx)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion
Ensure that the rate_limit_rx variable is properly handled in case of errors during runtime.

.map(|(k, v)| {
(
k.to_string(),
match k {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion
Consider handling the case where k does not match any of the expected variants. This will help prevent potential runtime errors if an unexpected value is encountered.

};
use runtime::fetch::{FetchRequest, FetchResponse};
use runtime::{
fetch::{FetchRequest, FetchResponse},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion
Consider ensuring that the RateLimitKey is properly defined and imported to avoid potential runtime errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants