forked from oppia/oppia-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Technical Analytics: Milestone 2 - Add Ability To Log Feature Flags (o…
…ppia#5240) <!-- READ ME FIRST: Please fill in the explanation section below and check off every point from the Essential Checklist! --> ## Explanation <!-- - Explain what your PR does. If this PR fixes an existing bug, please include - "Fixes #bugnum:" in the explanation so that GitHub can auto-close the issue - when this PR is merged. --> When merged, this PR will: - Create a `FeatureFlagLogger.kt` file that aggregates and logs all feature flags. - Add a `FeatureFlagLoggerTest.kt` to test the FeatureFlagLogger. - Add logging logic to the `ApplicationLifecycleObserver.kt` file so that it is logged when the app is in foreground. ### Screenshot of the FeatureFlagContext log in the Event Logs page <p align="center"> <img src="https://github.com/oppia/oppia-android/assets/18438114/894f9251-4b59-41f7-b2b2-3124e430d5bd" width="280" alt="Screenshot of the Event Logs page showing the FeatureFlagsEventContext being logged"/> </p> ## Essential Checklist <!-- Please tick the relevant boxes by putting an "x" in them. --> - [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".) - [x] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation. - [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide). - [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)). - [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop". - [x] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)). ## For UI-specific PRs only <!-- Delete these section if this PR does not include UI-related changes. --> If your PR includes UI-related changes, then: - Add screenshots for portrait/landscape for both a tablet & phone of the before & after UI changes - For the screenshots above, include both English and pseudo-localized (RTL) screenshots (see [RTL guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines)) - Add a video showing the full UX flow with a screen reader enabled (see [accessibility guide](https://github.com/oppia/oppia-android/wiki/Accessibility-A11y-Guide)) - For PRs introducing new UI elements or color changes, both light and dark mode screenshots must be included - Add a screenshot demonstrating that you ran affected Espresso tests locally & that they're passing --------- Co-authored-by: Adhiambo Peres <[email protected]> Co-authored-by: Ben Henning <[email protected]>
- Loading branch information
1 parent
add9f74
commit b9d9dff
Showing
18 changed files
with
860 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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
142 changes: 142 additions & 0 deletions
142
domain/src/main/java/org/oppia/android/domain/oppialogger/analytics/FeatureFlagsLogger.kt
This file contains 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,142 @@ | ||
package org.oppia.android.domain.oppialogger.analytics | ||
|
||
import org.oppia.android.app.model.EventLog | ||
import org.oppia.android.app.model.EventLog.FeatureFlagItemContext | ||
import org.oppia.android.app.model.EventLog.FeatureFlagListContext | ||
import org.oppia.android.util.platformparameter.APP_AND_OS_DEPRECATION | ||
import org.oppia.android.util.platformparameter.DOWNLOADS_SUPPORT | ||
import org.oppia.android.util.platformparameter.EDIT_ACCOUNTS_OPTIONS_UI | ||
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY | ||
import org.oppia.android.util.platformparameter.ENABLE_ONBOARDING_FLOW_V2 | ||
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION | ||
import org.oppia.android.util.platformparameter.EXTRA_TOPIC_TABS_UI | ||
import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation | ||
import org.oppia.android.util.platformparameter.EnableDownloadsSupport | ||
import org.oppia.android.util.platformparameter.EnableEditAccountsOptionsUi | ||
import org.oppia.android.util.platformparameter.EnableExtraTopicTabsUi | ||
import org.oppia.android.util.platformparameter.EnableFastLanguageSwitchingInLesson | ||
import org.oppia.android.util.platformparameter.EnableInteractionConfigChangeStateRetention | ||
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics | ||
import org.oppia.android.util.platformparameter.EnableLoggingLearnerStudyIds | ||
import org.oppia.android.util.platformparameter.EnableNpsSurvey | ||
import org.oppia.android.util.platformparameter.EnableOnboardingFlowV2 | ||
import org.oppia.android.util.platformparameter.EnablePerformanceMetricsCollection | ||
import org.oppia.android.util.platformparameter.EnableSpotlightUi | ||
import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSON | ||
import org.oppia.android.util.platformparameter.INTERACTION_CONFIG_CHANGE_STATE_RETENTION | ||
import org.oppia.android.util.platformparameter.LEARNER_STUDY_ANALYTICS | ||
import org.oppia.android.util.platformparameter.LOGGING_LEARNER_STUDY_IDS | ||
import org.oppia.android.util.platformparameter.PlatformParameterValue | ||
import org.oppia.android.util.platformparameter.SPOTLIGHT_UI | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
/** | ||
* Convenience logger for feature flags. | ||
* | ||
* This logger is meant to be used for feature flag-related logging on every app launch. It is | ||
* primarily used within the ApplicationLifecycleObserver to log the status of feature flags in a | ||
* given app session. | ||
*/ | ||
@Singleton | ||
class FeatureFlagsLogger @Inject constructor( | ||
private val analyticsController: AnalyticsController, | ||
@EnableDownloadsSupport | ||
private val enableDownloadsSupport: PlatformParameterValue<Boolean>, | ||
@EnableExtraTopicTabsUi | ||
private val enableExtraTopicTabsUi: PlatformParameterValue<Boolean>, | ||
@EnableLearnerStudyAnalytics | ||
private val enableLearnerStudyAnalytics: PlatformParameterValue<Boolean>, | ||
@EnableFastLanguageSwitchingInLesson | ||
private val enableFastLanguageSwitchingInLesson: PlatformParameterValue<Boolean>, | ||
@EnableLoggingLearnerStudyIds | ||
private val enableLoggingLearnerStudyIds: PlatformParameterValue<Boolean>, | ||
@EnableEditAccountsOptionsUi | ||
private val enableEditAccountsOptionsUi: PlatformParameterValue<Boolean>, | ||
@EnablePerformanceMetricsCollection | ||
private val enablePerformanceMetricsCollection: PlatformParameterValue<Boolean>, | ||
@EnableSpotlightUi | ||
private val enableSpotlightUi: PlatformParameterValue<Boolean>, | ||
@EnableInteractionConfigChangeStateRetention | ||
private val enableInteractionConfigChangeStateRetention: PlatformParameterValue<Boolean>, | ||
@EnableAppAndOsDeprecation | ||
private val enableAppAndOsDeprecation: PlatformParameterValue<Boolean>, | ||
@EnableNpsSurvey | ||
private val enableNpsSurvey: PlatformParameterValue<Boolean>, | ||
@EnableOnboardingFlowV2 | ||
private val enableOnboardingFlowV2: PlatformParameterValue<Boolean> | ||
) { | ||
/** | ||
* A variable containing a list of all the feature flags in the app. | ||
* | ||
* @return a list of key-value pairs of [String] and [PlatformParameterValue] | ||
*/ | ||
private var featureFlagItemMap: Map<String, PlatformParameterValue<Boolean>> = mapOf( | ||
DOWNLOADS_SUPPORT to enableDownloadsSupport, | ||
EXTRA_TOPIC_TABS_UI to enableExtraTopicTabsUi, | ||
LEARNER_STUDY_ANALYTICS to enableLearnerStudyAnalytics, | ||
FAST_LANGUAGE_SWITCHING_IN_LESSON to enableFastLanguageSwitchingInLesson, | ||
LOGGING_LEARNER_STUDY_IDS to enableLoggingLearnerStudyIds, | ||
EDIT_ACCOUNTS_OPTIONS_UI to enableEditAccountsOptionsUi, | ||
ENABLE_PERFORMANCE_METRICS_COLLECTION to enablePerformanceMetricsCollection, | ||
SPOTLIGHT_UI to enableSpotlightUi, | ||
INTERACTION_CONFIG_CHANGE_STATE_RETENTION to enableInteractionConfigChangeStateRetention, | ||
APP_AND_OS_DEPRECATION to enableAppAndOsDeprecation, | ||
ENABLE_NPS_SURVEY to enableNpsSurvey, | ||
ENABLE_ONBOARDING_FLOW_V2 to enableOnboardingFlowV2 | ||
) | ||
|
||
/** | ||
* This method can be used to override the featureFlagItemMap and sets its value to the given map. | ||
* | ||
* @param featureFlagItemMap denotes the map of feature flag names to their corresponding | ||
* [PlatformParameterValue]s | ||
*/ | ||
fun setFeatureFlagItemMap(featureFlagItemMap: Map<String, PlatformParameterValue<Boolean>>) { | ||
this.featureFlagItemMap = featureFlagItemMap | ||
} | ||
|
||
/** | ||
* This method logs the name, enabled status and sync status of all feature flags to Firebase. | ||
* | ||
* @param appSessionId denotes the id of the current appInForeground session | ||
*/ | ||
fun logAllFeatureFlags(appSessionId: String) { | ||
val featureFlagItemList = mutableListOf<FeatureFlagItemContext>() | ||
for (flag in featureFlagItemMap) { | ||
featureFlagItemList.add( | ||
createFeatureFlagItemContext(flag) | ||
) | ||
} | ||
|
||
// TODO(#5341): Set the UUID value for this context | ||
val featureFlagContext = FeatureFlagListContext.newBuilder() | ||
.setAppSessionId(appSessionId) | ||
.addAllFeatureFlags(featureFlagItemList) | ||
.build() | ||
|
||
analyticsController.logLowPriorityEvent( | ||
EventLog.Context.newBuilder() | ||
.setFeatureFlagListContext(featureFlagContext) | ||
.build(), | ||
profileId = null | ||
) | ||
} | ||
|
||
/** | ||
* Creates an [EventLog] context for the feature flags to be logged. | ||
* | ||
* @param flagDetails denotes the key-value pair of the feature flag name and its corresponding | ||
* [PlatformParameterValue] | ||
* @return an [EventLog.Context] for the feature flags to be logged | ||
*/ | ||
private fun createFeatureFlagItemContext( | ||
flagDetails: Map.Entry<String, PlatformParameterValue<Boolean>>, | ||
): FeatureFlagItemContext { | ||
return FeatureFlagItemContext.newBuilder() | ||
.setFlagName(flagDetails.key) | ||
.setFlagEnabledState(flagDetails.value.value) | ||
.setFlagSyncStatus(flagDetails.value.syncStatus) | ||
.build() | ||
} | ||
} |
This file contains 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
Oops, something went wrong.