-
Notifications
You must be signed in to change notification settings - Fork 55
LCORE-741: quota limiters in configuration #721
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
LCORE-741: quota limiters in configuration #721
Conversation
WalkthroughAdds quota-handling accessors to AppConfig: introduces a cached private Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Caller
participant AppConfig as AppConfig
participant Factory as QuotaLimiterFactory
Caller->>AppConfig: access quota_limiters
alt first access (_quota_limiters is None)
AppConfig->>AppConfig: ensure configuration loaded (or raise LogicError)
AppConfig->>Factory: QuotaLimiterFactory.quota_limiters(quota_handlers_config)
Factory-->>AppConfig: list[QuotaLimiter]
AppConfig->>AppConfig: cache in _quota_limiters
AppConfig-->>Caller: return list[QuotaLimiter]
else subsequent access (cached)
AppConfig-->>Caller: return cached _quota_limiters
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
83e0de7 to
24d3a9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/configuration.py(4 hunks)tests/unit/test_configuration.py(2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use absolute imports for internal modules (e.g., from auth import get_auth_dependency)
Files:
src/configuration.py
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.py: All modules start with descriptive module-level docstrings explaining purpose
Use logger = logging.getLogger(name) for module logging after import logging
Define type aliases at module level for clarity
All functions require docstrings with brief descriptions
Provide complete type annotations for all function parameters and return types
Use typing_extensions.Self in model validators where appropriate
Use modern union syntax (str | int) and Optional[T] or T | None consistently
Function names use snake_case with descriptive, action-oriented prefixes (get_, validate_, check_)
Avoid in-place parameter modification; return new data structures instead of mutating arguments
Use appropriate logging levels: debug, info, warning, error with clear messages
All classes require descriptive docstrings explaining purpose
Class names use PascalCase with conventional suffixes (Configuration, Error/Exception, Resolver, Interface)
Abstract base classes should use abc.ABC and @AbstractMethod for interfaces
Provide complete type annotations for all class attributes
Follow Google Python docstring style for modules, classes, and functions, including Args, Returns, Raises, Attributes sections as needed
Files:
src/configuration.pytests/unit/test_configuration.py
src/{models/config.py,configuration.py}
📄 CodeRabbit inference engine (CLAUDE.md)
src/{models/config.py,configuration.py}: All configuration uses Pydantic models extending ConfigurationBase
Configuration base models must set model_config with extra="forbid" to reject unknown fields
Files:
src/configuration.py
src/{models/**/*.py,configuration.py}
📄 CodeRabbit inference engine (CLAUDE.md)
src/{models/**/*.py,configuration.py}: Use @field_validator and @model_validator for custom validation in Pydantic models
Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
Files:
src/configuration.py
tests/{unit,integration}/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
tests/{unit,integration}/**/*.py: Use pytest for all unit and integration tests
Do not use unittest in tests; pytest is the standard
Files:
tests/unit/test_configuration.py
tests/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
tests/**/*.py: Use pytest-mock to create AsyncMock objects for async interactions in tests
Use the shared auth mock constant: MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") in tests
Files:
tests/unit/test_configuration.py
🧬 Code graph analysis (2)
src/configuration.py (3)
src/models/config.py (1)
QuotaHandlersConfiguration(584-593)src/quota/quota_limiter.py (1)
QuotaLimiter(19-93)src/quota/quota_limiter_factory.py (1)
QuotaLimiterFactory(17-66)
tests/unit/test_configuration.py (1)
src/configuration.py (5)
quota_handlers_configuration(151-155)conversation_cache(158-166)quota_limiters(169-177)AppConfig(39-177)load_configuration(56-62)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: build-pr
- GitHub Check: e2e_tests (azure)
- GitHub Check: e2e_tests (ci)
🔇 Additional comments (5)
tests/unit/test_configuration.py (3)
81-83: LGTM! Consistent error handling test.The test correctly verifies that accessing
quota_handlers_configurationbefore loading configuration raises the expected error, following the same pattern as other configuration property tests.
89-91: LGTM! Consistent error handling test.The test correctly verifies that accessing
quota_limitersbefore loading configuration raises the expected error.
742-806: LGTM! Comprehensive quota handlers test.The test thoroughly verifies quota handlers configuration with storage, including:
- Storage configuration
- Number of limiters created
- Specific string representations of limiters
- Scheduler configuration
The string representation assertions provide good validation of the actual limiter instances created by the factory.
src/configuration.py (2)
23-23: LGTM! Imports follow conventions.The new imports for quota handling functionality follow the existing import patterns and coding guidelines for absolute imports.
Also applies to: 29-30
150-155: LGTM! Consistent configuration accessor.The
quota_handlers_configurationproperty correctly follows the established pattern for configuration accessors, including proper error handling when configuration is not loaded.
24d3a9c to
b312f60
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/configuration.py (1)
172-181: LGTM with optional improvement suggestion.The lazy initialization pattern correctly mirrors
conversation_cacheand properly caches the quota limiters after first access. The implementation is functionally correct.Optional improvement: When
QuotaLimiterFactory.quota_limiters()legitimately returns an empty list (e.g., no storage configured), the conditionif not self._quota_limiters:will remain True on every access, causing repeated factory calls. Consider using a sentinel pattern:def __init__(self) -> None: """Initialize the class instance.""" self._configuration: Optional[Configuration] = None self._conversation_cache: Optional[Cache] = None - self._quota_limiters: list[QuotaLimiter] = [] + self._quota_limiters: Optional[list[QuotaLimiter]] = Nonedef init_from_dict(self, config_dict: dict[Any, Any]) -> None: """Initialize configuration from a dictionary.""" # clear cached values when configuration changes self._conversation_cache = None - self._quota_limiters = [] + self._quota_limiters = None # now it is possible to re-read configuration self._configuration = Configuration(**config_dict)@property def quota_limiters(self) -> list[QuotaLimiter]: """Return list of all setup quota limiters.""" if self._configuration is None: raise LogicError("logic error: configuration is not loaded") - if not self._quota_limiters: + if self._quota_limiters is None: self._quota_limiters = QuotaLimiterFactory.quota_limiters( self._configuration.quota_handlers ) return self._quota_limitersThis avoids repeated factory invocation when the factory returns an empty list, though the current implementation is acceptable given minimal impact.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/configuration.py(5 hunks)tests/unit/test_configuration.py(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/unit/test_configuration.py
🧰 Additional context used
📓 Path-based instructions (4)
src/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use absolute imports for internal modules (e.g., from auth import get_auth_dependency)
Files:
src/configuration.py
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.py: All modules start with descriptive module-level docstrings explaining purpose
Use logger = logging.getLogger(name) for module logging after import logging
Define type aliases at module level for clarity
All functions require docstrings with brief descriptions
Provide complete type annotations for all function parameters and return types
Use typing_extensions.Self in model validators where appropriate
Use modern union syntax (str | int) and Optional[T] or T | None consistently
Function names use snake_case with descriptive, action-oriented prefixes (get_, validate_, check_)
Avoid in-place parameter modification; return new data structures instead of mutating arguments
Use appropriate logging levels: debug, info, warning, error with clear messages
All classes require descriptive docstrings explaining purpose
Class names use PascalCase with conventional suffixes (Configuration, Error/Exception, Resolver, Interface)
Abstract base classes should use abc.ABC and @AbstractMethod for interfaces
Provide complete type annotations for all class attributes
Follow Google Python docstring style for modules, classes, and functions, including Args, Returns, Raises, Attributes sections as needed
Files:
src/configuration.py
src/{models/config.py,configuration.py}
📄 CodeRabbit inference engine (CLAUDE.md)
src/{models/config.py,configuration.py}: All configuration uses Pydantic models extending ConfigurationBase
Configuration base models must set model_config with extra="forbid" to reject unknown fields
Files:
src/configuration.py
src/{models/**/*.py,configuration.py}
📄 CodeRabbit inference engine (CLAUDE.md)
src/{models/**/*.py,configuration.py}: Use @field_validator and @model_validator for custom validation in Pydantic models
Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
Files:
src/configuration.py
🧬 Code graph analysis (1)
src/configuration.py (4)
src/models/config.py (1)
QuotaHandlersConfiguration(584-593)src/cache/cache_factory.py (1)
CacheFactory(16-49)src/quota/quota_limiter.py (1)
QuotaLimiter(19-93)src/quota/quota_limiter_factory.py (1)
QuotaLimiterFactory(17-66)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: build-pr
- GitHub Check: e2e_tests (ci)
- GitHub Check: e2e_tests (azure)
🔇 Additional comments (4)
src/configuration.py (4)
23-23: LGTM! Imports follow guidelines.The quota handling imports are necessary for the new functionality and follow the absolute import pattern as per coding guidelines.
Also applies to: 29-30
54-54: LGTM! Proper initialization with type annotation.The
_quota_limitersattribute is correctly initialized with a complete type annotation that matches the property return type.
64-70: Excellent fix! Cache invalidation now properly implemented.The cache clearing for both
_conversation_cacheand_quota_limitersbefore reloading configuration correctly addresses the critical cache invalidation issue flagged in previous reviews. This ensures quota limiters and conversation cache reflect the newly loaded configuration rather than stale values.
154-159: LGTM! Property follows established patterns.The
quota_handlers_configurationproperty correctly follows the same pattern as other configuration accessors, with consistent error handling and proper type annotations.
Description
LCORE-741: quota limiters in configuration
Type of change
Related Tickets & Documents
Summary by CodeRabbit
New Features
Bug Fixes
Tests