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

RUM-6039 Fix StrictMode warning regarding I/O disk operation on main thread #2284

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

mariusc83
Copy link
Member

@mariusc83 mariusc83 commented Sep 25, 2024

What does this PR do?

Fixes: #2229

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

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)

@mariusc83 mariusc83 force-pushed the mconstantin/remove-io-operation-from-main-thread branch from 71fd9a7 to 90aaa08 Compare September 25, 2024 11:14
@mariusc83 mariusc83 marked this pull request as ready for review September 25, 2024 11:14
@mariusc83 mariusc83 requested review from a team as code owners September 25, 2024 11:14
@@ -51,7 +52,7 @@ internal class NdkCrashReportsFeature(
NDK_CRASH_REPORTS_FOLDER
)
try {
allowThreadDiskReads {
allowThreadDiskWrites {
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder why do we need to create the dirs on the main thread, maybe the owner of this code can give more info while reviewing this code. Tks !!.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

yes and no, I didn't wrote that function allowThreadDiskRead, I think @xgouchet did ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Check line 54 and 56 ;)

Copy link
Member

@0xnm 0xnm Sep 25, 2024

Choose a reason for hiding this comment

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

I'm referencing the code to create directories, not to allow I/O. This code to call directories creation on the main thread was since the creation of NDK module.

Copy link
Member Author

Choose a reason for hiding this comment

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

yup I am getting to understand why, this is going inside the NDK but I don't see a reason why we should just not pass the path to the ndk and create the file inside when we actually write the first content. What do you think ? Not sure if it is a change to do it now or maybe just keep it as it is ?

Copy link
Member

Choose a reason for hiding this comment

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

This path is also used in DatadogNdkCrashHandler, so we need to make sure that any change we do to this logic is compatible.

We maybe indeed can create it only when crash happens, the downside is that we will lose the time on the folder creation during the crash itself, when time is precious, but maybe the time penalty of such call is negligible.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes that's the reason why I am afraid as when the signal is handle you are in a different state it is not the same as in the JVM crash state. You have so little time to do something then the process is killed so you need to be very efficient there, I think for this main reason I prefer in this case to have that folder created already.

@@ -63,7 +63,7 @@ internal class ConsentAwareStorage(
callerClass = ConsentAwareStorage::class.java.name,
metric = TelemetryMetricType.MethodCalled,
samplingRate = MethodCallSamplingRate.RARE.rate,
operationName = "writeCurrentBatch[${orchestrator?.getRootDir()?.nameWithoutExtension}]"
operationName = "writeCurrentBatch[${orchestrator?.getRooDirName()}]"
Copy link
Member

Choose a reason for hiding this comment

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

Side note: I'm not even sure what is the point of having directory name here. With what we currently have it will be essentially (value of operationName):writeCurrentBatchrum-pending-v2 or writeCurrentBatchrum-v2.

Assuming that tracking consent information is probably useless, we are interested mostly in the feature name, which is a part of MetricsDispatcher already, so can be removed from here and be an additional attribute of all the events sent. But this performance metric is not using MetricsDispatcher, but InternalLogger, which is confusing.

It would be much more sense to have operation name = writeCurrentBatch and feature name attached as an attribute.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the thing I asked on the original thread in Slack but no - one answered so I said to go with this and discuss it here maybe.

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe we could just use feature name here....it will remove a lot of boiler code, what do you all think ? The only thing is that we will miss the folder type ? Granted/Pending. For that we can also pass the tracking consent in the operationName.

Copy link
Member

Choose a reason for hiding this comment

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

I would avoid growing constructor much. Also what is the point of having tracking consent here?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add enrich MetricsDispatcher? Implementation already has everything needed: logger and feature name,

Copy link
Member Author

Choose a reason for hiding this comment

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

Waiting for more opinions here before getting into it but I think it is the right call instead of using the root dir name.

Copy link
Member Author

Choose a reason for hiding this comment

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

the only thing is to not affect the metric which is based on the operationName in the dashboards

Copy link
Member

Choose a reason for hiding this comment

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

It is our internal metric, so we can break it at any time.

@mariusc83 mariusc83 force-pushed the mconstantin/remove-io-operation-from-main-thread branch 2 times, most recently from 3cf5c30 to 775c31b Compare September 25, 2024 11:57
@codecov-commenter
Copy link

codecov-commenter commented Sep 25, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Project coverage is 69.93%. Comparing base (a115df3) to head (1947770).
Report is 14 commits behind head on develop.

Files with missing lines Patch % Lines
...n/kotlin/com/datadog/android/core/StrictModeExt.kt 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2284      +/-   ##
===========================================
- Coverage    70.03%   69.93%   -0.10%     
===========================================
  Files          732      732              
  Lines        27228    27204      -24     
  Branches      4580     4571       -9     
===========================================
- Hits         19069    19024      -45     
- Misses        6883     6895      +12     
- Partials      1276     1285       +9     
Files with missing lines Coverage Δ
...d/core/internal/persistence/ConsentAwareStorage.kt 97.62% <100.00%> (+1.19%) ⬆️
...core/internal/persistence/file/FileOrchestrator.kt 100.00% <ø> (ø)
...ence/file/advanced/ConsentAwareFileOrchestrator.kt 96.77% <100.00%> (+0.11%) ⬆️
...al/persistence/file/batch/BatchFileOrchestrator.kt 94.08% <100.00%> (+0.04%) ⬆️
.../persistence/file/single/SingleFileOrchestrator.kt 80.00% <100.00%> (+1.43%) ⬆️
...dog/android/ndk/internal/NdkCrashReportsFeature.kt 69.64% <100.00%> (ø)
...n/kotlin/com/datadog/android/core/StrictModeExt.kt 50.00% <0.00%> (-50.00%) ⬇️

... and 34 files with indirect coverage changes

@mariusc83 mariusc83 force-pushed the mconstantin/remove-io-operation-from-main-thread branch from 775c31b to 1947770 Compare September 25, 2024 13:35
@mariusc83 mariusc83 self-assigned this Sep 25, 2024
@mariusc83 mariusc83 merged commit 0742a18 into develop Sep 25, 2024
23 checks passed
@mariusc83 mariusc83 deleted the mconstantin/remove-io-operation-from-main-thread branch September 25, 2024 15:02
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.

StrictMode violations on DatadogTree : Timber.Tree
4 participants