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

feat: added configurable rate limiting system #205

Merged
merged 3 commits into from
Oct 26, 2024
Merged

Conversation

TeKrop
Copy link
Owner

@TeKrop TeKrop commented Oct 21, 2024

Features

  • Added configurable rate limiting system within the docker compose environment
  • HTTP 429 errors will be returned in two cases :
    • More than X r/s from the same IP
    • Entire API has been temporarily blocked by Blizzard (HTTP 403), 5 seconds timer (Redis cache)

Misc

  • Added local reverse-proxy container in compose to test the API in production-like environment

Summary by Sourcery

Implement a configurable rate limiting system to manage API request rates and prevent excessive calls, with HTTP 429 errors for violations. Enhance the Docker Compose setup with a reverse-proxy for testing, and update documentation and tests to support these changes.

New Features:

  • Introduce a configurable rate limiting system to manage API requests, returning HTTP 429 errors when limits are exceeded.

Enhancements:

  • Add a local reverse-proxy container in the Docker Compose setup to simulate a production-like environment for testing.

Build:

  • Update Docker Compose configuration to include a reverse-proxy service for testing purposes.

Documentation:

  • Update README to reflect changes in rate limiting and add instructions for launching the API in testing mode.

Tests:

  • Add tests to verify the behavior of the API when Blizzard's rate limits are reached, ensuring HTTP 429 responses are correctly returned.

@TeKrop TeKrop added the enhancement New feature or request label Oct 21, 2024
@TeKrop TeKrop self-assigned this Oct 21, 2024
Copy link
Contributor

sourcery-ai bot commented Oct 21, 2024

Reviewer's Guide by Sourcery

This pull request implements a configurable rate limiting system within the Docker Compose environment. The changes include adding HTTP 429 error responses for rate limiting cases, implementing a global rate limit for Blizzard API calls, and adding a reverse proxy container for testing in a production-like environment. The implementation involves modifications to various files to handle rate limiting logic, update configurations, and add new test cases.

Updated class diagram for rate limiting system

classDiagram
    class CacheManager {
        +is_being_rate_limited() bool
        +get_global_rate_limit_remaining_time() int
        +set_global_rate_limit() void
    }
    class Settings {
        +blizzard_rate_limit_key: str
        +blizzard_rate_limit_retry_after: int
        +rate_limit_per_second_per_ip: int
        +rate_limit_per_ip_burst: int
        +max_connections_per_ip: int
    }
    class RateLimitErrorMessage {
        +error: str
    }
    class HTTPException {
        +status_code: int
        +detail: str
        +headers: dict
    }
    CacheManager --> Settings : uses
    RateLimitErrorMessage --> HTTPException : extends
Loading

File-Level Changes

Change Details Files
Implemented rate limiting system
  • Added HTTP 429 error response for rate limiting cases
  • Implemented global rate limit for Blizzard API calls
  • Added Redis cache for storing rate limit information
  • Updated configuration settings for rate limiting
  • Modified request handling to check for rate limits before making API calls
app/common/helpers.py
app/config.py
app/common/cache_manager.py
app/main.py
app/models/errors.py
Added reverse proxy for testing
  • Created a new reverse-proxy container in Docker Compose for testing
  • Updated Makefile with new testing command
  • Modified README to include information about the testing environment
docker-compose.yml
Makefile
README.md
Updated test cases
  • Added new test cases for rate limiting scenarios
  • Modified existing tests to account for new rate limiting behavior
  • Removed outdated test cases
tests/views/test_gamemodes_route.py
tests/views/test_player_stats_route.py
tests/views/test_player_stats_summary_route.py
tests/views/test_roles_route.py
tests/views/test_hero_routes.py
tests/views/test_heroes_route.py
tests/views/test_player_career_route.py
tests/views/test_player_summary_view.py
tests/views/test_search_players_route.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @TeKrop - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟡 Complexity: 1 issue found
  • 🟡 Documentation: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@TeKrop TeKrop force-pushed the feature/rate-limiting branch from 00e6fb0 to 1f44e4b Compare October 26, 2024 13:32
Copy link

@TeKrop TeKrop merged commit b8f66de into main Oct 26, 2024
3 checks passed
@TeKrop TeKrop deleted the feature/rate-limiting branch October 26, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant