fix bug: throttledRateLimiter is not once per minute, but five times (#7156)
This commit is contained in:
parent
dc46ccd2c9
commit
16f3637b0b
|
@ -41,7 +41,8 @@ public class ThrottlingLogger {
|
||||||
this.fastRateLimiter =
|
this.fastRateLimiter =
|
||||||
new RateLimiter(RATE_LIMIT / rateTimeUnit.toSeconds(1), RATE_LIMIT, clock);
|
new RateLimiter(RATE_LIMIT / rateTimeUnit.toSeconds(1), RATE_LIMIT, clock);
|
||||||
this.throttledRateLimiter =
|
this.throttledRateLimiter =
|
||||||
new RateLimiter(RATE_LIMIT / rateTimeUnit.toSeconds(1), THROTTLED_RATE_LIMIT, clock);
|
new RateLimiter(
|
||||||
|
THROTTLED_RATE_LIMIT / rateTimeUnit.toSeconds(1), THROTTLED_RATE_LIMIT, clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Log a message at the given level. */
|
/** Log a message at the given level. */
|
||||||
|
|
|
@ -144,4 +144,41 @@ class ThrottlingLoggerTest {
|
||||||
assertThat(logs.getEvents()).hasSize(9);
|
assertThat(logs.getEvents()).hasSize(9);
|
||||||
assertThat(logs.getEvents().get(8).getMessage()).isEqualTo("oh no!");
|
assertThat(logs.getEvents().get(8).getMessage()).isEqualTo("oh no!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void allowOnlyOneLogPerMinuteAfterSuppression() {
|
||||||
|
TestClock clock = TestClock.create();
|
||||||
|
ThrottlingLogger logger = new ThrottlingLogger(realLogger, clock);
|
||||||
|
|
||||||
|
logger.log(Level.WARNING, "oh no!");
|
||||||
|
logger.log(Level.WARNING, "oh no!");
|
||||||
|
logger.log(Level.WARNING, "oh no!");
|
||||||
|
logger.log(Level.WARNING, "oh no!");
|
||||||
|
logger.log(Level.WARNING, "oh no!");
|
||||||
|
|
||||||
|
logger.log(Level.WARNING, "oh no I should trigger suppression!");
|
||||||
|
logger.log(Level.WARNING, "oh no I should be suppressed!");
|
||||||
|
|
||||||
|
assertThat(logs.getEvents()).hasSize(7);
|
||||||
|
|
||||||
|
clock.advance(Duration.ofMillis(12_001));
|
||||||
|
logger.log(Level.WARNING, "suppression 1");
|
||||||
|
clock.advance(Duration.ofMillis(12_001));
|
||||||
|
logger.log(Level.WARNING, "suppression 2");
|
||||||
|
clock.advance(Duration.ofMillis(12_001));
|
||||||
|
logger.log(Level.WARNING, "suppression 3");
|
||||||
|
clock.advance(Duration.ofMillis(12_001));
|
||||||
|
logger.log(Level.WARNING, "suppression 4");
|
||||||
|
clock.advance(Duration.ofMillis(12_001));
|
||||||
|
logger.log(Level.WARNING, "allowed 1");
|
||||||
|
|
||||||
|
logs.assertDoesNotContain("suppression 1");
|
||||||
|
logs.assertDoesNotContain("suppression 2");
|
||||||
|
logs.assertDoesNotContain("suppression 3");
|
||||||
|
logs.assertDoesNotContain("suppression 4");
|
||||||
|
logs.assertContains("allowed 1");
|
||||||
|
|
||||||
|
assertThat(logs.getEvents()).hasSize(8);
|
||||||
|
assertThat(logs.getEvents().get(7).getMessage()).isEqualTo("allowed 1");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue