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-5977 create UploadSchedulerStrategy interface and default implementation #2222

Merged

Conversation

xgouchet
Copy link
Member

What does this PR do?

Creates a basic interface to let customers decide how long to wait after an upload before trying again, based on the number of upload attempts, status code and exceptions.

@xgouchet xgouchet requested review from a team as code owners August 29, 2024 16:01
@xgouchet xgouchet force-pushed the xgouchet/RUM-5977/custom_upload_scheduler_strategy branch from 1c08628 to 8663f6b Compare August 29, 2024 16:06
@codecov-commenter
Copy link

codecov-commenter commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 93.87755% with 3 lines in your changes missing coverage. Please review.

Project coverage is 69.99%. Comparing base (4b09b22) to head (ad6e8f1).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
...id/core/internal/metrics/BatchMetricsDispatcher.kt 33.33% 0 Missing and 2 partials ⚠️
...rnal/data/upload/DefaultUploadSchedulerStrategy.kt 93.75% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2222      +/-   ##
===========================================
+ Coverage    69.97%   69.99%   +0.02%     
===========================================
  Files          726      727       +1     
  Lines        27033    27042       +9     
  Branches      4555     4557       +2     
===========================================
+ Hits         18915    18927      +12     
+ Misses        6838     6836       -2     
+ Partials      1280     1279       -1     
Files with missing lines Coverage Δ
...in/com/datadog/android/core/internal/SdkFeature.kt 91.49% <100.00%> (+0.58%) ⬆️
...id/core/internal/data/upload/DataUploadRunnable.kt 96.49% <100.00%> (-0.43%) ⬇️
...d/core/internal/data/upload/DataUploadScheduler.kt 100.00% <100.00%> (ø)
...rnal/data/upload/DefaultUploadSchedulerStrategy.kt 93.75% <93.75%> (ø)
...id/core/internal/metrics/BatchMetricsDispatcher.kt 95.95% <33.33%> (-2.70%) ⬇️

... and 29 files with indirect coverage changes

throwable: Throwable?
): Long {
if (uploadAttempts > 0 && throwable == null && lastStatusCode == HTTP_ACCEPTED) {
decreaseInterval()
Copy link
Member

Choose a reason for hiding this comment

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

Question, if the upload has succeeded after some failed attempts, why not just recover to the default delay immediately?

Copy link
Member Author

Choose a reason for hiding this comment

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

So far I've kept the historical behaviour of our backoff strategy. We will have future tickets to make a different implementations

Copy link
Member

@ambushwork ambushwork left a comment

Choose a reason for hiding this comment

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

LGTM!

@xgouchet xgouchet force-pushed the xgouchet/RUM-5977/custom_upload_scheduler_strategy branch 2 times, most recently from f36165d to 04b96ad Compare August 30, 2024 07:44
interface UploadSchedulerStrategy {

/**
* Should return the delay in millisecond to wait until the next upload attempt
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Should return the delay in millisecond to wait until the next upload attempt
* Should return the delay in milliseconds to wait until the next upload attempt

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

/**
* Should return the delay in millisecond to wait until the next upload attempt
* is performed.
* @param featureName the name of the feature for which a new upload will be scheduled
Copy link
Member

Choose a reason for hiding this comment

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

since we are exposing feature name here, maybe we should mention that they are listed in the Feature.Companion object of the Feature interface?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea

* Should return the delay in millisecond to wait until the next upload attempt
* is performed.
* @param featureName the name of the feature for which a new upload will be scheduled
* @param uploadAttempts the number of requests that were attempted during this run. Will be zero if the device
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should elaborate what is the meaning of the run here? Is it for a single batch or for all batches in general?

* is not ready (e.g.: when offline or with low battery). If multiple batches can be uploaded, the attempts will
* stop at the first failure.
* @param lastStatusCode the HTTP status code of the last request (if available). A successful upload will have a
* status code 202 (Accepted). When null, it means that
Copy link
Member

Choose a reason for hiding this comment

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

Sentence ending is missing

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

* is not ready (e.g.: when offline or with low battery). If multiple batches can be uploaded, the attempts will
* stop at the first failure.
* @param lastStatusCode the HTTP status code of the last request (if available). A successful upload will have a
* status code 202 (Accepted). When null, it means that
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: One of the dangers of exposing this interface (if it is exposed to the user configuration, apart of messing up with time unit) is that implementations may wrongly check for 200 status code instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will be exposed, but we won't document it in the website, so almost no one will implement it. Also it is mentioned in the documentation that they should check for a 202.

Comment on lines +61 to +62
lastBatchUploadStatus?.code,
lastBatchUploadStatus?.throwable
Copy link
Member

Choose a reason for hiding this comment

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

What if we simply pass lastBatchUploadStatus as a whole here? Does it have a downside?

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'm not keen of making the whole UploadStatus public. WDYT?

internal val uploadConfiguration: DataUploadConfiguration
) : UploadSchedulerStrategy {

private val currentDelays = mutableMapOf<String, Long>()
Copy link
Member

Choose a reason for hiding this comment

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

We probably need to make this one thread-safe, just in case. Even though we have only a single upload thread currently, it may change in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point


// endregion

// region Internal
Copy link
Member

Choose a reason for hiding this comment

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

missing // endregion for this one

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@xgouchet xgouchet requested a review from 0xnm August 30, 2024 09:08
@xgouchet xgouchet force-pushed the xgouchet/RUM-5977/custom_upload_scheduler_strategy branch from 04b96ad to e232d84 Compare August 30, 2024 09:08
Base automatically changed from xgouchet/RUM-5977/upload_status to develop August 30, 2024 09:36
@xgouchet xgouchet force-pushed the xgouchet/RUM-5977/custom_upload_scheduler_strategy branch from e232d84 to ad6e8f1 Compare August 30, 2024 10:22
@xgouchet xgouchet merged commit 045a231 into develop Aug 30, 2024
23 checks passed
@xgouchet xgouchet deleted the xgouchet/RUM-5977/custom_upload_scheduler_strategy branch August 30, 2024 11:08
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.

4 participants