This repository was archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 487
Remove Cache Clearing to reduce CDN load on failing devices (EXPOSUREAPP-2405) #1108
Merged
jakobmoellerdev
merged 10 commits into
dev
from
fix/do-not-clear-cache-on-key-retrieval-failure
Sep 7, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
353d3bd
Remove Cache Clearing to reduce CDN load on failing devices. This ide…
jakobmoellerdev 461a4a4
Merge remote-tracking branch 'origin/dev' into fix/do-not-clear-cache…
jakobmoellerdev 1c00161
Remove Files that failed for Key Retrieval
jakobmoellerdev 3dfe7b7
Introduce dedicated QuotaCalculator for Unit Testing
jakobmoellerdev b6a21b9
Refactor QuotaCalculator for LocalData Property Access and Write Tests
jakobmoellerdev dba08b5
Use Instant on the Device Read since this is not timezone specific
jakobmoellerdev ec758e0
Add specific state for the quota calculation and dedicated rollback
jakobmoellerdev a3c89ed
Merge branch 'dev' into fix/do-not-clear-cache-on-key-retrieval-failure
jakobmoellerdev 437362c
PR Comments
jakobmoellerdev 06c8b5b
Merge remote-tracking branch 'origin/fix/do-not-clear-cache-on-key-re…
jakobmoellerdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
62 changes: 62 additions & 0 deletions
62
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/GoogleQuotaCalculator.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package de.rki.coronawarnapp.util | ||
|
|
||
| import de.rki.coronawarnapp.storage.LocalData | ||
| import org.joda.time.Chronology | ||
| import org.joda.time.DateTime | ||
| import org.joda.time.DateTimeZone | ||
| import org.joda.time.Duration | ||
| import org.joda.time.Instant | ||
|
|
||
| /** | ||
| * This Calculator class takes multiple parameters to check if the Google API | ||
| * can be called or the Rate Limit has been reached. The Quota is expected to reset at | ||
| * the start of the day in the given timeZone and Chronology | ||
| * | ||
| * @property incrementByAmount The amount of Quota Calls to increment per Call | ||
| * @property quotaLimit The maximum amount of Quota Calls allowed before Rate Limiting | ||
| * @property quotaResetPeriod The Period after which the Quota Resets | ||
| * @property quotaTimeZone The Timezone to work in | ||
| * @property quotaChronology The Chronology to work in | ||
| */ | ||
| class GoogleQuotaCalculator( | ||
| val incrementByAmount: Int, | ||
jakobmoellerdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val quotaLimit: Int, | ||
| val quotaResetPeriod: Duration, | ||
| val quotaTimeZone: DateTimeZone, | ||
| val quotaChronology: Chronology | ||
| ) : QuotaCalculator<Int> { | ||
| override var hasExceededQuota: Boolean = false | ||
|
|
||
| override fun calculateQuota(): Boolean { | ||
| if (Instant.now().isAfter(LocalData.nextTimeRateLimitingUnlocks)) { | ||
| LocalData.nextTimeRateLimitingUnlocks = DateTime | ||
| .now(quotaTimeZone) | ||
| .withChronology(quotaChronology) | ||
| .plus(quotaResetPeriod) | ||
| .withTimeAtStartOfDay() | ||
| .toInstant() | ||
| LocalData.googleAPIProvideDiagnosisKeysCallCount = 0 | ||
| } | ||
|
|
||
| if (LocalData.googleAPIProvideDiagnosisKeysCallCount <= quotaLimit) { | ||
| LocalData.googleAPIProvideDiagnosisKeysCallCount += incrementByAmount | ||
| } | ||
|
|
||
| hasExceededQuota = LocalData.googleAPIProvideDiagnosisKeysCallCount > quotaLimit | ||
|
|
||
| return hasExceededQuota | ||
| } | ||
|
|
||
| override fun resetProgressTowardsQuota(newProgress: Int) { | ||
| if (newProgress > quotaLimit) { | ||
| throw IllegalArgumentException("cannot reset progress to a value higher than the quota limit") | ||
| } | ||
| if (newProgress % incrementByAmount != 0) { | ||
| throw IllegalArgumentException("supplied progress is no multiple of $incrementByAmount") | ||
| } | ||
| LocalData.googleAPIProvideDiagnosisKeysCallCount = newProgress | ||
| hasExceededQuota = false | ||
| } | ||
|
|
||
| override fun getProgressTowardsQuota(): Int = LocalData.googleAPIProvideDiagnosisKeysCallCount | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/QuotaCalculator.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package de.rki.coronawarnapp.util | ||
|
|
||
| /** | ||
| * Class to check if a Quota has been reached based on the calculation done inside | ||
| * the Calculator | ||
| * | ||
| */ | ||
| interface QuotaCalculator<T> { | ||
| val hasExceededQuota: Boolean | ||
|
|
||
| /** | ||
| * This function is called to recalculate an old quota score | ||
| */ | ||
| fun calculateQuota(): Boolean | ||
|
|
||
| /** | ||
| * Reset the quota progress | ||
| * | ||
| * @param newProgress new progress towards the quota | ||
| */ | ||
| fun resetProgressTowardsQuota(newProgress: T) | ||
|
|
||
| /** | ||
| * Retrieve the current progress towards the quota | ||
| * | ||
| * @return current progress count | ||
| */ | ||
| fun getProgressTowardsQuota(): T | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it still increment count by 14 each time
executeAPISubmissionis called? I thought that after #1088 it should increment it only by 1, asprovideDiagnosisKeysis called once. Assuming that Google docs are correct:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be done in a separate PR as we plan to provide this change here before 1.4 official release. this way we single out the commit. But you are correct, with the changes in v1.5 mode, this needs to be set to 1
P.S.: I also already included a test case for this change. I hope to do a one-liner correction.