-
Notifications
You must be signed in to change notification settings - Fork 625
Implement remote config fetcher to fetch and cache configs. #4967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement remote config fetcher to fetch and cache configs. #4967
Conversation
a220260
to
cf4b036
Compare
Coverage Report 1Affected Products
Test Logs |
Size Report 1Affected Products
Test Logs |
firebase-sessions/src/main/kotlin/com/google/firebase/sessions/settings/RemoteSettings.kt
Outdated
Show resolved
Hide resolved
firebase-sessions/src/main/kotlin/com/google/firebase/sessions/settings/RemoteSettings.kt
Outdated
Show resolved
Hide resolved
firebase-sessions/src/main/kotlin/com/google/firebase/sessions/settings/RemoteSettings.kt
Outdated
Show resolved
Hide resolved
...ase-sessions/src/test/kotlin/com/google/firebase/sessions/testing/FakeRemoteConfigFetcher.kt
Outdated
Show resolved
Hide resolved
firebase-sessions/src/test/kotlin/com/google/firebase/sessions/RemoteSettingsTest.kt
Outdated
Show resolved
Hide resolved
Startup Time Report 1Note: Layout is sometimes suboptimal due to limited formatting support on GitHub. Please check this report on GCS. Startup time comparison between the CI merge commit (485f4b5) and the base commit (d4a30e1) are not available. No macrobenchmark data found for the base commit (d4a30e1). Analysis for the CI merge commit (485f4b5) can be found at: |
val aqsSettings = it.get("app_quality") as JSONObject | ||
try { | ||
if (aqsSettings.has("sessions_enabled")) { | ||
sessionsEnabled = aqsSettings.get("sessions_enabled") as Boolean? | ||
} | ||
|
||
if (aqsSettings.has("sampling_rate")) { | ||
sessionSamplingRate = aqsSettings.get("sampling_rate") as Double? | ||
} | ||
|
||
// Check if cache is expired. If not, return | ||
// Initiate a fetch. On successful response cache the fetched values | ||
if (aqsSettings.has("session_timeout_seconds")) { | ||
sessionTimeoutSeconds = aqsSettings.get("session_timeout_seconds") as Int? | ||
} | ||
|
||
if (aqsSettings.has("cache_duration")) { | ||
cacheDuration = aqsSettings.get("cache_duration") as Int? | ||
} | ||
} catch (exception: JSONException) { | ||
Log.e(TAG, "Error parsing the configs remotely fetched: ", exception) | ||
} | ||
} | ||
|
||
sessionsEnabled?.let { settingsCache.updateSettingsEnabled(sessionsEnabled) } | ||
|
||
sessionTimeoutSeconds?.let { | ||
settingsCache.updateSessionRestartTimeout(sessionTimeoutSeconds) | ||
} | ||
|
||
sessionSamplingRate?.let { settingsCache.updateSamplingRate(sessionSamplingRate) } | ||
|
||
cacheDuration?.let { settingsCache.updateSessionCacheDuration(cacheDuration) } | ||
?: let { settingsCache.updateSessionCacheDuration(86400) } | ||
|
||
settingsCache.updateSessionCacheUpdatedTime(System.currentTimeMillis()) | ||
fetchInProgress = false |
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.
WDYT about putting the onSuccess block in a separate method?
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.
Not sure what gains that provides. I would rather leave it here as the only thing that is done on success is to cache the values. So, leaving it as is.
firebase-sessions/src/main/kotlin/com/google/firebase/sessions/settings/RemoteSettings.kt
Outdated
Show resolved
Hide resolved
firebase-sessions/src/main/kotlin/com/google/firebase/sessions/settings/RemoteSettings.kt
Outdated
Show resolved
Hide resolved
fetchedResponse.remove("app_quality") | ||
|
||
// Sleep for a second before updating configs | ||
Thread.sleep(2000) |
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.
Do the sleeps slow down tests?
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.
It does - for 2 seconds. Basically it is a situations where we are setting the cache duration for configs to be set as 1 second and 2 seconds later, we are providing updated configs.
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.
Ah I see - we should be able to avoid sleeps. Sleeps are bad cause they slow down the tests and are flakey. We get the time here it seems:
Line 73 in 8c12472
val currentTimestamp = System.currentTimeMillis() |
We can pass this in as an function parameter to RemoteSettings. That way we can fast forward time in the test. We do that in our Session Initiator Tests:
Line 136 in 8c12472
fakeTimeProvider.addInterval(LARGE_INTERVAL) |
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.
Tried making the refactor to accomodate the TimeProvider, but that seem to take a lot more refactor that what it is today. Example: Time class internally does not provide time comparison with another time value. Until that is done, it is hard to refactor to use that class. So, will leave it as is for now since the time internal to sleep here is just 2 seconds.
No description provided.