-
Notifications
You must be signed in to change notification settings - Fork 134
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
GH1618 Simplify (internal) flushing logic #1628
GH1618 Simplify (internal) flushing logic #1628
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 2479 Passed, 0 Skipped, 5m 8.75s Wall Time 🔻 Code Coverage Decreases vs Default Branch (9)
|
@@ -157,13 +157,11 @@ internal class FilesOrchestrator: FilesOrchestratorType { | |||
.compactMap { try deleteFileIfItsObsolete(file: $0.file, fileCreationDate: $0.creationDate) } | |||
.sorted(by: { $0.creationDate < $1.creationDate }) | |||
|
|||
#if DD_SDK_COMPILED_FOR_TESTING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure about this? When we do this "open" batch is going to be included.
This function is called in the DataUploadWorker
as well (it happens in line 77: fileReader.readFiles(limit: maxBatchesPerUpload)
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is conditioned by ignoreFilesAgeWhenReading
flag enabled from core.flushAndTearDown()
which is only available when DD_SDK_COMPILED_FOR_TESTING
macro is set:
dd-sdk-ios/DatadogCore/Sources/Datadog.swift
Lines 485 to 489 in 3686259
#if DD_SDK_COMPILED_FOR_TESTING | |
public static func flushAndDeinitialize(instanceName: String = CoreRegistry.defaultInstanceName) { | |
internalFlushAndDeinitialize(instanceName: instanceName) | |
} | |
#endif |
so I don't see how this may interrupt DataUploadWorker
in production apps. The entire concept of "ignoring files age" was introduced for testing purpose (we want to force-send all data in tests). Does it sound ok to you @maciejburda?
Ultimately, I don't like using macros in this way as they shred the codebase. Since it was introduced a long time ago however, we managed to keep the impact of DD_SDK_COMPILED_FOR_TESTING
very minimal. A better approach would be to abstract certain components and inject different implementation in tests - it implies a much bigger effort, but I hope we do it one day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what am I missing, but the modified function getReadableFiles(excludingFilesNamed excludedFileNames: Set<String> = [], limit: Int = .max)
is being called by the DataUploadWorker
dependency: FileReader
.
Removing this #if
makes the file orchestrator ignore file age for producation code as well, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic we enable here is conditioned by ignoreFilesAgeWhenReading
flag 🙂:
if ignoreFilesAgeWhenReading {
return filesFromOldest
.prefix(limit)
.map { $0.file }
}
And this is only set to true
in our tests 💡.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I get it now! Thanks for clarifying :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
What and why?
🧰 The internal
Datadog.internalFlushAndDeinitialize()
does not work without settingDD_SDK_COMPILED_FOR_TESTING
compiler flag. To simplify the reasoning about internal "flush", I propose to remove this macro from downstream logic. It will be still used to hide the public API behind this feature, see:dd-sdk-ios/DatadogCore/Sources/Datadog.swift
Lines 485 to 489 in a43c63d
Solves #1618
How?
The "flush" logic was protected twice:
DD_SDK_COMPILED_FOR_TESTING
flag,DD_SDK_COMPILED_FOR_TESTING
.The second occurrence was redundant and it is removed.
Review checklist
Custom CI job configuration (optional)
tools/