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

hybrid-application: merge from master #719

Merged
merged 128 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
7a9603f
RUMM-1615 Allow launch time earlier than `UIApplicationDidBecomeActiv…
maxep Oct 15, 2021
7fea66d
RUMM-1615 Update `LaunchTimeProviderType ` documentation
maxep Oct 18, 2021
9f146b6
RUMM-1615 Create `RUMCommandPublisher` to publish RUM command to a su…
maxep Oct 22, 2021
55811d2
RUMM-1615 Refacto `RUMAutoInstrumentation` to `RUMInstrumentation`
maxep Oct 29, 2021
ee146ab
RUMM-1615 SwiftUI View Instrumentation
maxep Oct 22, 2021
cbaf621
RUMM-1615 Fix integration test flakiness
maxep Oct 27, 2021
c9d7572
RUMM-1615 Workaround FB8907671 in 14.2 <= iOS < 14.5
maxep Oct 28, 2021
2c84bbe
RUMM-1615 Add `RUMViewModifier` unit tests
maxep Nov 3, 2021
4d2e97c
RUMM-1615 Use native view modifier
maxep Nov 3, 2021
58eaa1f
RUMM-1615 Remove `RUMInstrumentation` compliance to `SwiftUIViewHandler`
maxep Nov 3, 2021
5791552
Revert "RUMM-1615 Add `RUMViewModifier` unit tests"
maxep Nov 3, 2021
bdd6713
RUMM-1615 Update identity property name and documentation
maxep Nov 4, 2021
1c75e6b
RUMM-1745 Use single handler for UIKit and SwiftUI views instrumentation
maxep Nov 2, 2021
0f83834
RUMM-1745 prefix publisher methods with `notify_`
maxep Nov 12, 2021
6ebc2a5
RUMM-1745 Rename RUM instrumentations properties
maxep Nov 12, 2021
724ff1e
RUMM-1745 Keep weak ref to view controller
maxep Nov 12, 2021
a0c6699
RUMM-1745 Fix typo
maxep Nov 16, 2021
e149db5
RUMM-1745 Remove unnecessary stack check
maxep Nov 16, 2021
d127697
RUMM-1745 Test nil identity
maxep Nov 16, 2021
a86632a
RUMM-1745 Keep predicate private to view handler
maxep Nov 17, 2021
006bf44
RUMM-1615 Workaround FB8907671 in 14.2 <= iOS < 15
maxep Nov 17, 2021
3dd94c2
RUMM-1745 Fix SwiftUI scenario navigation bar title
maxep Nov 17, 2021
bc80661
RUMM-1758 Fix Xcode 12.x compilation issue in 'Example' target
ncreated Nov 24, 2021
785d09b
RUMM-1758 Resolve Xcode 13.1 upgrade warnings
ncreated Nov 24, 2021
b01284d
Merge pull request #657 from DataDog/maxep/RUMM-1745/swiftui-uikit-na…
maxep Nov 24, 2021
b89f1c1
RUMM-1658 Manual instrumentation of SwiftUI actions
maxep Nov 12, 2021
b0ffbea
RUMM-1658 Remove `RUMSwipeActionModifier`
maxep Nov 22, 2021
283237c
RUMM-1658 Fix doc typo
maxep Nov 24, 2021
c5983a4
Merge pull request #672 from DataDog/ncreated/RUMM-1758-fix-Example-a…
ncreated Nov 24, 2021
ccb9354
RUMM-1758 Link SwiftUI (weakly) to the 'Example' target
ncreated Nov 25, 2021
f7c7a3a
Merge pull request #673 from DataDog/ncreated/RUMM-1758-fix-runtime-i…
ncreated Nov 25, 2021
d71e560
Merge pull request #661 from DataDog/maxep/RUMM-1658/swiftui-actions
maxep Nov 29, 2021
ecc3bbb
Update to version 1.0.2 of testing framework
Nov 30, 2021
b280161
Merge pull request #675 from DataDog/nachoBonafonte/update-to-testing…
Dec 1, 2021
6e3da95
🚩RUM-1755 Add config overrides for debug launch arguments
fuzzybinary Dec 2, 2021
eb9c464
Allow passing in a type for errors sent with a message
AvdLee Dec 3, 2021
cf17b18
🧹Cleanup MobileDevice initialization
fuzzybinary Dec 3, 2021
59bb278
Move deinit of MobileDevice to possibly fix tests.
fuzzybinary Dec 3, 2021
8e7c19e
Merge pull request #676 from DataDog/feature/swiftui
maxep Dec 6, 2021
55afb58
Add `nil` default to error with message method for backwards compatib…
AvdLee Dec 6, 2021
2c437f4
Move ProcessInfo out of MobileDevice and into AppContext
fuzzybinary Dec 6, 2021
1b56d0b
Merge pull request #679 from DataDog/jward/RUM-1755-debug-launch-argu…
fuzzybinary Dec 6, 2021
80bdcae
Add custom type support for resource loading
AvdLee Dec 7, 2021
19348a1
Add tests for setting a custom type
AvdLee Dec 7, 2021
2e1ca19
Add missing comma
AvdLee Dec 7, 2021
c3a02ce
Add tests for custom error types
ncreated Dec 8, 2021
65aa429
RUMM-1821 Fix flaky conditions in `RUMResourcesScenarioTests`
ncreated Dec 8, 2021
639c7ec
RUMM-1821 Improve `UITests` observability in CI App by logging `RUMSe…
ncreated Dec 9, 2021
92fd3dc
Update to version 1.0.3-beta.1 of testing framework
Dec 9, 2021
102445f
RUMM-1821 Fix UI tests plan selection on CI
ncreated Dec 9, 2021
8eef37c
RUMM-1821 Exclude mobile vitals and SwiftUI tests from CR test plan
ncreated Dec 9, 2021
2704a4b
RUMM-1821 CR fix - cleanup
ncreated Dec 9, 2021
c62be2d
Merge pull request #682 from DataDog/ncreated/RUMM-1821-fix-flakiness…
ncreated Dec 9, 2021
68711e4
Merge pull request #680 from AvdLee/master
ncreated Dec 9, 2021
fc969b2
Merge pull request #684 from DataDog/ncreated/RUMM-1821-fix-selecting…
ncreated Dec 9, 2021
67be79e
RUMM-1765 Make starting "Background" view based on the command's prop…
ncreated Nov 29, 2021
e245f68
RUMM-1765 Mark the very first RUM session in the process as "initial"
ncreated Nov 29, 2021
93b992a
RUMM-1765 Handle application launch events in `RUMSessionScope`
ncreated Nov 30, 2021
0928f3b
RUMM-1765 Start RUM session with the first tracked event
ncreated Nov 30, 2021
972b42b
RUMM-1765 Improve RUM command mocks
ncreated Dec 1, 2021
373a915
RUMM-1765 Test app launch events tracking in `RUMMonitorTests`
ncreated Dec 1, 2021
0e9cfef
RUMM-1765 Add debug utility for testing background events tracking
ncreated Dec 6, 2021
db4ba70
RUMM-1765 CR fix - address comments
ncreated Dec 7, 2021
795e402
RUMM-1765 Add tests for expected App Launch x Background Events Track…
ncreated Dec 10, 2021
b1609bb
RUMM-1765 Adjust naming in `AppStateHistory` to better fit the new us…
ncreated Dec 10, 2021
d3646f7
RUMM-1765 Inject `AppStateListener` to RUM scopes
ncreated Dec 10, 2021
4c9338b
RUMM-1765 Make App Launch x Background Events Tracking tests green
ncreated Dec 10, 2021
591708a
RUMM-1765 Fix `Benchmarks` build
ncreated Dec 10, 2021
ad16182
Merge pull request #686 from DataDog/nachoBonafonte/update-to-testing…
Dec 10, 2021
a92066e
RUMM-1765 Fix a bug with custom actions not being sent if tracked as …
ncreated Dec 13, 2021
44a15a8
RUMM-1765 Inject SDK init time to RUM application scope
ncreated Dec 13, 2021
9cc6cd4
RUMM-1765 Start 'ApplicationLaunch' view using the time of SDK init
ncreated Dec 13, 2021
64bcce5
RUMM-1765 Fix `Benchmarks` build
ncreated Dec 13, 2021
87f9639
RUMM-1765 Update `CrashContext` with RUM session info and application…
ncreated Dec 14, 2021
c14df6a
RUMM-1765 Add separate unit tests for `RUMOffViewEventsHandlingRule`
ncreated Dec 16, 2021
5f03f4e
RUMM-1765 Implement separate `Core` component for sampling
ncreated Dec 14, 2021
3922189
RUMM-1765 Inject `Sampler` to RUM
ncreated Dec 14, 2021
de82efe
RUM-1805 Set PLCrashReporter custom path
maxep Dec 17, 2021
b43a12e
RUMM-1765 Send application launch crashes in new RUM session
ncreated Dec 17, 2021
33df857
RUM-1805 Lets PLCrashReporter create the custom subdirectory
maxep Dec 20, 2021
6ecd331
RUMM-1839 Fix Application Launch Handler Memory Leak
maxep Dec 20, 2021
83f75a9
Merge pull request #685 from DataDog/ncreated/RUMM-1765-do-not-start-…
ncreated Dec 20, 2021
bdccc5e
Merge pull request #694 from DataDog/maxeo/RUMM-1839/fix-app-launch-h…
maxep Dec 20, 2021
0ea2b5f
Merge pull request #692 from DataDog/maxeo/RUMM-1805/crash-reports-lo…
maxep Dec 20, 2021
bb4732b
Merge pull request #690 from DataDog/ncreated/RUMM-1765-collect-app-l…
ncreated Dec 21, 2021
36a5197
RUMM-1765 Handle background crashes which happened in the previous se…
ncreated Dec 21, 2021
332620f
RUMM-1765 Add features for debugging background crashes in Example app
ncreated Dec 17, 2021
7a6548a
RUMM-1765 Update `AppStateListener` to provide more accurate informat…
ncreated Dec 20, 2021
0813c48
RUMM-1765 Apply CR feedback from #685
ncreated Dec 20, 2021
a7b0242
RUMM-1765 CR feedback - fix number of iterations in `AppStateListener…
ncreated Dec 22, 2021
4910a31
Merge pull request #695 from DataDog/ncreated/RUMM-1765-send-app-laun…
ncreated Dec 22, 2021
0b4ae5e
Merge pull request #696 from DataDog/ncreated/RUMM-1765-fix-foregroun…
ncreated Dec 22, 2021
b733c29
Merge pull request #697 from DataDog/ncreated/RUMM-1765-CR-feedback
ncreated Dec 22, 2021
d8c0efc
Merge branch 'master' into ncreated/RUMM-1765-app-launch-events-tracking
ncreated Dec 22, 2021
e3468ed
Merge pull request #699 from DataDog/ncreated/RUMM-1765-app-launch-ev…
ncreated Dec 22, 2021
562d454
RUMM-1744 Copy & paste Kronos code and tests into SDK
ncreated Dec 28, 2021
11d5602
RUMM-1744 Unlink Kronos dependency from the SDK
ncreated Dec 28, 2021
0ec79ae
RUMM-1744 Fix import statement in tests to make it compile
ncreated Dec 28, 2021
3a20977
RUMM-1744 Annotate all Kronos types with "Kronos" prefix and adjust t…
ncreated Dec 28, 2021
733c0e2
RUMM-1744 Adjust Kronos code to pass our linter
ncreated Dec 28, 2021
aa5279c
RUMM-1744 Add license header including 'MobileNativeFoundation' copyr…
ncreated Dec 29, 2021
514e493
RUMM-1744 Update LICENSE-3rdparty.csv to include 'MobileNativeFoundat…
ncreated Dec 29, 2021
8a17f5c
RUMM-1779 Keep view active until all resources are consumed
maxep Dec 29, 2021
d68908b
Merge pull request #701 from DataDog/ncreated/RUMM-1744-move-Kronos-c…
ncreated Dec 30, 2021
92a8105
RUMM-1779 Assert no event is sent after view is inactive
maxep Dec 30, 2021
1e9c097
RUMM-1744 Add E2E tests for Kronos
ncreated Dec 30, 2021
3f48e78
Merge pull request #703 from DataDog/ncreated/RUMM-1744-stabilize-Kro…
ncreated Dec 31, 2021
87161de
Merge pull request #702 from DataDog/maxep/RUMM-1779/keep-view-active
maxep Dec 31, 2021
5fd9d56
RUMM-1744 Add `Version` type to distribution tool
ncreated Jan 3, 2022
c6a9c08
RUMM-1744 Add `DirectoryMatcher` type to distribution tool
ncreated Jan 3, 2022
f40de15
RUMM-1744 Define separate validators for each XCFramework
ncreated Jan 3, 2022
0d517e5
RUMM-1744 Cleanup
ncreated Jan 3, 2022
3f47ccc
Merge pull request #704 from DataDog/ncreated/RUMM-1744-update-releas…
ncreated Jan 5, 2022
85f6ec8
RUMM-1799 Clarify linking crash reporting using SPM
maxep Jan 4, 2022
0c96d0a
Merge pull request #708 from DataDog/ncreated/RUMM-1744-embed-Kronos-…
ncreated Jan 5, 2022
b4d285b
Merge pull request #707 from DataDog/maxep/RUMM-1799/crash-reporting-…
maxep Jan 6, 2022
a2f8a1f
RUMM-1744 Collect Kronos telemetry if Internal Monitoring is enabled
ncreated Jan 7, 2022
62b76a8
RUMM-1744 Instrument Kronos E2E tests with `KronosInternalMonitor`
ncreated Jan 7, 2022
062f279
RUMM-1890 Fix flakiness in `CrashContextTests` when running below iOS…
ncreated Jan 10, 2022
583766c
RUMM-1890 Fix flakiness in `DataUploadWorkerTests`
ncreated Jan 10, 2022
b97b9ea
RUMM-1890 Fix flakiness in `VitalRefreshRateReaderTests`
ncreated Jan 10, 2022
ab4d65d
RUMM-1890 Add more verbosity to failure in `CrashContextProviderTests`
ncreated Jan 10, 2022
cc5058d
RUMM-1890 Fix flakiness in `testItStoresWeakReferenceToUIViewController`
ncreated Jan 10, 2022
36d0b47
RUMM-1890 Fix flakiness in `testWhenSamplingRateIs50_onlyHalfOfTheEve…
ncreated Jan 10, 2022
70d8729
RUMM-1890 CR feedback
ncreated Jan 11, 2022
10b4943
Merge pull request #711 from DataDog/ncreated/RUMM-1890-fix-issues-fr…
ncreated Jan 11, 2022
79c63be
Merge pull request #709 from DataDog/ncreated/RUMM-1744-collect-Krono…
ncreated Jan 11, 2022
beeb9bb
Merge master into merge-from-master
buranmert Jan 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ instrumented-tests/LICENSE
venv
*.pyc
__pycache__
*.swp
3 changes: 1 addition & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
github "lyft/Kronos" ~> 4.2
github "microsoft/plcrashreporter" ~> 1.10.0
github "microsoft/plcrashreporter" ~> 1.10.1
3 changes: 1 addition & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
github "lyft/Kronos" "4.2.1"
github "microsoft/plcrashreporter" "1.10.0"
github "microsoft/plcrashreporter" "1.10.1"
340 changes: 273 additions & 67 deletions Datadog/Datadog.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1310"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1310"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1310"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1310"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1310"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1310"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1310"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1310"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1310"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -50,12 +50,27 @@
ReferencedContainer = "container:Datadog.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "DD_DEBUG"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "DD_DEBUG_RUM"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
<EnvironmentVariable
key = "DD_TEST_SCENARIO_CLASS_NAME"
value = "LoggingManualInstrumentationScenario"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "DD_TEST_SCENARIO_CLASS_NAME"
value = "RUMSwiftUIInstrumentationScenario"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "DD_TEST_SCENARIO_CLASS_NAME"
value = "RUMMobileVitalsScenario"
Expand Down
7 changes: 5 additions & 2 deletions Datadog/E2ETests/E2ETests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ class E2ETests: XCTestCase {
// MARK: - Measuring Performance with APM

/// Measures time of execution for given `block` - sends it as a `"perf_measure"` `Span` with a given resource name.
func measure(resourceName: String, _ block: () -> Void) {
@discardableResult
func measure<T>(resourceName: String, _ block: () -> T) -> T {
let start = Date()
block()
let result = block()
let stop = Date()

let performanceSpan = Global.sharedTracer.startRootSpan(operationName: "perf_measure", startTime: start)
performanceSpan.setTag(key: DDTags.resource, value: resourceName)
performanceSpan.finish(at: stop)

return result
}

// MARK: - SDK Lifecycle
Expand Down
224 changes: 224 additions & 0 deletions Datadog/E2ETests/NTP/KronosE2ETests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-2020 Datadog, Inc.
*/

@testable import Datadog

class KronosE2ETests: E2ETests {
/// The logger sending logs on Kronos execution. These logs are available in Mobile Integrations org.
private var logger: Logger! // swiftlint:disable:this implicitly_unwrapped_optional
/// The logger sending telemetry on internal Kronos execution. These logs are available in Mobile Integrations org.
private var telemetryLogger: Logger! // swiftlint:disable:this implicitly_unwrapped_optional
private let queue = DispatchQueue(label: "kronos-monitor-queue")

override func setUp() {
super.setUp()
logger = Logger
.builder
.set(loggerName: "kronos-e2e")
.build()
telemetryLogger = Logger.builder
.set(loggerName: "kronos-e2e-internal-telemetry")
.sendNetworkInfo(true)
.build()
}

override func tearDown() {
logger = nil
telemetryLogger = nil
super.tearDown()
}

/// Creates kronos monitor for checking connections to all IPs resolved from NTP pool and sending additional telemetry on their statuses.
private func createKronosMonitor() -> KronosMonitor? {
if #available(iOS 14.2, *) {
let monitor = KronosInternalMonitor(
queue: queue,
connectionMonitor: IPConnectionMonitor(queue: queue)
)
// Here we redirect IM's logger to E2E Kronos logger (`telemetryLogger`) to send data to Mobile Integrations org, not IM's org
monitor.export(to: InternalMonitor(sdkLogger: telemetryLogger))
return monitor
} else {
return nil
}
}

/// TODO: RUMM-1859: Add E2E tests for monitoring Kronos in nightly tests
func test_kronos_clock_performs_sync_using_datadog_ntp_pool() { // E2E:wip
/// The result of `KronosClock.sync()`.
struct KronosSyncResult {
/// First received server date.
var firstReceivedDate: Date? = nil
/// First received server offset.
var firstReceivedOffset: TimeInterval? = nil
/// Last received server date.
var lastReceivedDate: Date? = nil
/// Last received server offset.
var lastReceivedOffset: TimeInterval? = nil
/// Device date measured at the moment of receiving any server date. Used for additional debugging and comparision.
var measuredDeviceDate = Date()
}

func performKronosSync(using pool: String) -> KronosSyncResult {
KronosClock.reset()
defer { KronosClock.reset() }

// Given
let numberOfSamplesForEachIP = 2 // exchange only 2 samples with each resolved IP - to run test quick

// Each IP (each server) is asked in parallel, but samples are obtained sequentially.
// Here we compute test timeout, to ensure that all (parallel) servers complete querying their (sequential) samples
// below `testTimeout` with assuming +50% margin. This should guarantee no flakiness on test timeout.
let testTimeout = kronosDefaultTimeout * Double(numberOfSamplesForEachIP) * 1.5

// When
let completionExpectation = expectation(description: "KronosClock.sync() calls completion closure")
var result = KronosSyncResult()

KronosClock.sync(
from: pool,
samples: numberOfSamplesForEachIP,
monitor: createKronosMonitor(),
first: { date, offset in // this closure could not be called if all samples to all servers resulted with failure
result.firstReceivedDate = date
result.firstReceivedOffset = offset
result.measuredDeviceDate = Date()
},
completion: { date, offset in // this closure should always be called
result.lastReceivedDate = date
result.lastReceivedOffset = offset
result.measuredDeviceDate = Date()
completionExpectation.fulfill()
}
)

// Then

// We don't expect receiving timeout on `completionExpectation`. Number of samples and individual sample timeout
// is configured in a way that lets `KronosNTPClient` always fulfill the `completionExpectation`.
waitForExpectations(timeout: testTimeout)

return result
}

// Run test for each Datadog NTP pool:
DateCorrector.datadogNTPServers.forEach { ddNTPPool in
let result = measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
performKronosSync(using: ddNTPPool)
}

// Report result for this pool:
if let _ = result.firstReceivedDate, let _ = result.firstReceivedOffset, let serverDate = result.lastReceivedDate, let serverOffset = result.lastReceivedOffset {
// We consider `KronosClock.sync()` result to be consistent only if it has both `first` and `last` time values set.
// We log consistent result as INFO log that can be seen in Mobile Integration org.
logger.info("KronosClock.sync() completed with consistent result for \(ddNTPPool)", attributes: [
"serverOffset_measured": serverDate.timeIntervalSince(result.measuredDeviceDate),
"serverOffset_received": serverOffset,
"serverDate_received": iso8601DateFormatter.string(from: serverDate),
])
} else {
// Inconsistent result may correspond to flaky execution, e.g. if network was unreachable or if **all** NTP calls received timeout.
// We track inconsistent result as WARN log that will be watched by E2E monitor.
logger.warn("KronosClock.sync() completed with inconsistent result for \(ddNTPPool)", attributes: [
"serverDate_firstReceived": result.firstReceivedDate.flatMap { iso8601DateFormatter.string(from: $0) },
"serverDate_lastReceived": result.lastReceivedDate.flatMap { iso8601DateFormatter.string(from: $0) },
"serverOffset_firstReceived": result.firstReceivedOffset,
"serverOffset_lastReceived": result.lastReceivedOffset,
])
}
}
}

/// TODO: RUMM-1859: Add E2E tests for monitoring Kronos in nightly tests
func test_kronos_ntp_client_queries_both_ipv4_and_ipv6_ips() { // E2E:wip
/// The result of `KronosNTPClient.query(pool:)`.
struct KronosNTPClientQueryResult {
/// Partial offsets received for each NTP packet sent to each resolved IP.
var receivedOffsets: [TimeInterval?] = []
/// Expected number of NTP packets to send.
var expectedNumberOfSamples = 0
/// Actual number of NTP packets that completed.
var numberOfCompletedSamples = 0
}

func performKronosNTPClientQuery() -> KronosNTPClientQueryResult {
let testTimeout: TimeInterval = 30
let monitor = createKronosMonitor()

// Given
let pool = "2.datadog.pool.ntp.org" // a pool resolved to multiple IPv4 and IPv6 addresses (e.g. 4 + 4)
let numberOfSamplesForEachIP = 2 // exchange only 2 samples with each resolved IP - to run test quick

// Each IP (each server) is asked in parallel, but samples are obtained sequentially.
// Here we compute individual sample timeout, to ensure that all (parallel) servers complete querying their (sequential) samples
// below `testTimeout` with assuming -30% margin. This should guarantee no flakiness on test timeout.
let timeoutForEachSample = (testTimeout / Double(numberOfSamplesForEachIP)) * 0.7

// When
let completionExpectation = expectation(description: "It completes all samples for all IPs")
var result = KronosNTPClientQueryResult()

monitor?.notifySyncStart(from: pool) // must be notified by hand because normally it's called from `KronosClock.sync()`

KronosNTPClient()
.query(
pool: pool,
numberOfSamples: numberOfSamplesForEachIP,
maximumServers: .max, // query all resolved IPs in the pool - to include both IPv4 and IPv6
timeout: timeoutForEachSample,
monitor: monitor
) { offset, completed, total in
result.receivedOffsets.append(offset)
result.numberOfCompletedSamples = completed
result.expectedNumberOfSamples = total

if completed == total {
monitor?.notifySyncEnd(serverOffset: offset) // must be notified by hand because normally it's called from `KronosClock.sync()`
completionExpectation.fulfill()
}
}

// Then

// We don't expect receiving timeout on `completionExpectation`. Number of samples and individual sample timeout
// is configured in a way that lets `KronosNTPClient` always fulfill the `completionExpectation`.
// In worst case, it can fulfill it, with recording only `nil` offsets, which will mean receiving timeouts
// or error on all NTP queries.
waitForExpectations(timeout: testTimeout)

return result
}

// Run test:
let result = measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
performKronosNTPClientQuery()
}

// Report result:
if result.receivedOffsets.contains(where: { offset in offset != nil }) {
// We consider `KronosNTPClient.query(pool:)` result to be consistent if it received at least one offset.
let receivedOffsets: [String] = result.receivedOffsets.map { offset in
if let offset = offset {
return "\(offset)"
} else {
return "(nil)"
}
}
logger.info(
"KronosNTPClient.query(pool:) completed with consistent result receiving \(result.numberOfCompletedSamples)/\(result.expectedNumberOfSamples) NTP packets",
attributes: [
"offsets_received": receivedOffsets
]
)
} else {
// Inconsistent result may correspond to flaky execution, e.g. if network was unreachable or if **all** NTP calls received timeout.
// We track inconsistent result as WARN log that will be watched by E2E monitor.
logger.warn(
"KronosNTPClient.query(pool:) completed with inconsistent result receiving \(result.numberOfCompletedSamples)/\(result.expectedNumberOfSamples) NTP packets"
)
}
}
}
1 change: 1 addition & 0 deletions Datadog/Example/AppConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct ExampleAppConfiguration: AppConfiguration {
.enableTracing(true)
.enableRUM(true)
.enableCrashReporting(using: DDCrashReportingPlugin())
.trackBackgroundEvents()
}

return configuration.build()
Expand Down
Loading