Skip to content

RUM-5182: Add precheck conditions when registering session replay feature#2264

Merged
ambushwork merged 1 commit into
feature/sr-dynamic-optimisationfrom
yl/sr-opt/add-min-specs
Oct 2, 2024
Merged

RUM-5182: Add precheck conditions when registering session replay feature#2264
ambushwork merged 1 commit into
feature/sr-dynamic-optimisationfrom
yl/sr-opt/add-min-specs

Conversation

@ambushwork

Copy link
Copy Markdown
Member

What does this PR do?

  • Add SystemRequirementConfiguration class to contain requirements to check
  • Add SystemRequirementChecker to check if every condition can be met:
    • MemoryRequirementChecker implementation to check max RAM size
    • CpuRequirementChecker implementation to check cpu cores number
  • Add SessionReplayRequirement class to use SystemRequirementConfiguration and all the checkers to determine if the task can be executed after checking the conditions.

Motivation

RUN-5182

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch 4 times, most recently from 2072869 to 7ebd002 Compare September 17, 2024 11:15
@ambushwork ambushwork changed the title RUN-5182: Add precheck conditions when registering session replay feature RUM-5182: Add precheck conditions when registering session replay feature Sep 17, 2024
@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch from 7ebd002 to 4275f94 Compare September 17, 2024 11:38
@codecov-commenter

codecov-commenter commented Sep 17, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 66.01942% with 35 lines in your changes missing coverage. Please review.

Project coverage is 70.10%. Comparing base (35991f3) to head (70b09b1).
Report is 2 commits behind head on feature/sr-dynamic-optimisation.

Files with missing lines Patch % Lines
...d/sessionreplay/SystemRequirementsConfiguration.kt 50.00% 17 Missing ⚠️
.../internal/prerequisite/MemoryRequirementChecker.kt 62.50% 4 Missing and 5 partials ⚠️
...lay/internal/prerequisite/CPURequirementChecker.kt 73.33% 2 Missing and 2 partials ⚠️
.../android/core/internal/persistence/file/FileExt.kt 0.00% 2 Missing ⚠️
...ndroid/sessionreplay/SessionReplayConfiguration.kt 71.43% 2 Missing ⚠️
...com/datadog/android/sessionreplay/SessionReplay.kt 95.24% 1 Missing ⚠️
Additional details and impacted files
@@                         Coverage Diff                         @@
##           feature/sr-dynamic-optimisation    #2264      +/-   ##
===================================================================
+ Coverage                            70.09%   70.10%   +0.01%     
===================================================================
  Files                                  731      734       +3     
  Lines                                27241    27328      +87     
  Branches                              4598     4609      +11     
===================================================================
+ Hits                                 19092    19156      +64     
- Misses                                6845     6870      +25     
+ Partials                              1304     1302       -2     
Files with missing lines Coverage Δ
...com/datadog/android/sessionreplay/SessionReplay.kt 62.50% <95.24%> (+8.33%) ⬆️
.../android/core/internal/persistence/file/FileExt.kt 85.00% <0.00%> (-2.93%) ⬇️
...ndroid/sessionreplay/SessionReplayConfiguration.kt 96.92% <71.43%> (-3.08%) ⬇️
...lay/internal/prerequisite/CPURequirementChecker.kt 73.33% <73.33%> (ø)
.../internal/prerequisite/MemoryRequirementChecker.kt 62.50% <62.50%> (ø)
...d/sessionreplay/SystemRequirementsConfiguration.kt 50.00% <50.00%> (ø)

... and 33 files with indirect coverage changes

@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch from 4275f94 to a17dc90 Compare September 17, 2024 12:13
@ambushwork
ambushwork marked this pull request as ready for review September 17, 2024 12:13
@ambushwork
ambushwork requested review from a team as code owners September 17, 2024 12:13
Comment thread dd-sdk-android-core/api/apiSurface
Comment thread detekt_custom.yml Outdated
Comment thread detekt_custom.yml Outdated
Comment thread detekt_custom.yml Outdated
@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch 2 times, most recently from 6792490 to d57126f Compare September 18, 2024 09:41
Comment thread features/dd-sdk-android-session-replay/build.gradle.kts Outdated
@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch from d57126f to d15d780 Compare September 18, 2024 12:01
jonathanmos
jonathanmos previously approved these changes Sep 19, 2024
@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch 3 times, most recently from de30f0a to 3ed945f Compare September 19, 2024 13:18
@ambushwork

ambushwork commented Sep 19, 2024

Copy link
Copy Markdown
Member Author

@0xnm @jonathanmos I just refactored the PR, please review it again if you want, main changes:

  • Add public API to SessionReplayConfiguration to set SystemRequirementConfigutation
  • Switch back to main thread to register feature after checking the requirements.

@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch 2 times, most recently from 6669428 to 6cc73ca Compare September 19, 2024 13:40
@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch from 6cc73ca to 281cb42 Compare September 20, 2024 13:12
@ambushwork
ambushwork requested a review from 0xnm September 20, 2024 13:13
@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch 3 times, most recently from 355b137 to c089683 Compare September 24, 2024 10:58
@ambushwork

Copy link
Copy Markdown
Member Author

I applied the @0xnm 's change in my branch, please check again, thanks!

Comment on lines +38 to +40
companion object
val DEFAULT: SystemRequirementConfiguration
val NONE: SystemRequirementConfiguration

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should these be exposed to the user? what is the case for using NONE on the client-side - always enable Session Replay?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I think we need to provide an option to the client that session replay can be enabled in any case without checking any system requirements.

private var textAndInputPrivacy = TextAndInputPrivacy.MASK_ALL
private var extensionSupport: ExtensionSupport = NoOpExtensionSupport()
private var dynamicOptimizationEnabled = true
private var systemRequirementConfiguration = SystemRequirementConfiguration.NONE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't it be DEFAULT? because the default value for the default Session Replay configuration is NONE, while DEFAULT also exists.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well, from my point of view of product design, I assume that at the beginning, most of user will not be aware of the existence of this API, in this case should we add a default limiter to disable the session replay? with this concern I use NONE as the default configuration, for the client who is aware of this API, they can use DEFAULT one to setup manually.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

my point is that default is not called DEFAULT, but NONE, but I see that it is for the backward compatibility

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You are right, but I wonder what name we should give to them, let's check the opinion of the other reviewers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

I share @0xnm 's concern, mostly in term of naming.
The default value is NONE, so maybe the other value could be BASIC. Another option could be to use a naming similar to Facebook's device-year-class library. That lib would categorize the device with the year when devices with the same capabilities were most popular. E.g.: it would tell you that a low-end phone purchased today is equivalent to a 2018 standard phone.
Our "default" setting (minCPUCores = 2, minRAMSizeMb = 1024) looks like a 2011 phone specs.

@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch 2 times, most recently from d00334f to 277ad5a Compare September 25, 2024 14:20
@ambushwork
ambushwork requested a review from 0xnm September 27, 2024 09:04

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this one mostly lgtm, but I would like to have another pair of eyes having a fresh look here, especially on the public API changes.

@xgouchet or @mariusc83 can you please take a look?

Comment thread features/dd-sdk-android-session-replay/api/apiSurface
private var textAndInputPrivacy = TextAndInputPrivacy.MASK_ALL
private var extensionSupport: ExtensionSupport = NoOpExtensionSupport()
private var dynamicOptimizationEnabled = true
private var systemRequirementConfiguration = SystemRequirementConfiguration.NONE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

my point is that default is not called DEFAULT, but NONE, but I see that it is for the backward compatibility

@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch 2 times, most recently from a9cd682 to 72d14db Compare September 27, 2024 15:53
jonathanmos
jonathanmos previously approved these changes Sep 29, 2024
xgouchet
xgouchet previously approved these changes Sep 30, 2024
private var textAndInputPrivacy = TextAndInputPrivacy.MASK_ALL
private var extensionSupport: ExtensionSupport = NoOpExtensionSupport()
private var dynamicOptimizationEnabled = true
private var systemRequirementConfiguration = SystemRequirementConfiguration.NONE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

I share @0xnm 's concern, mostly in term of naming.
The default value is NONE, so maybe the other value could be BASIC. Another option could be to use a naming similar to Facebook's device-year-class library. That lib would categorize the device with the year when devices with the same capabilities were most popular. E.g.: it would tell you that a low-end phone purchased today is equivalent to a 2018 standard phone.
Our "default" setting (minCPUCores = 2, minRAMSizeMb = 1024) looks like a 2011 phone specs.

/**
* Defines the minimum system requirements for enabling the Session Replay feature.
* When [SessionReplay.enable] is invoked, the system configuration is verified against these requirements.
* If the system meets the specified criteria, Session Replay will be successfully enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

We should add in the kdoc here that by default, we do not have any minimum requirements and Session Replay will be applied to all devices

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@xgouchet Should our approach not be to optimize performance by default (including not running by default on weak devices), but give users a way to opt-out of our optimizations? If so, the default precheck would be applied for all users with the caveat that they can turn it off with the flag that we've provided in the configuration.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@jonathanmos as we discussed with @MaelNamNam before, this precheck should not be covered by the flag of the dynamic optimisation, they should be different API to enable/disable. I think we can keep it disable by default, I will add doc to elaborate

Comment on lines +32 to +39
val checkers = listOf(
CPURequirementChecker(minCPUCores, internalLogger = internalLogger),
MemoryRequirementChecker(minRAMSizeMb, internalLogger = internalLogger)
)
(sdkCore as InternalSdkCore).getPersistenceExecutorService().submitSafe(OPERATION_NAME, internalLogger) {
val checkResult = checkers.all {
it.checkMinimumRequirement()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

So I have a bit of a concern here. Right now it's not a problem, but it could become one eventually.
We create a new Checker instance and perform the checks every time we call the runIfMeetRequirements() method. The thing is that the cpu and ram size will never change on a given device, meaning we could memoize the result of the check for the current session and ensure we don't perform the check on every call. Not necessary for this PR but we should probably add a task for this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see the point here, so the way of memorising it for me is to persist result in shared preference or a file, but I may wonder if this solution will have the same effect with the current one because current checkers actually just read files. So the difference of two solutions is just the file that they are reading if I am not wrong?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well, I was more thinking on an in memory check (technically some device coud have a Ram upgrade, or we could have some different checks in the future), to limit the check to once per app run.
In the current use case (the SystemRequirementConfiguration class being only used in one place) it wouldn't change anything, as I said, which is why just keeping a Jira task (and maybe a TODO comment in the class) is enough for now

@ambushwork
ambushwork dismissed stale reviews from xgouchet and jonathanmos via b52034f September 30, 2024 11:50
@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch 2 times, most recently from b52034f to 24d1af6 Compare September 30, 2024 12:14
xgouchet
xgouchet previously approved these changes Oct 1, 2024
@ambushwork
ambushwork requested review from 0xnm and jonathanmos October 1, 2024 10:04
0xnm
0xnm previously approved these changes Oct 1, 2024

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lgtm. I left a few suggestions, but nothing blocking.

Comment thread features/dd-sdk-android-session-replay/api/apiSurface Outdated
@ambushwork
ambushwork dismissed stale reviews from 0xnm and xgouchet via 70b09b1 October 2, 2024 08:00
@ambushwork
ambushwork force-pushed the yl/sr-opt/add-min-specs branch from 24d1af6 to 70b09b1 Compare October 2, 2024 08:00
@ambushwork
ambushwork merged commit 2b56563 into feature/sr-dynamic-optimisation Oct 2, 2024
@ambushwork
ambushwork deleted the yl/sr-opt/add-min-specs branch October 2, 2024 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants