Merge "Update the rate limiting parameters to be a bit more strict in limiting, but keep the buffer longer before reset." into tm-dev
This commit is contained in:
@@ -24,9 +24,14 @@ import com.android.internal.annotations.GuardedBy;
|
||||
|
||||
/** Rate limiter for adding errors into dropbox. */
|
||||
public class DropboxRateLimiter {
|
||||
private static final long RATE_LIMIT_BUFFER_EXPIRY = 15 * DateUtils.SECOND_IN_MILLIS;
|
||||
private static final long RATE_LIMIT_BUFFER_DURATION = 10 * DateUtils.SECOND_IN_MILLIS;
|
||||
private static final int RATE_LIMIT_ALLOWED_ENTRIES = 5;
|
||||
// After RATE_LIMIT_ALLOWED_ENTRIES have been collected (for a single breakdown of
|
||||
// process/eventType) further entries will be rejected until RATE_LIMIT_BUFFER_DURATION has
|
||||
// elapsed, after which the current count for this breakdown will be reset.
|
||||
private static final long RATE_LIMIT_BUFFER_DURATION = 10 * DateUtils.MINUTE_IN_MILLIS;
|
||||
// The time duration after which the rate limit buffer will be cleared.
|
||||
private static final long RATE_LIMIT_BUFFER_EXPIRY = 3 * RATE_LIMIT_BUFFER_DURATION;
|
||||
// The number of entries to keep per breakdown of process/eventType.
|
||||
private static final int RATE_LIMIT_ALLOWED_ENTRIES = 6;
|
||||
|
||||
@GuardedBy("mErrorClusterRecords")
|
||||
private final ArrayMap<String, ErrorRecord> mErrorClusterRecords = new ArrayMap<>();
|
||||
|
||||
@@ -49,10 +49,11 @@ public class DropboxRateLimiterTest {
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
// Different processes and tags should not get rate limited either.
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag", "process2").shouldRateLimit());
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag2", "process").shouldRateLimit());
|
||||
// The 6th entry of the same process should be rate limited.
|
||||
// The 7th entry of the same process should be rate limited.
|
||||
assertTrue(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
}
|
||||
|
||||
@@ -64,12 +65,13 @@ public class DropboxRateLimiterTest {
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
// The 6th entry of the same process should be rate limited.
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
// The 7th entry of the same process should be rate limited.
|
||||
assertTrue(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
|
||||
// After 11 seconds there should be nothing left in the buffer and the same type of entry
|
||||
// After 11 minutes there should be nothing left in the buffer and the same type of entry
|
||||
// should not get rate limited anymore.
|
||||
mClock.setOffsetMillis(11000);
|
||||
mClock.setOffsetMillis(11 * 60 * 1000);
|
||||
|
||||
assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
|
||||
}
|
||||
@@ -86,13 +88,15 @@ public class DropboxRateLimiterTest {
|
||||
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
|
||||
assertEquals(0,
|
||||
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
|
||||
assertEquals(0,
|
||||
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
|
||||
assertEquals(1,
|
||||
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
|
||||
assertEquals(2,
|
||||
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
|
||||
|
||||
// After 11 seconds the rate limiting buffer will be cleared and rate limiting will stop.
|
||||
mClock.setOffsetMillis(11000);
|
||||
// After 11 minutes the rate limiting buffer will be cleared and rate limiting will stop.
|
||||
mClock.setOffsetMillis(11 * 60 * 1000);
|
||||
|
||||
// The first call after rate limiting stops will still return the number of dropped events.
|
||||
assertEquals(2,
|
||||
|
||||
Reference in New Issue
Block a user