github-insights / github-metrics

0 stars 0 forks source link

GitHub API rate limit handling #128

Open tomellm opened 1 month ago

tomellm commented 1 month ago

The GitHub API uses rate limiting to avoid clients from sending too many requests: https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28

When making calls to the Rest API you'll notice the following response headers:

X-Ratelimit-Limit: 5000
X-Ratelimit-Remaining: 4999
X-Ratelimit-Reset: 1712830913
X-Ratelimit-Resource: core
X-Ratelimit-Used: 1

Find a way to make our client code respect these rate limits. Other people probably already solved this problem in Spring Boot apps so make sure to spend some time to investigate existing solutions instead of diving directly in code.

Resilience4j optional. Maybe as a separate ticket.

tomellm commented 1 month ago

consider how the rate limiting is tied to different tokes, meaning is it bound to the installation token or the app or whatever

tomellm commented 1 month ago

Initial idea is the following. The number of requests we can do is relative to a specific time-frame this means we have a max req/min. Knowing what the limit req/min is I can now create a interceptor that will check if we are making more or less requests compared to the max req/min. If we do end up making more then the max what the interceptor will do is influence the rate at which cache eviction is being done. All cache eviction is on a schedule that is specified by each cache themselves but it is dependent on a multiplier which is the thing the interceptor changes. If the interceptor deems that there are too many requests being made then it will set this multiplier higher meaning less requests are being made. Otherwise it will drop it until reaching 1 where the cache eviction is being done on the default schedule. Some things to consider here are: