Skip to content
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

Technical Analytics: Milestone 2 - Add Ability To Log Feature Flags #5240

Open
wants to merge 106 commits into
base: develop
Choose a base branch
from

Conversation

kkmurerwa
Copy link
Collaborator

@kkmurerwa kkmurerwa commented Nov 22, 2023

Explanation

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

Screenshot of the Event Logs page showing the FeatureFlagsEventContext being logged

Essential Checklist

  • 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: ...".)
  • Any changes to scripts/assets files have their rationale included in the PR explanation.
  • The PR follows the style guide.
  • The PR does not contain any unnecessary code changes from Android Studio (reference).
  • The PR is made from a branch that's not called "develop" and is up-to-date with "develop".
  • The PR is assigned to the appropriate reviewers (reference).

For UI-specific PRs only

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)
  • Add a video showing the full UX flow with a screen reader enabled (see accessibility 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

kkmurerwa and others added 30 commits October 18, 2023 10:01
Co-authored-by: Adhiambo Peres <59600948+adhiamboperes@users.noreply.github.com>
…a/oppia-android into technical-analytics-milestone-1
…a/oppia-android into technical-analytics-milestone-1
@adhiamboperes
Copy link
Collaborator

@kkmurerwa, checking if you meant to assign this to @BenHenning.

@kkmurerwa
Copy link
Collaborator Author

This is not done yet. I meant to assign M3 to you and ended up assigning M2 instead.

Copy link

oppiabot bot commented Apr 9, 2024

Hi @kkmurerwa, I'm going to mark this PR as stale because it hasn't had any updates for 7 days. If no further activity occurs within 7 days, it will be automatically closed so that others can take up the issue.
If you are still working on this PR, please make a follow-up commit within 3 days (and submit it for review, if applicable). Please also let us know if you are stuck so we can help you!

@oppiabot oppiabot bot added the stale Corresponds to items that haven't seen a recent update and may be automatically closed. label Apr 9, 2024
@oppiabot oppiabot bot removed the stale Corresponds to items that haven't seen a recent update and may be automatically closed. label Apr 14, 2024
@kkmurerwa
Copy link
Collaborator Author

kkmurerwa commented Apr 14, 2024

@BenHenning this PR is now ready for another review. PTAL

@kkmurerwa kkmurerwa assigned BenHenning and unassigned kkmurerwa Apr 15, 2024
Copy link
Sponsor Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kkmurerwa! Just small things left I think--PTAL.

@@ -176,6 +176,7 @@ class ApplicationLifecycleObserver @Inject constructor(

private fun logAllFeatureFlags() {
CoroutineScope(backgroundDispatcher).launch {
// TODO(#5240): Replace appSessionId generation to the modified Twitter snowflake algorithm.
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should point to an issue, not a PR. Should it be pointing to #5341? Though, I think that issue also needs to be updated to explain the additional work of using the modified snowflake algorithm (per the TDD).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have modified the reference on the code and updated the issue to include the detail about the Twitter snowflake algorithm. Let me know if the issue description is detailed enough.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the TODO was removed from code--shouldn't it stay here and point to #5341?

I also think #5341 is a bit confusing since, after this PR is merged, it will seem as if an ID is being provided. The issue should probably instead explain what needs to be changed from the solution introduced in this PR to get analytics to where we want them long-term.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the issue description and reverted the deletion that removed the TODO from the codebase.

@@ -251,6 +251,44 @@ class LoggingIdentifierControllerTest {
assertThat(sessionIdFlow.value).isEqualTo("59aea8d4-af4b-3249-b889-dfeba06d0495")
}

@Test
fun testGetAppSessionId_initialState_returnsRandomId() {
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test to verify a new app instance to demonstrate a different ID is generated, similar to this test:

fun testGetInstallationId_secondAppOpen_providerReturnsSameInstallationIdValue() {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a test that kind of checks for this but I will need some validation on whether it does that correctly.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in the meeting today, we should probably be doing something like the following to ensure correct behavior:

  • Arrange
    • Set fixed application random seed to value (explicitly within the test). Note this should be done in the test that doesn't verify app restart, too, for parity.
    • Set up rest of test as normal
  • Act
    • Update the application random seed to be something different.
    • Recreate the application component & reinit the test suite fields, where needed.
  • Assert: assert as normal (that the ID is different than in the test which doesn't 'restart' the app).

Copy link
Collaborator Author

@kkmurerwa kkmurerwa May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unable to create a test that can objectively test that the app is generating different app session IDs on restart based on how the test file is structured. I have created an issue to track this #5399. Once fixed, all tests on the file should now pass (or fail) for the correct reason.

@BenHenning BenHenning assigned kkmurerwa and unassigned BenHenning Apr 16, 2024
@kkmurerwa kkmurerwa assigned BenHenning and unassigned kkmurerwa May 6, 2024
@kkmurerwa
Copy link
Collaborator Author

@BenHenning this PR should be ready for another review. PTAL

Copy link
Sponsor Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kkmurerwa! Just a few follow-ups--PTAL.

* 1. The app is opened.
* 2. The app is destroyed by the Android system.
*/
fun updateAppSessionId() {
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? It seems like we shouldn't ever need to explicitly updated the session ID since it autoinitializes upon app open.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that now. I will remove this.

@@ -176,6 +176,7 @@ class ApplicationLifecycleObserver @Inject constructor(

private fun logAllFeatureFlags() {
CoroutineScope(backgroundDispatcher).launch {
// TODO(#5240): Replace appSessionId generation to the modified Twitter snowflake algorithm.
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the TODO was removed from code--shouldn't it stay here and point to #5341?

I also think #5341 is a bit confusing since, after this PR is merged, it will seem as if an ID is being provided. The issue should probably instead explain what needs to be changed from the solution introduced in this PR to get analytics to where we want them long-term.

@@ -251,6 +251,44 @@ class LoggingIdentifierControllerTest {
assertThat(sessionIdFlow.value).isEqualTo("59aea8d4-af4b-3249-b889-dfeba06d0495")
}

@Test
fun testGetAppSessionId_initialState_returnsRandomId() {
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in the meeting today, we should probably be doing something like the following to ensure correct behavior:

  • Arrange
    • Set fixed application random seed to value (explicitly within the test). Note this should be done in the test that doesn't verify app restart, too, for parity.
    • Set up rest of test as normal
  • Act
    • Update the application random seed to be something different.
    • Recreate the application component & reinit the test suite fields, where needed.
  • Assert: assert as normal (that the ID is different than in the test which doesn't 'restart' the app).

@BenHenning BenHenning assigned kkmurerwa and unassigned BenHenning May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants