Skip to content

REPLAY-1887 Provide the uploadFrequency per feature#1533

Merged
mariusc83 merged 1 commit into
developfrom
mconstantin/replay-1887/make-replay-data-uploader-more-eager
Jul 11, 2023
Merged

REPLAY-1887 Provide the uploadFrequency per feature#1533
mariusc83 merged 1 commit into
developfrom
mconstantin/replay-1887/make-replay-data-uploader-more-eager

Conversation

@mariusc83

@mariusc83 mariusc83 commented Jul 10, 2023

Copy link
Copy Markdown
Member

What does this PR do?

This PR is follow - up on the ios PR where we are providing a custom (batchSize, uploadFrequency) configuration for Session Replay feature to decrease the number of sessions with corrupted/not-enough records.

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 self-assigned this Jul 10, 2023

@xgouchet xgouchet left a comment

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.

It works, my main concern is making the core configuration's upload frequency optional.

It would be better to keep the core configuration mandatory, and make individual features override optional. If you flip the resolveUploadFrequency logic to the following, it would work better (that way people can just override the one feature they want a different upload frequency)

    private fun resolveUploadFrequency(
        coreFeature: CoreFeature,
        storageConfiguration: FeatureStorageConfiguration
    ): UploadFrequency {
        return storageConfiguration.uploadFrequency ?: coreFeature.uploadFrequency
    }

@mariusc83 mariusc83 closed this Jul 10, 2023
@mariusc83

Copy link
Copy Markdown
Member Author

It works, my main concern is making the core configuration's upload frequency optional.

It would be better to keep the core configuration mandatory, and make individual features override optional. If you flip the resolveUploadFrequency logic to the following, it would work better (that way people can just override the one feature they want a different upload frequency)

    private fun resolveUploadFrequency(
        coreFeature: CoreFeature,
        storageConfiguration: FeatureStorageConfiguration
    ): UploadFrequency {
        return storageConfiguration.uploadFrequency ?: coreFeature.uploadFrequency
    }

Tks @xgouchet, I think that's even better for now. My idea was that at some point we will drop this API at the core level as it doesn't make sense to have it anymore there. We could simplify it by having this only in the StorageConfiguration. But to keep a backward compatibility we could go this way indeed. I would like to hear also @0xnm thoughts on that.

@mariusc83 mariusc83 reopened this Jul 10, 2023
@mariusc83
mariusc83 force-pushed the mconstantin/replay-1887/make-replay-data-uploader-more-eager branch 2 times, most recently from 32f490b to 5555a4a Compare July 10, 2023 11:00
@mariusc83
mariusc83 marked this pull request as ready for review July 10, 2023 11:05
@mariusc83
mariusc83 requested a review from a team as a code owner July 10, 2023 11:05

@ncreated ncreated 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.

The override logic looks good 👌

@mariusc83
mariusc83 force-pushed the mconstantin/replay-1887/make-replay-data-uploader-more-eager branch from 5555a4a to fb29a38 Compare July 10, 2023 11:30
@codecov-commenter

codecov-commenter commented Jul 10, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1533 (702f13d) into develop (ee5007f) will decrease coverage by 0.26%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #1533      +/-   ##
===========================================
- Coverage    83.62%   83.36%   -0.26%     
===========================================
  Files          438      440       +2     
  Lines        14854    14871      +17     
  Branches      2237     2239       +2     
===========================================
- Hits         12421    12396      -25     
- Misses        1868     1884      +16     
- Partials       565      591      +26     
Impacted Files Coverage Δ
...android/api/storage/FeatureStorageConfiguration.kt 100.00% <100.00%> (ø)
...dog/android/core/internal/BatchingDelayResolver.kt 100.00% <100.00%> (ø)
...in/com/datadog/android/core/internal/SdkFeature.kt 91.00% <100.00%> (+0.47%) ⬆️
...g/android/core/internal/UploadFrequencyResolver.kt 100.00% <100.00%> (ø)
...core/internal/data/upload/v2/DataUploadRunnable.kt 100.00% <100.00%> (ø)
...ore/internal/data/upload/v2/DataUploadScheduler.kt 100.00% <100.00%> (ø)
...d/core/internal/persistence/ConsentAwareStorage.kt 98.75% <100.00%> (ø)
...oid/sessionreplay/internal/SessionReplayFeature.kt 100.00% <100.00%> (ø)

... and 17 files with indirect coverage changes

@mariusc83
mariusc83 requested a review from xgouchet July 10, 2023 12:00
Comment on lines +27 to +28
val uploadFrequency: UploadFrequency? = null,
val batchSize: BatchSize? = null

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.

it makes more sense to put default values into the DEFAULT object maybe?

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.

actually not...I prefer NULL, it's easier when I resolve them (if it is set here I take this one if not I take the core one)

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.

Yes, what I mean is to keep nullable type here, but put default null value to the DEFAULT object.

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.

hmm let me look into that, not sure I understand :)

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.

oh yeah, I see your point, done ;)


import com.datadog.android.api.storage.FeatureStorageConfiguration

internal class BatchingDelayResolver {

@0xnm 0xnm Jul 10, 2023

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.

imo it is a bit too much of abstractions, let's maybe just mock values returned by the wrappedFeature in the SdkFeature? Same for another resolver.

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 get your point, in the same time I prefer to have them separated and do not mix responsibilities. It's way easier for unit testing. I also suspect that this logic will change later so in that case SdkFeature will not change anymore and we will just change the resolver. What do you think ?

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.

not a fan of the overhead introduced by the resolvers either, it would be cleaner to not use them IMO

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 will try to add these as private methods instead, just need to find a better way to test it without too much noise.

private val networkInfoProvider: NetworkInfoProvider,
private val systemInfoProvider: SystemInfoProvider,
uploadFrequency: UploadFrequency,
internal val uploadFrequency: UploadFrequency,

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.

why this change is needed?

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.

tests

}

@Test
fun `M provide the core frequency W resolveUploadFrequency{not provide in storage config}`() {

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.

Suggested change
fun `M provide the core frequency W resolveUploadFrequency{not provide in storage config}`() {
fun `M provide the core frequency W resolveUploadFrequency{not provided in storage config}`() {

@mariusc83
mariusc83 force-pushed the mconstantin/replay-1887/make-replay-data-uploader-more-eager branch 3 times, most recently from cd35303 to 702f13d Compare July 11, 2023 08:59
@mariusc83
mariusc83 force-pushed the mconstantin/replay-1887/make-replay-data-uploader-more-eager branch from 702f13d to 81fa32a Compare July 11, 2023 09:29
@mariusc83
mariusc83 requested review from 0xnm and xgouchet July 11, 2023 09:30

@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, added few comments

Comment on lines +18 to +19
* @property uploadFrequency the desired upload frequency policy
* @property batchSize the desired batch size policy

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.

minor: maybe we should say, that if not explicitly provided, then value will be taken from the core configuration.

Comment on lines +158 to +162
whenever(mockWrappedFeature.storageConfiguration)
.thenReturn(fakeStorageConfig)
// When

testedFeature.initialize(appContext.mockInstance)

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.

Suggested change
whenever(mockWrappedFeature.storageConfiguration)
.thenReturn(fakeStorageConfig)
// When
testedFeature.initialize(appContext.mockInstance)
whenever(mockWrappedFeature.storageConfiguration)
.thenReturn(fakeStorageConfig)
// When
testedFeature.initialize(appContext.mockInstance)

}

@Test
fun `𝕄 initialize the storage 𝕎 initialize()`() {

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.

with core batch size probably is missing in the name?

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 am considering this as default initialization so wanted to keep it as that in the test description

@mariusc83
mariusc83 force-pushed the mconstantin/replay-1887/make-replay-data-uploader-more-eager branch from 81fa32a to 6118490 Compare July 11, 2023 10:40
@mariusc83
mariusc83 merged commit ccc5562 into develop Jul 11, 2023
@mariusc83
mariusc83 deleted the mconstantin/replay-1887/make-replay-data-uploader-more-eager branch July 11, 2023 13:55
@xgouchet xgouchet added this to the 2.0.0 milestone Dec 13, 2023
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