From eb40c83ff5937c9da27351f49780c5fd00cc7769 Mon Sep 17 00:00:00 2001 From: Sam Symons Date: Thu, 13 Jun 2024 13:47:35 -0700 Subject: [PATCH] Fast egress server draining (#2858) Task/Issue URL: https://app.asana.com/0/1203137811378537/1207555842602667/f Tech Design URL: CC: Description: This PR adds support for fast egress server draining. All of the real work happens on the BSK side, this PR just wires up events to pixels. --- DuckDuckGo.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 4 +- .../NetworkProtectionPixelEvent.swift | 42 +++++++++++++++++-- .../EventMapping+NetworkProtectionError.swift | 4 +- .../MacPacketTunnelProvider.swift | 22 ++++++++++ .../DataBrokerProtection/Package.swift | 2 +- .../NetworkProtectionMac/Package.swift | 2 +- LocalPackages/SubscriptionUI/Package.swift | 2 +- 8 files changed, 69 insertions(+), 11 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 7082165319..ef27acffa8 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -13078,7 +13078,7 @@ repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = 153.0.0; + version = 154.0.0; }; }; 9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 8bc4cd1715..405134d91b 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/BrowserServicesKit", "state" : { - "revision" : "b78ae617c7fe66244741f489158a1f40e567e674", - "version" : "153.0.0" + "revision" : "2045f13479f3da34b827198b43ae7a47e01551cf", + "version" : "154.0.0" } }, { diff --git a/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift b/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift index a5fa99cb35..4d19a8149b 100644 --- a/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift +++ b/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift @@ -47,6 +47,10 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { case networkProtectionTunnelWakeSuccess case networkProtectionTunnelWakeFailure(_ error: Error) + case networkProtectionServerMigrationAttempt + case networkProtectionServerMigrationSuccess + case networkProtectionServerMigrationFailure(_ error: Error) + case networkProtectionEnableAttemptConnecting case networkProtectionEnableAttemptSuccess case networkProtectionEnableAttemptFailure @@ -74,6 +78,8 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { case networkProtectionClientFailedToParseRedeemResponse(_ error: Error) case networkProtectionClientFailedToFetchLocations(_ error: Error?) case networkProtectionClientFailedToParseLocationsResponse(_ error: Error?) + case networkProtectionClientFailedToFetchServerStatus(_ error: Error?) + case networkProtectionClientFailedToParseServerStatusResponse(_ error: Error?) case networkProtectionClientInvalidAuthToken case networkProtectionKeychainErrorFailedToCastKeychainValueToData(field: String) @@ -275,6 +281,21 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { case .networkProtectionSystemExtensionActivationFailure: return "netp_system_extension_activation_failure" + case .networkProtectionClientFailedToFetchServerStatus: + return "netp_server_migration_failed_to_fetch_status" + + case .networkProtectionClientFailedToParseServerStatusResponse: + return "netp_server_migration_failed_to_parse_response" + + case .networkProtectionServerMigrationAttempt: + return "netp_ev_server_migration_attempt" + + case .networkProtectionServerMigrationFailure: + return "netp_ev_server_migration_attempt_failure" + + case .networkProtectionServerMigrationSuccess: + return "netp_ev_server_migration_attempt_success" + case .networkProtectionUnhandledError: return "netp_unhandled_error" } @@ -320,8 +341,14 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { return error.pixelParameters case .networkProtectionWireguardErrorCannotStartWireguardBackend(code: let code): return [PixelKit.Parameters.errorCode: String(code)] + case .networkProtectionClientFailedToFetchServerStatus(let error): + return error?.pixelParameters + case .networkProtectionClientFailedToParseServerStatusResponse(let error): + return error?.pixelParameters case .networkProtectionWireguardErrorInvalidState(reason: let reason): return [PixelKit.Parameters.reason: reason] + case .networkProtectionServerMigrationFailure: + return error?.pixelParameters case .networkProtectionActiveUser, .networkProtectionNewUser, .networkProtectionControllerStartAttempt, @@ -365,7 +392,9 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { .networkProtectionRekeyAttempt, .networkProtectionRekeyCompleted, .networkProtectionRekeyFailure, - .networkProtectionSystemExtensionActivationFailure: + .networkProtectionSystemExtensionActivationFailure, + .networkProtectionServerMigrationAttempt, + .networkProtectionServerMigrationSuccess: return nil } } @@ -376,7 +405,9 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { .networkProtectionClientFailedToFetchLocations(let error), .networkProtectionClientFailedToParseLocationsResponse(let error), .networkProtectionClientFailedToFetchServerList(let error), - .networkProtectionClientFailedToFetchRegisteredServers(let error): + .networkProtectionClientFailedToFetchRegisteredServers(let error), + .networkProtectionClientFailedToFetchServerStatus(let error), + .networkProtectionClientFailedToParseServerStatusResponse(let error): return error case .networkProtectionControllerStartFailure(let error), .networkProtectionTunnelStartFailure(let error), @@ -387,7 +418,8 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { .networkProtectionWireguardErrorCannotSetNetworkSettings(let error), .networkProtectionRekeyFailure(let error), .networkProtectionUnhandledError(_, _, let error), - .networkProtectionSystemExtensionActivationFailure(let error): + .networkProtectionSystemExtensionActivationFailure(let error), + .networkProtectionServerMigrationFailure(let error): return error case .networkProtectionActiveUser, .networkProtectionNewUser, @@ -431,7 +463,9 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { .networkProtectionWireguardErrorCannotStartWireguardBackend, .networkProtectionNoAuthTokenFoundError, .networkProtectionRekeyAttempt, - .networkProtectionRekeyCompleted: + .networkProtectionRekeyCompleted, + .networkProtectionServerMigrationAttempt, + .networkProtectionServerMigrationSuccess: return nil } } diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/EventMapping+NetworkProtectionError.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/EventMapping+NetworkProtectionError.swift index 3a068bfed6..fc47c35d55 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/EventMapping+NetworkProtectionError.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/EventMapping+NetworkProtectionError.swift @@ -82,7 +82,9 @@ extension EventMapping where Event == NetworkProtectionError { .wireGuardDnsResolution, .wireGuardSetNetworkSettings, .startWireGuardBackend, - .failedToRetrieveAuthToken: + .failedToRetrieveAuthToken, + .failedToFetchServerStatus, + .failedToParseServerStatusResponse: domainEvent = .networkProtectionUnhandledError(function: #function, line: #line, error: event) frequency = .standard return diff --git a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift index 8b4fd7288d..054745409a 100644 --- a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift +++ b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift @@ -115,6 +115,10 @@ final class MacPacketTunnelProvider: PacketTunnelProvider { domainEvent = .networkProtectionWireguardErrorCannotStartWireguardBackend(code: code) case .noAuthTokenFound: domainEvent = .networkProtectionNoAuthTokenFoundError + case .failedToFetchServerStatus(let error): + domainEvent = .networkProtectionClientFailedToFetchServerStatus(error) + case .failedToParseServerStatusResponse(let error): + domainEvent = .networkProtectionClientFailedToParseServerStatusResponse(error) case .unhandledError(function: let function, line: let line, error: let error): domainEvent = .networkProtectionUnhandledError(function: function, line: line, error: error) case .failedToRetrieveAuthToken, @@ -312,6 +316,24 @@ final class MacPacketTunnelProvider: PacketTunnelProvider { includeAppVersionParameter: true ) } + case .serverMigrationAttempt(let step): + switch step { + case .begin: + PixelKit.fire( + NetworkProtectionPixelEvent.networkProtectionServerMigrationAttempt, + frequency: .dailyAndCount, + includeAppVersionParameter: true) + case .failure(let error): + PixelKit.fire( + NetworkProtectionPixelEvent.networkProtectionServerMigrationFailure(error), + frequency: .dailyAndCount, + includeAppVersionParameter: true) + case .success: + PixelKit.fire( + NetworkProtectionPixelEvent.networkProtectionServerMigrationSuccess, + frequency: .dailyAndCount, + includeAppVersionParameter: true) + } } } diff --git a/LocalPackages/DataBrokerProtection/Package.swift b/LocalPackages/DataBrokerProtection/Package.swift index fc6b5e2af2..a5a2e25958 100644 --- a/LocalPackages/DataBrokerProtection/Package.swift +++ b/LocalPackages/DataBrokerProtection/Package.swift @@ -29,7 +29,7 @@ let package = Package( targets: ["DataBrokerProtection"]) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "153.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "154.0.0"), .package(path: "../SwiftUIExtensions"), .package(path: "../XPCHelper"), ], diff --git a/LocalPackages/NetworkProtectionMac/Package.swift b/LocalPackages/NetworkProtectionMac/Package.swift index a87366d64a..9e05b6db81 100644 --- a/LocalPackages/NetworkProtectionMac/Package.swift +++ b/LocalPackages/NetworkProtectionMac/Package.swift @@ -32,7 +32,7 @@ let package = Package( .library(name: "VPNAppLauncher", targets: ["VPNAppLauncher"]), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "153.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "154.0.0"), .package(url: "https://github.com/airbnb/lottie-spm", exact: "4.4.1"), .package(path: "../AppLauncher"), .package(path: "../UDSHelper"), diff --git a/LocalPackages/SubscriptionUI/Package.swift b/LocalPackages/SubscriptionUI/Package.swift index 86a9679004..c3e64dba9b 100644 --- a/LocalPackages/SubscriptionUI/Package.swift +++ b/LocalPackages/SubscriptionUI/Package.swift @@ -12,7 +12,7 @@ let package = Package( targets: ["SubscriptionUI"]), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "153.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "154.0.0"), .package(path: "../SwiftUIExtensions") ], targets: [