Skip to content

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

Merged
merged 8 commits into from
May 5, 2023

Conversation

visumickey
Copy link
Contributor

No description provided.

@visumickey visumickey force-pushed the firebase-sessions-config-fetcher branch from a220260 to cf4b036 Compare May 2, 2023 01:23
@visumickey visumickey requested review from samedson and mrober May 2, 2023 01:23
@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 2, 2023

Coverage Report 1

Affected Products

  • firebase-sessions

    Overall coverage changed from ? (d4a30e1) to 68.79% (485f4b5) by ?.

    17 individual files with coverage change

    FilenameBase (d4a30e1)Merge (485f4b5)Diff
    ApplicationInfo.kt?100.00%?
    EventGDTLogger.kt?75.00%?
    FirebaseSessions.kt?0.00%?
    FirebaseSessionsEarly.kt?0.00%?
    FirebaseSessionsRegistrar.kt?0.00%?
    LocalOverrideSettings.kt?88.46%?
    RemoteSettings.kt?85.53%?
    RemoteSettingsFetcher.kt?3.23%?
    SessionCoordinator.kt?76.47%?
    SessionEvent.kt?100.00%?
    SessionEvents.kt?100.00%?
    SessionGenerator.kt?20.00%?
    SessionInitiator.kt?66.67%?
    SessionsSettings.kt?90.00%?
    SettingsCache.kt?94.12%?
    SettingsProvider.kt?0.00%?
    Time.kt?0.00%?

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/3AWi645jZY.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 2, 2023

Size Report 1

Affected Products

  • base

    TypeBase (d4a30e1)Merge (485f4b5)Diff
    apk (aggressive)?8.39 kB? (?)
    apk (release)?8.65 kB? (?)
  • firebase-datatransport

    TypeBase (d4a30e1)Merge (485f4b5)Diff
    aar?4.94 kB? (?)
    apk (aggressive)?161 kB? (?)
    apk (release)?1.35 MB? (?)
  • firebase-sessions

    TypeBase (d4a30e1)Merge (485f4b5)Diff
    aar?93.9 kB? (?)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/jJcvLwCr9L.html

@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2023

Unit Test Results

22 files  22 suites   31s ⏱️
35 tests 35 ✔️ 0 💤 0
70 runs  70 ✔️ 0 💤 0

Results for commit e21558d.

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 3, 2023

Startup Time Report 1

Note: 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:

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/iEC3KqbrFM/index.html

@visumickey visumickey changed the title Implement remote config fetcher to cache values. Implement remote config fetcher to fetch and cache configs. May 3, 2023
Comment on lines 111 to 145
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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

fetchedResponse.remove("app_quality")

// Sleep for a second before updating configs
Thread.sleep(2000)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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:

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:

Copy link
Contributor Author

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.

@visumickey visumickey merged commit c3b0dcc into firebase-sessions May 5, 2023
@visumickey visumickey deleted the firebase-sessions-config-fetcher branch May 5, 2023 16:18
@firebase firebase locked and limited conversation to collaborators Jun 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants