Repository navigation
initial ratelimiting implementation - #145
Merged
Merged
Conversation
tomellm
requested review from
LanderTuyteleersXplore,
YorbenAudenaert,
bavodaniels,
gerd-goemans and
henrybley
as code owners
May 22, 2024 16:27
tomellm
marked this pull request as draft
May 22, 2024 16:27
tomellm
force-pushed
the
tom/#128-initial-rate-limiting
branch
from
May 22, 2024 17:03
99ddcf1 to
80735d1
Compare
tomellm
force-pushed
the
tom/#128-initial-rate-limiting
branch
from
May 23, 2024 14:34
80735d1 to
2e4fc82
Compare
tomellm
added a commit
that referenced
this pull request
May 27, 2024
check out the PR #145 for more details
tomellm
force-pushed
the
tom/#128-initial-rate-limiting
branch
from
May 27, 2024 07:27
2e4fc82 to
d211c50
Compare
tomellm
marked this pull request as ready for review
May 27, 2024 07:28
tomellm
added a commit
that referenced
this pull request
May 27, 2024
check out the PR #145 for more details
tomellm
force-pushed
the
tom/#128-initial-rate-limiting
branch
from
May 27, 2024 07:46
d211c50 to
b0ae0a2
Compare
henrybley
reviewed
May 27, 2024
henrybley
left a comment
Contributor
There was a problem hiding this comment.
mostly looking good just the few comments
| import java.util.Optional; | ||
|
|
||
| public class ApiRateLimitState { | ||
| private static final double RATE_LIMIT_BUFFER = 0.9; |
Contributor
There was a problem hiding this comment.
this should be .env configurable
|
|
||
| @Override | ||
| public boolean freshDataCanWait() { | ||
| return this.rateLimitState.shouldDataWait(ApiRateLimitStatus.GOOD); |
Contributor
There was a problem hiding this comment.
I think all these should be .env configurable
| ROOT: INFO | ||
| githubadapter.config.ratelimiting: TRACE | ||
| githubadapter.ratelimiting: TRACE | ||
|
|
Contributor
There was a problem hiding this comment.
should this be committed? this was for your testing I assume?
tomellm
added a commit
that referenced
this pull request
May 27, 2024
check out the PR #145 for more details
tomellm
force-pushed
the
tom/#128-initial-rate-limiting
branch
from
May 27, 2024 10:54
b0ae0a2 to
30e9782
Compare
check out the PR #145 for more details
tomellm
force-pushed
the
tom/#128-initial-rate-limiting
branch
from
May 27, 2024 11:04
30e9782 to
16d5690
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This is our initial idea on how to implement some kind of rate limiting in the system. Please consider that this is still in progress and in no way done so there definitely are a few dumb mistakes in here.
Overview
The general idea is the following. On every request we can know how our rate-limiting stats. This allows us to adjust requests so that we don't hit the rate-limit. To adjust the number of requests being made we decided to have a kind of status based system. The
github-adaptertracks the rate-limit stats and updates this status accordingly. With this status we can then decide for every adapter individually if makes sense to keep fetching new data or to wait it out until the limit improves.Implementation
To be able to decide when to make a request and when not to we though changing the way scheduling works was needed.
Before
the exporters defined a schedule on which the the Github Api was hit. The caching layer existed because some exporters needed the same Api paths leading to redundand requests.
Now
the exporters have been decoupled from the Github Api. The exporters run periodically very 30s but they practically always hit the caches. These caches are now evicted on the schedule that exporters were running before. Functionally this is the same as before, but compared to before this allows us to decide not to evict the cache if nessesary, which is what we are doing.
Every Adapter implementation then looks at the current Ratelimit status, which is one of the following:
github-metrics/domain/src/main/java/be/xplore/githubmetrics/domain/apistate/ApiRateLimitStatus.java
Lines 5 to 8 in 99ddcf1
and decides whether to cache evict or not.
Changing the status
To look at the headers of every response gotten I decided to use a interceptor on the RestClient. This interceptor looks at the ratio of requests made to time passed and compares it to a "ideal" ratio. This ideal ratio is simply calculated from the ratelimit state. When comparing the "actual" and the "ideal" ratio we can then set the status. The "ideal" ratio times one of these multiplies should be less or equal to the "actual" to result in the following statuses.
*Consider that even tho the status may jump from OK to CRITICAL it can only go down one step at a time.