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

[ENH]: add rate limiting #1728

Merged
merged 2 commits into from
Feb 28, 2024
Merged

[ENH]: add rate limiting #1728

merged 2 commits into from
Feb 28, 2024

Conversation

nicolasgere
Copy link
Contributor

@nicolasgere nicolasgere commented Feb 16, 2024

Description of changes

Summarize the changes made by this PR.

  • New functionality
    • Add rate limiting service. If no rate limit service is provided, it will not do anything.

Test plan

How are these changes tested?
Unit test on rate limiting service.

  • Test

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

@nicolasgere nicolasgere changed the title add rate limiting WIP: add rate limiting Feb 16, 2024
Copy link

github-actions bot commented Feb 16, 2024

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@nicolasgere nicolasgere requested review from jeffchuber, atroyn, beggers and tazarov and removed request for atroyn February 20, 2024 17:43
@nicolasgere nicolasgere changed the title WIP: add rate limiting [ENH]: add rate limiting Feb 22, 2024
Copy link
Contributor

@tazarov tazarov left a comment

Choose a reason for hiding this comment

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

This looks good. Couple of small nits

@@ -142,6 +143,7 @@ def __init__(self, settings: Settings):
allow_methods=["*"],
)
self._app.add_exception_handler(QuotaError, self.quota_exception_handler)
self._app.add_exception_handler(RateLimitError, self.rate_limit_exception_handler)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to define a separate exception handler for each exception? Can the existing one be reused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am following fastApi way of doing it, can be easily change if needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to add this if it does not provide any value? I understand adding a simple implementation that does something bare minimum.

@patch('chromadb.quota.test_provider.QuotaProviderForTest.get_for_subject', mock_get_for_subject)
@patch('chromadb.rate_limiting.test_provider.RateLimitingTestProvider.is_allowed', lambda self, key, quota, point=1: False)
def test_rate_limiting_should_raise(rate_limiting_gym: RateLimitingGym):
with pytest.raises(Exception) as exc_info:
Copy link
Contributor

Choose a reason for hiding this comment

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

a simple syntax for this is:

with pytest.raises(Exception,matches="FAKE_RESOURCE") as exc_info:
...

from chromadb.quota import QuotaProvider, Resource


class RateLimitError(Exception):
Copy link
Contributor

Choose a reason for hiding this comment

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

As a follow up to the new errors I think we should handle that on client-side with some sort of exponential back-off.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed but I don't think it needs to be done as part of this PR. In general I see client work as significantly less important than server work, especially as we move towards Cloud launch (I expect many customers to roll their own clients)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see client work as significantly less important than server work, especially as we move towards Cloud launch (I expect many customers to roll their own clients)

I don't agree with this. The client is part of chromas experience. Cloud is targeted at developers who are in the same usage bracket and the client is a first-party part of that experience.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @HammadB here - our initial target user for cloud is not likely to roll their own.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding a task to discuss client implication.

Copy link
Member

@beggers beggers left a comment

Choose a reason for hiding this comment

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

Looks good to me

from chromadb.quota import QuotaProvider, Resource


class RateLimitError(Exception):
Copy link
Member

Choose a reason for hiding this comment

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

Agreed but I don't think it needs to be done as part of this PR. In general I see client work as significantly less important than server work, especially as we move towards Cloud launch (I expect many customers to roll their own clients)

@nicolasgere nicolasgere merged commit 5e9c7a7 into main Feb 28, 2024
118 checks passed
atroyn pushed a commit to csbasil/chroma that referenced this pull request Apr 3, 2024
## Description of changes

*Summarize the changes made by this PR.*
 - New functionality
- Add rate limiting service. If no rate limit service is provided, it
will not do anything.

## Test plan
*How are these changes tested?*
Unit test on rate limiting service.


---------

Co-authored-by: nicolas <nico@trychroma.com>
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.

None yet

5 participants