Skip to content

Implement additional rate limiter for v2 API calls - #2882

Merged
johha merged 2 commits into
cloudfoundry:mainfrom
sap-contributions:v2-api-rate-limiter
Aug 2, 2022
Merged

johha merged 2 commits into
cloudfoundry:mainfrom
sap-contributions:v2-api-rate-limiter

Conversation

@johha

@johha johha commented Jul 25, 2022 •

Copy link
Copy Markdown
Member
  • A explanation of the proposed change:

    As v2 API is deprecated and v3 API has in general a better performance (at least on big foundations) we want to motivate users to migrate to v3 API.
    We want to add a rate limiter for v2 API calls as an additional 'motivator'. This rate limiter distinguishes between requests from admin and regular users. It is disabled per default and can be configured by operators.

    The v2 rate limiter reuses the logic of the general rate limiter. Main differences are the paths on which the rate limit will be skipped and the error messages.
    To improve reuse between the general rate limiter and v2 rate limiter we introduced a base rate limiter which contains most of the logic (move over from general rate limiter).
    This will also make it easier to implement further requests limiter.

    If enabled users will see the following additional headers

    X-Ratelimit-Limit-V2-Api: 100
    X-Ratelimit-Remaining-V2-Api: 0
    X-Ratelimit-Reset-V2-Api: 1658755978
    
  • An explanation of the use cases your change solves
    As an operator I want to rate limit v2 API calls for regular (incl. unauthenticated) and admin users

  • Links to any other associated PRs

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

- Make RequestCounter Singleton reusable
- Introduce abstract/base rate limiter
- Adopt existing rate limiter to new structure
- Introduce helper class for rate limit headers
@johha
johha force-pushed the v2-api-rate-limiter branch from 1dae194 to efdd0d4 Compare July 25, 2022 15:38
Comment thread middleware/base_rate_limiter.rb Resolved
Comment thread middleware/base_rate_limiter.rb Resolved
Comment thread middleware/base_rate_limiter.rb Resolved
Comment thread middleware/base_rate_limiter.rb Resolved
Comment thread middleware/rate_limiter_v2_api.rb Resolved
Comment thread middleware/rate_limiter_v2_api.rb Resolved
Comment thread middleware/base_rate_limiter.rb Resolved
Comment thread middleware/base_rate_limiter.rb Resolved
Comment thread middleware/base_rate_limiter.rb Resolved
- Replace 'skip_rate_limiting' with 'apply_rate_limiting'
- Code cleanup
- Improve signatures & code structure
- Use shared test examples
- Fix admin test
johha added a commit to sap-contributions/capi-release that referenced this pull request Jul 26, 2022
@johha

johha commented Jul 26, 2022

Copy link
Copy Markdown
Member Author

Related PR for configuration in capi-release: cloudfoundry/capi-release#254

@johha
johha marked this pull request as ready for review July 27, 2022 06:25
johha added a commit to sap-contributions/capi-release that referenced this pull request Jul 29, 2022
johha added a commit to sap-contributions/capi-release that referenced this pull request Jul 29, 2022
@johha
johha merged commit 141d1da into cloudfoundry:main Aug 2, 2022
@johha
johha deleted the v2-api-rate-limiter branch August 2, 2022 07:10
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