| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Fixes LinearRateLimiter#isLimited to report the remaining time until a permission can be acquired (as documented), preventing overly-early rescheduling of rate-limited resources.
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiter.java | Switches isLimited from reporting elapsed time to reporting remaining time in the refresh period. |
| operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiterTest.java | Updates and adds tests to distinguish “remaining” vs “elapsed” duration behavior. |
Sorry, something went wrong.
`RateLimiter.isLimited` is documented to return the "minimal duration
until a permission could be acquired again", but `LinearRateLimiter`
returned the time *elapsed* since the current period started:
Duration.between(actualState.getLastRefreshTime(), LocalDateTime.now())
The two are inverted. Measured with a 1000ms refresh period:
moment reported correct
right after limit hit 19ms ~1000ms
800ms into the period 804ms ~200ms
`EventProcessor.handleRateLimitedSubmission` feeds this value straight
into `TimerEventSource.scheduleOnce`, so a rate-limited resource is
rescheduled almost immediately after the limit is reached (floored at
MINIMAL_RATE_LIMIT_RESCHEDULE_DURATION), gets rate-limited again, and
repeats — producing a burst of pointless timer events. Conversely, a
resource limited near the end of a period waits roughly a full extra
period after a permission was already available.
Now returns the time until the current period ends, clamped at zero.
`returnsMinimalDurationToAcquirePermission` only asserted
`isLessThan(REFRESH_PERIOD)`, which held for both the correct and the
inverted value; it now also asserts the reported wait is close to the
full period. A second test asserts the reported duration shrinks as the
period elapses, which is what distinguishes remaining from elapsed. Both
fail without this change.
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiter.java:70
var remaining =
Duration.between(
LocalDateTime.now(), actualState.getLastRefreshTime().plus(refreshPeriod));
return Optional.of(remaining.isNegative() ? Duration.ZERO : remaining);
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiter.java:66
var now = LocalDateTime.now();
if (actualState.getCount() < limitForPeriod) {
actualState.increaseCount();
return Optional.empty();
} else if (actualState.getLastRefreshTime().isBefore(now.minus(refreshPeriod))) {
actualState.reset();
actualState.increaseCount();
return Optional.empty();
} else {
var remaining = Duration.between(now, actualState.getLastRefreshTime().plus(refreshPeriod));
return Optional.of(remaining.isNegative() ? Duration.ZERO : remaining);
operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiterTest.java:68
void reportedDurationIsTheTimeRemainingNotTheTimeElapsed() throws InterruptedException {
var rl = new LinearRateLimiter(REFRESH_PERIOD, 1);
assertThat(rl.isLimited(state)).isEmpty();
var justAfterLimit = rl.isLimited(state).orElseThrow();
Thread.sleep(REFRESH_PERIOD.toMillis() / 2);
var halfWayThroughPeriod = rl.isLimited(state).orElseThrow();
Sorry, something went wrong.
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiter.java:60
} else if (actualState.getLastRefreshTime().isBefore(now.minus(refreshPeriod))) {
operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/rate/LinearRateLimiterTest.java:72
assertThat(rl.isLimited(state)).isEmpty();
var justAfterLimit = rl.isLimited(state).orElseThrow();
Thread.sleep(REFRESH_PERIOD.toMillis() / 2);
var halfWayThroughPeriod = rl.isLimited(state).orElseThrow();
Sorry, something went wrong.
…ator-framework#3521) ] `RateLimiter.isLimited` is documented to return the "minimal duration until a permission could be acquired again", but `LinearRateLimiter` returned the time *elapsed* since the current period started: Duration.between(actualState.getLastRefreshTime(), LocalDateTime.now()) The two are inverted. Measured with a 1000ms refresh period: moment reported correct right after limit hit 19ms ~1000ms 800ms into the period 804ms ~200ms `EventProcessor.handleRateLimitedSubmission` feeds this value straight into `TimerEventSource.scheduleOnce`, so a rate-limited resource is rescheduled almost immediately after the limit is reached (floored at MINIMAL_RATE_LIMIT_RESCHEDULE_DURATION), gets rate-limited again, and repeats — producing a burst of pointless timer events. Conversely, a resource limited near the end of a period waits roughly a full extra period after a permission was already available. Now returns the time until the current period ends, clamped at zero. `returnsMinimalDurationToAcquirePermission` only asserted `isLessThan(REFRESH_PERIOD)`, which held for both the correct and the inverted value; it now also asserts the reported wait is close to the full period. A second test asserts the reported duration shrinks as the period elapses, which is what distinguishes remaining from elapsed. Both fail without this change. Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
| Back | FazBrowse Home | New Git URL |
RateLimiter.isLimited is documented to return the "minimal duration
until a permission could be acquired again", but LinearRateLimiter
returned the time elapsed since the current period started:
The two are inverted. Measured with a 1000ms refresh period:
EventProcessor.handleRateLimitedSubmission feeds this value straight
into TimerEventSource.scheduleOnce, so a rate-limited resource is
rescheduled almost immediately after the limit is reached (floored at
MINIMAL_RATE_LIMIT_RESCHEDULE_DURATION), gets rate-limited again, and
repeats — producing a burst of pointless timer events. Conversely, a
resource limited near the end of a period waits roughly a full extra
period after a permission was already available.
Now returns the time until the current period ends, clamped at zero.
returnsMinimalDurationToAcquirePermission only asserted
isLessThan(REFRESH_PERIOD), which held for both the correct and the
inverted value; it now also asserts the reported wait is close to the
full period. A second test asserts the reported duration shrinks as the
period elapses, which is what distinguishes remaining from elapsed. Both
fail without this change.
Part of #3517