Merge "Update the rate limiting parameters to be a bit more strict in limiting, but keep the buffer longer before reset." into tm-dev am: 7d302d0927

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18029562

Change-Id: I9d378567a4a2064de48fd6150e58892a9954e3f1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Siim Sammul
2022-05-09 14:28:36 +00:00
committed by Automerger Merge Worker
2 changed files with 18 additions and 9 deletions

View File

@@ -24,9 +24,14 @@ import com.android.internal.annotations.GuardedBy;
/** Rate limiter for adding errors into dropbox. */ /** Rate limiter for adding errors into dropbox. */
public class DropboxRateLimiter { public class DropboxRateLimiter {
private static final long RATE_LIMIT_BUFFER_EXPIRY = 15 * DateUtils.SECOND_IN_MILLIS; // After RATE_LIMIT_ALLOWED_ENTRIES have been collected (for a single breakdown of
private static final long RATE_LIMIT_BUFFER_DURATION = 10 * DateUtils.SECOND_IN_MILLIS; // process/eventType) further entries will be rejected until RATE_LIMIT_BUFFER_DURATION has
private static final int RATE_LIMIT_ALLOWED_ENTRIES = 5; // 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") @GuardedBy("mErrorClusterRecords")
private final ArrayMap<String, ErrorRecord> mErrorClusterRecords = new ArrayMap<>(); private final ArrayMap<String, ErrorRecord> mErrorClusterRecords = new ArrayMap<>();

View File

@@ -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());
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. // Different processes and tags should not get rate limited either.
assertFalse(mRateLimiter.shouldRateLimit("tag", "process2").shouldRateLimit()); assertFalse(mRateLimiter.shouldRateLimit("tag", "process2").shouldRateLimit());
assertFalse(mRateLimiter.shouldRateLimit("tag2", "process").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()); 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()); 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()); 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. // should not get rate limited anymore.
mClock.setOffsetMillis(11000); mClock.setOffsetMillis(11 * 60 * 1000);
assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit()); assertFalse(mRateLimiter.shouldRateLimit("tag", "process").shouldRateLimit());
} }
@@ -86,13 +88,15 @@ public class DropboxRateLimiterTest {
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated()); mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
assertEquals(0, assertEquals(0,
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated()); mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
assertEquals(0,
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
assertEquals(1, assertEquals(1,
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated()); mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
assertEquals(2, assertEquals(2,
mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated()); mRateLimiter.shouldRateLimit("tag", "p").droppedCountSinceRateLimitActivated());
// After 11 seconds the rate limiting buffer will be cleared and rate limiting will stop. // After 11 minutes the rate limiting buffer will be cleared and rate limiting will stop.
mClock.setOffsetMillis(11000); mClock.setOffsetMillis(11 * 60 * 1000);
// The first call after rate limiting stops will still return the number of dropped events. // The first call after rate limiting stops will still return the number of dropped events.
assertEquals(2, assertEquals(2,