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

Add concurrent request limiter and implement it in GitHub integration #1603

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

garrrikkotua
Copy link
Contributor

@garrrikkotua garrrikkotua commented Oct 2, 2023

Changes proposed ✍️

What

🤖 Generated by Copilot at 83de21a

This pull request adds a concurrent request limiter feature for the GitHub GraphQL queries used by the integrations service. The feature uses a RedisCache to store and update the number of concurrent requests for each integration and prevents exceeding the GitHub API rate limit. The feature is implemented in the rateLimiter.ts file and the caching.ts file, and is used by the BaseQuery class and its subclasses in the graphql folder. The feature is also applied to the processStream.ts and processWebhookStream.ts files, which handle the GitHub integration streams.

🤖 Generated by Copilot at 83de21a

Sing, O Muse, of the valiant code warriors who strove
To tame the mighty GitHub, whose queries they wove
With skill and cunning, using ConcurrentRequestLimiter
And RedisCache, the swift and subtle decrementer.

Why

How

🤖 Generated by Copilot at 83de21a

  • Add and implement a concurrent request limiter for the GitHub GraphQL queries to avoid exceeding the rate limit of 2 concurrent requests per integration (link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link)
  • Create a new interface IConcurrentRequestLimiter and a new type Limiter in the caching.ts file to define the concurrent request limiter logic and its parameters (link,link)
  • Implement the IConcurrentRequestLimiter interface in the ConcurrentRequestLimiter class in the rateLimiter.ts file, which uses a cache to store and update the current number of concurrent requests for each integration, and a timeout function to implement a delay mechanism (link,link)
  • Implement a new decrement method in the ICache interface and the RedisCache class to support the concurrent request limiter logic (link,link)
  • Add a new optional parameter limiter of type Limiter to the getSinglePage method of the BaseQuery class in the baseQuery.ts file, and add a conditional logic to use the processWithLimit method of the limiter.concurrentRequestLimiter to execute the GraphQL query with the concurrent request limit (link,link,link)
  • Add a new function getConcurrentRequestLimiter to the processStream.ts file, which creates a singleton concurrent request limiter for each GitHub integration using the ctx.cache and the github-concurrent-request-limiter key (link,link)
  • Add the concurrent request limiter and the integration ID to the getSinglePage method calls of the various GitHub GraphQL query classes in the processStream.ts and processWebhookStream.ts files, which handle the processing of different types of GitHub streams (link,link,link,link,link,link,link,link,link,link,link,link,link,link,link)

Checklist ✅

  • Label appropriately with Feature, Improvement, or Bug.
  • Add screehshots to the PR description for relevant FE changes
  • New backend functionality has been unit-tested.
  • API documentation has been updated (if necessary) (see docs on API documentation).
  • Quality standards are met.

@garrrikkotua garrrikkotua merged commit f410c2b into main Oct 2, 2023
8 checks passed
@garrrikkotua garrrikkotua deleted the fix/prevent-secondary-rate-limits branch October 2, 2023 10:59
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

2 participants