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-1633 Drop batch telemetry where duration or age have negative values #1850

Conversation

mariusc83
Copy link
Member

@mariusc83 mariusc83 commented Feb 8, 2024

What does this PR do?

In order to prevent the graphs skewing in the telemetry dashboards we are dropping the metrics for which the batch age and batch duration values are negatives due to the device time manual modification or time zone change.

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 Feb 8, 2024
@mariusc83 mariusc83 requested review from a team as code owners February 8, 2024 16:18
@@ -89,7 +90,7 @@ internal class BatchMetricsDispatcher(
deletionReason: RemovalReason
): Map<String, Any?>? {
val fileCreationTimestamp = file.nameAsTimestampSafe(internalLogger) ?: return null
val fileAgeInMillis = dateTimeProvider.getDeviceTimestamp() - fileCreationTimestamp
val fileAgeInMillis = max(0, (dateTimeProvider.getDeviceTimestamp() - fileCreationTimestamp))
Copy link
Member

Choose a reason for hiding this comment

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

Then it would still skew, but towards the zero. maybe it is better to ignore than this metric if it is negative?
Or maybe we don't need to use dateTimeProvider here? Because file is created using newFileName = System.currentTimeMillis().toString(), which is not affected at all by NTP synchronization. Meaning that to calculate file age property, we still need to use System.currentTimeMillis() directly, this will be reliable, because we want duration, and not instant.

wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

iOS has the same and we wanted to align Android also to make sure we have the same charts. I am ready to discuss this into the parking lot today during our daily.

Copy link
Member

Choose a reason for hiding this comment

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

The thing is that file created using System.currentTimeMillis(), without NTP-adjustment (well, maybe there is adjustment done by the device). It means that for file age at least we need also to use System.currentTimeMillis() without NTP-adjustment, this should guarantee that time behind these calls is monotonic.

Copy link
Member Author

Choose a reason for hiding this comment

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

exactly why we are using that here and not the NTP adjustment one. But no one can guarantee that by the time we send the metric the System time was not skewed or the time zone was not changed. This will give a negative age. We've already noticed this behaviour in our data.

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking that getDeviceTimestamp is affected by our NTP adjustment, apparently it is not and it is plain System.currentTimeMillis() under the hood. Then yes, not so much we can do (apart of ignoring the metric is value is negative).

@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2024

Codecov Report

Merging #1850 (fddada4) into develop (c9f8785) will decrease coverage by 0.09%.
The diff coverage is 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1850      +/-   ##
===========================================
- Coverage    83.45%   83.36%   -0.09%     
===========================================
  Files          470      470              
  Lines        16594    16593       -1     
  Branches      2492     2492              
===========================================
- Hits         13847    13832      -15     
- Misses        2064     2072       +8     
- Partials       683      689       +6     
Files Coverage Δ
...id/core/internal/metrics/BatchMetricsDispatcher.kt 98.61% <100.00%> (+0.08%) ⬆️

... and 26 files with indirect coverage changes

Comment on lines 377 to 380
(
fakeMetadata.lastTimeWasUsedInMs +
forge.aLong(min = 100, max = 1000)
).toString()
Copy link
Member

Choose a reason for hiding this comment

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

maybe just extract this into a variable? formatting looks strange here.

@mariusc83 mariusc83 force-pushed the mconstantin/rum-1633/make-sure-batch-age-in-telemetry-is-positive branch from 3a2681d to 02a77de Compare February 12, 2024 08:47
@mariusc83 mariusc83 changed the title RUM-1633 Make the batch age and duration have positive values in telemetry events RUM-1633 Drop batch telemetry where duration or age have negative values Feb 12, 2024
@mariusc83 mariusc83 force-pushed the mconstantin/rum-1633/make-sure-batch-age-in-telemetry-is-positive branch from 02a77de to fddada4 Compare February 12, 2024 09:42
@mariusc83 mariusc83 merged commit 35dc427 into develop Feb 12, 2024
23 checks passed
@mariusc83 mariusc83 deleted the mconstantin/rum-1633/make-sure-batch-age-in-telemetry-is-positive branch February 12, 2024 10:26
@xgouchet xgouchet added this to the 2.6.0 milestone Feb 19, 2024
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