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

checkin limits implementation #1696

Merged
merged 2 commits into from
Dec 16, 2024
Merged

Conversation

emrgnt-cmplxty
Copy link
Contributor

@emrgnt-cmplxty emrgnt-cmplxty commented Dec 15, 2024

Important

Implements rate limiting for database operations with configurable limits in DatabaseConfig, enforced by PostgresLimitsHandler, and updates API and tests accordingly.

  • Rate Limiting Implementation:
    • Introduces LimitSettings in database.py to define global_per_min, route_per_min, and monthly_limit.
    • Adds limits, route_limits, and user_limits to DatabaseConfig in database.py.
    • Implements PostgresLimitsHandler in limits.py to manage request logging and limit checking.
    • Updates PostgresDatabaseProvider in postgres.py to initialize PostgresLimitsHandler.
  • Configuration:
    • Updates r2r.toml to include default and route-specific limits under [database.limits] and [database.route_limits].
    • Modifies config.py to handle new limit settings during configuration loading.
  • API Changes:
    • Adds rate limiting dependency in base_router.py to enforce limits on API routes.
  • Testing:
    • Updates test_users.py to include tests for user registration and token refresh, ensuring compliance with new limits.

This description was created by Ellipsis for 7f29118. It will automatically update as commits are pushed.

@emrgnt-cmplxty emrgnt-cmplxty marked this pull request as ready for review December 16, 2024 05:35
@emrgnt-cmplxty emrgnt-cmplxty merged commit 1ab9f90 into main Dec 16, 2024
12 of 13 checks passed
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to 7f29118 in 1 minute and 39 seconds

More details
  • Looked at 491 lines of code in 10 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. py/core/database/limits.py:93
  • Draft comment:
    The check for if not limits: is redundant since _determine_limits_for already ensures defaults are applied. Consider removing this check.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The check_limits method in PostgresLimitsHandler has a redundant check for limits being None, as the _determine_limits_for method already ensures defaults are applied.
2. py/core/main/api/v3/users_router.py:110
  • Draft comment:
    Remove print statements used for debugging in the register function. These should not be present in production code.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The print statements in the register function in users_router.py are likely for debugging and should be removed for production code.
3. py/tests/integration/test_users.py:37
  • Draft comment:
    Remove print statements used for debugging in the register_and_return_user_id function. These should not be present in production code.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The print statements in the register_and_return_user_id function in test_users.py are likely for debugging and should be removed for production code.

Workflow ID: wflow_zold39gAouls2cFO


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

def merge_with_defaults(
self, defaults: "LimitSettings"
) -> "LimitSettings":
return LimitSettings(
Copy link
Contributor

Choose a reason for hiding this comment

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

Using or to set defaults in merge_with_defaults can lead to incorrect behavior if a limit is set to 0. Consider using a more explicit check to handle 0 as a valid limit.

logger.warning(
f"Global per-minute limit exceeded for user_id={user_id}, route={route}"
)
raise ValueError("Global per-minute rate limit exceeded")
Copy link
Contributor

Choose a reason for hiding this comment

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

Using ValueError for rate limit exceptions is not ideal. Consider defining a custom exception for rate limit violations to distinguish them from other 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.

1 participant