Skip to content

RUM-8042 Add pending batches to batch deleted metric #2191

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

Merged
merged 3 commits into from
Feb 20, 2025

Conversation

maxep
Copy link
Member

@maxep maxep commented Feb 12, 2025

What and why?

Add pending batches attribute to Batch Deleted Metric.
This attribute will help drawing distribution of pending batches throughout sessions.

How?

FilesOrchestrator keeps track of pending batches and send it as part of BatchDeletedMetric telemetry.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference
  • Add CHANGELOG entry for user facing changes
  • Add Objective-C interface for public APIs (see our guidelines [internal]) and run make api-surface)

@maxep maxep requested review from a team as code owners February 12, 2025 14:50
@maxep maxep force-pushed the maxep/RUM-8042/pending-batch-telemetry branch from 8d0f383 to a6cd347 Compare February 12, 2025 16:49
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Feb 12, 2025

Datadog Report

Branch report: maxep/RUM-8042/pending-batch-telemetry
Commit report: 737e7f4
Test service: dd-sdk-ios

✅ 0 Failed, 790 Passed, 3020 Skipped, 59.93s Total Time

simaoseica-dd
simaoseica-dd previously approved these changes Feb 12, 2025
Copy link
Contributor

@simaoseica-dd simaoseica-dd left a comment

Choose a reason for hiding this comment

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

Looks good. Just some questions

Comment on lines 64 to 65
@ReadWriteLock
private var pendingBatches: Int = 0
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 using a lock here because getting and deleting a file can happen on different threads, but this can add penalty to the call thread.

The other option will be to read the directory each time we send the telemetry:

BatchDeletedMetric.pendingBatches: try? directory.files()

But this also has the drawback of reading the disk each time.

Copy link
Member

@mariedm mariedm left a comment

Choose a reason for hiding this comment

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

Looks good! I left a couple of questions.

@@ -258,6 +268,9 @@ internal class FilesOrchestrator: FilesOrchestratorType {
///
/// Note: The `batchFile` doesn't exist at this point.
private func sendBatchDeletedMetric(batchFile: ReadableFile, deletionReason: BatchDeletedMetric.RemovalReason) {
// Decrement pending batches at each batch deletion
pendingBatches -= 1
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the decrementation happen where the batch is deleted rather than when sending the telemetry?

let files = try directory.files()

// Reset pending batches for telemetry
pendingBatches = files.count
Copy link
Member

Choose a reason for hiding this comment

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

Could this lead to discrepancies? Right now this variable can be updated from different places.

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 a fair point! Makes me leaning toward the solution proposed here. This was, we would be sure that data is accurate.

Copy link
Member

@mariedm mariedm Feb 18, 2025

Choose a reason for hiding this comment

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

Or could we update pendingBatches either only here, or when a file gets created & removed? This way we keep the lock.

Copy link
Member Author

Choose a reason for hiding this comment

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

Getting the files.count while reading is to know the pending batches when the SDK starts. At start, no file has been created or removed but there could be files on disk. So, we need to get the count at read/create/delete operations. I will push the other solution, LMKWYT!

Copy link
Member

@mariedm mariedm Feb 18, 2025

Choose a reason for hiding this comment

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

Got it!

How often would this telemetry be sent, apart from app launch? I wonder what would be the performance impact of reading from disk.

Initially I wanted to suggest initializing the counter when creating the FileOrchestrator, but I see getReadableFiles is called from other places so that won't work.

Given that potential inconsistencies only happen at app launch, when the reset happens, would the initial counter implementation be acceptable? It might be a good tradeoff between performance and accuracy.

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 think reading the disk each time we send the telemetry is acceptable. With average upload frequency, this will be call every 2s if a batch is present and ready. So I don't expect any perf impact.

@maxep maxep force-pushed the maxep/RUM-8042/pending-batch-telemetry branch from 9932036 to 63e8fd6 Compare February 18, 2025 10:19
mariedm
mariedm previously approved these changes Feb 20, 2025
Copy link
Member

@mariedm mariedm left a comment

Choose a reason for hiding this comment

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

🚀

@maxep maxep force-pushed the maxep/RUM-8042/pending-batch-telemetry branch from 63e8fd6 to 737e7f4 Compare February 20, 2025 15:58
@maxep
Copy link
Member Author

maxep commented Feb 20, 2025

/merge

@dd-devflow
Copy link

dd-devflow bot commented Feb 20, 2025

View all feedbacks in Devflow UI.
2025-02-20 16:03:11 UTC ℹ️ Start processing command /merge


2025-02-20 16:03:15 UTC ℹ️ MergeQueue: waiting for PR to be ready

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-02-20 16:25:16 UTC ℹ️ MergeQueue: merge request added to the queue

The median merge time in develop is 28m.


2025-02-20 16:52:30 UTC ℹ️ MergeQueue: This merge request was merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants