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

Pr 4 #4

Open
wants to merge 5 commits into
base: pr-3
Choose a base branch
from
Open

Pr 4 #4

wants to merge 5 commits into from

Conversation

petttr1
Copy link
Collaborator

@petttr1 petttr1 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.

@@ -57,7 +56,12 @@ pub(super) async fn new_gateway(config: Option<engine_v2::VersionedConfig>) -> O
.into_iter()
.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.

@@ -4,7 +4,10 @@ use grafbase_telemetry::{
gql_response_status::{GraphqlResponseStatus, SubgraphResponseStatus},
span::{GqlRecorderSpanExt, GRAFBASE_TARGET},
};
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