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

macOS: Add pixels to track VPN wake and stop attempts #2694

Merged
merged 9 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
14 changes: 6 additions & 8 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,6 @@
4B2D06292A11C0C900DE1F49 /* Bundle+VPN.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4D605E2A0B29FA00BCD287 /* Bundle+VPN.swift */; };
4B2D062A2A11C0C900DE1F49 /* NetworkProtectionOptionKeyExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4D605F2A0B29FA00BCD287 /* NetworkProtectionOptionKeyExtension.swift */; };
4B2D062C2A11C0E100DE1F49 /* Networking in Frameworks */ = {isa = PBXBuildFile; productRef = 4B2D062B2A11C0E100DE1F49 /* Networking */; };
4B2D062D2A11C12300DE1F49 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85799C1725DEBB3F0007EC87 /* Logging.swift */; };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want Logging.swift in system extensions, so I removed it from our tunnel and proxy sysexes.

4B2D06322A11C1D300DE1F49 /* NSApplicationExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA5C8F622591021700748EB7 /* NSApplicationExtension.swift */; };
4B2D06332A11C1E300DE1F49 /* OptionalExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B637273C26CCF0C200C8CB02 /* OptionalExtension.swift */; };
4B2D065B2A11D1FF00DE1F49 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4BEC322A11B509001D9AC5 /* Logging.swift */; };
Expand Down Expand Up @@ -1488,7 +1487,6 @@
7B97CD5D2B7E0BCE004FEF43 /* BundleExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6106B9D26A565DA0013B453 /* BundleExtension.swift */; };
7B97CD5E2B7E0BEA004FEF43 /* OptionalExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B637273C26CCF0C200C8CB02 /* OptionalExtension.swift */; };
7B97CD5F2B7E0BF7004FEF43 /* NSApplicationExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA5C8F622591021700748EB7 /* NSApplicationExtension.swift */; };
7B97CD602B7E0C2E004FEF43 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85799C1725DEBB3F0007EC87 /* Logging.swift */; };
7BA076BB2B65D61400D7FB72 /* NetworkProtectionProxy in Frameworks */ = {isa = PBXBuildFile; productRef = 7BA076BA2B65D61400D7FB72 /* NetworkProtectionProxy */; };
7BA4727D26F01BC400EAA165 /* CoreDataTestUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9292C42667104B00AD2C21 /* CoreDataTestUtilities.swift */; };
7BA59C9B2AE18B49009A97B1 /* SystemExtensionManager in Frameworks */ = {isa = PBXBuildFile; productRef = 7BA59C9A2AE18B49009A97B1 /* SystemExtensionManager */; };
Expand Down Expand Up @@ -3242,6 +3240,7 @@
7B2DDCF72A93A8BB0039D884 /* NetworkProtectionAppEvents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionAppEvents.swift; sourceTree = "<group>"; };
7B2E52242A5FEC09000C6D39 /* NetworkProtectionAgentNotificationsPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkProtectionAgentNotificationsPresenter.swift; sourceTree = "<group>"; };
7B3618C12ADE75C8000D6154 /* NetworkProtectionNavBarPopoverManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionNavBarPopoverManager.swift; sourceTree = "<group>"; };
7B427BA82BD81D8C0014AE6C /* BrowserServicesKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = BrowserServicesKit; path = ../../BrowserServicesKit; sourceTree = "<group>"; };
7B430EA02A71411A00BAC4A1 /* NetworkProtectionSimulateFailureMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionSimulateFailureMenu.swift; sourceTree = "<group>"; };
7B4CE8DA26F02108009134B1 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
7B4CE8E626F02134009134B1 /* TabBarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4652,6 +4651,7 @@
378E279C2970217400FCADA2 /* LocalPackages */ = {
isa = PBXGroup;
children = (
7B427BA82BD81D8C0014AE6C /* BrowserServicesKit */,
378E279D2970217400FCADA2 /* BuildToolPlugins */,
3192A2702A4C4E330084EA89 /* DataBrokerProtection */,
9DB6E7222AA0DA7A00A17F3C /* LoginItems */,
Expand Down Expand Up @@ -10399,7 +10399,6 @@
4B25377A2A11C01700610219 /* UserText+NetworkProtectionExtensions.swift in Sources */,
B65DA5F42A77D3FA00CBEE8D /* BundleExtension.swift in Sources */,
EE66418D2B9B1981005BCD17 /* NetworkProtectionTokenStore+SubscriptionTokenKeychainStorage.swift in Sources */,
4B2D062D2A11C12300DE1F49 /* Logging.swift in Sources */,
7B2E52252A5FEC09000C6D39 /* NetworkProtectionAgentNotificationsPresenter.swift in Sources */,
B602E8232A1E260E006D261F /* Bundle+NetworkProtectionExtensions.swift in Sources */,
4B2D062A2A11C0C900DE1F49 /* NetworkProtectionOptionKeyExtension.swift in Sources */,
Expand Down Expand Up @@ -10561,7 +10560,6 @@
buildActionMask = 2147483647;
files = (
7B97CD5C2B7E0BBB004FEF43 /* UserDefaultsWrapper.swift in Sources */,
7B97CD602B7E0C2E004FEF43 /* Logging.swift in Sources */,
7B97CD5E2B7E0BEA004FEF43 /* OptionalExtension.swift in Sources */,
7B97CD5F2B7E0BF7004FEF43 /* NSApplicationExtension.swift in Sources */,
7BDA36F52B7E055800AD5388 /* MacTransparentProxyProvider.swift in Sources */,
Expand Down Expand Up @@ -12599,8 +12597,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 138.0.0;
kind = revision;
revision = a29350fafa5533cde9613d1bd8bf82f0b2d8b6d8;
};
};
4311906792B7676CE9535D76 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */ = {
Expand All @@ -12615,8 +12613,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 139.0.0;
kind = revision;
revision = fa4ade40bc72129171123689d2f6b5d4e3266f61;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
"version" : "3.0.0"
}
},
{
"identity" : "browserserviceskit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "1c2e84e6cd4543e9104aff753e48b146eeb36007",
"version" : "139.0.0"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -120,7 +111,7 @@
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
Expand All @@ -138,7 +129,7 @@
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
case networkProtectionTunnelStartSuccess
case networkProtectionTunnelStartFailure(_ error: Error)

case networkProtectionTunnelStopAttempt
case networkProtectionTunnelStopSuccess
case networkProtectionTunnelStopFailure(_ error: Error)

case networkProtectionTunnelUpdateAttempt
case networkProtectionTunnelUpdateSuccess
case networkProtectionTunnelUpdateFailure(_ error: Error)

case networkProtectionTunnelWakeAttempt
case networkProtectionTunnelWakeSuccess
case networkProtectionTunnelWakeFailure(_ error: Error)

case networkProtectionEnableAttemptConnecting
case networkProtectionEnableAttemptSuccess
case networkProtectionEnableAttemptFailure
Expand Down Expand Up @@ -119,6 +127,15 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
case .networkProtectionTunnelStartFailure:
return "netp_tunnel_start_failure"

case .networkProtectionTunnelStopAttempt:
return "netp_tunnel_stop_attempt"

case .networkProtectionTunnelStopSuccess:
return "netp_tunnel_stop_success"

case .networkProtectionTunnelStopFailure:
return "netp_tunnel_stop_failure"

case .networkProtectionTunnelUpdateAttempt:
return "netp_tunnel_update_attempt"

Expand All @@ -128,6 +145,15 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
case .networkProtectionTunnelUpdateFailure:
return "netp_tunnel_update_failure"

case .networkProtectionTunnelWakeAttempt:
return "netp_tunnel_wake_attempt"

case .networkProtectionTunnelWakeSuccess:
return "netp_tunnel_wake_success"

case .networkProtectionTunnelWakeFailure:
return "netp_tunnel_wake_failure"

case .networkProtectionEnableAttemptConnecting:
return "netp_ev_enable_attempt"

Expand Down Expand Up @@ -300,9 +326,15 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
.networkProtectionTunnelStartAttempt,
.networkProtectionTunnelStartSuccess,
.networkProtectionTunnelStartFailure,
.networkProtectionTunnelStopAttempt,
.networkProtectionTunnelStopSuccess,
.networkProtectionTunnelStopFailure,
.networkProtectionTunnelUpdateAttempt,
.networkProtectionTunnelUpdateSuccess,
.networkProtectionTunnelUpdateFailure,
.networkProtectionTunnelWakeAttempt,
.networkProtectionTunnelWakeSuccess,
.networkProtectionTunnelWakeFailure,
.networkProtectionEnableAttemptConnecting,
.networkProtectionEnableAttemptSuccess,
.networkProtectionEnableAttemptFailure,
Expand Down Expand Up @@ -343,7 +375,9 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
return error
case .networkProtectionControllerStartFailure(let error),
.networkProtectionTunnelStartFailure(let error),
.networkProtectionTunnelStopFailure(let error),
.networkProtectionTunnelUpdateFailure(let error),
.networkProtectionTunnelWakeFailure(let error),
.networkProtectionClientFailedToParseRedeemResponse(let error),
.networkProtectionWireguardErrorCannotSetNetworkSettings(let error),
.networkProtectionRekeyFailure(let error),
Expand All @@ -356,8 +390,12 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {
.networkProtectionControllerStartSuccess,
.networkProtectionTunnelStartAttempt,
.networkProtectionTunnelStartSuccess,
.networkProtectionTunnelStopAttempt,
.networkProtectionTunnelStopSuccess,
.networkProtectionTunnelUpdateAttempt,
.networkProtectionTunnelUpdateSuccess,
.networkProtectionTunnelWakeAttempt,
.networkProtectionTunnelWakeSuccess,
.networkProtectionEnableAttemptConnecting,
.networkProtectionEnableAttemptSuccess,
.networkProtectionEnableAttemptFailure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//

import Combine
import Common
import Foundation
import Subscription
import NetworkProtection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ final class MacPacketTunnelProvider: PacketTunnelProvider {
frequency: .dailyAndCount,
includeAppVersionParameter: true)
}
case .tunnelStopAttempt(let step):
switch step {
case .begin:
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelStopAttempt,
frequency: .standard,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Daily attempts are useless, unfortunately.

includeAppVersionParameter: true)
case .failure(let error):
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelStopFailure(error),
frequency: .dailyAndCount,
includeAppVersionParameter: true)
case .success:
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelStopSuccess,
frequency: .dailyAndCount,
includeAppVersionParameter: true)
}
case .tunnelUpdateAttempt(let step):
switch step {
case .begin:
Expand All @@ -251,6 +269,24 @@ final class MacPacketTunnelProvider: PacketTunnelProvider {
frequency: .dailyAndCount,
includeAppVersionParameter: true)
}
case .tunnelWakeAttempt(let step):
switch step {
case .begin:
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelWakeAttempt,
frequency: .dailyAndCount,
includeAppVersionParameter: true)
case .failure(let error):
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelWakeFailure(error),
frequency: .dailyAndCount,
includeAppVersionParameter: true)
case .success:
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionTunnelWakeSuccess,
frequency: .dailyAndCount,
includeAppVersionParameter: true)
}
}
}

Expand Down Expand Up @@ -421,30 +457,6 @@ final class MacPacketTunnelProvider: PacketTunnelProvider {
try? loadDefaultPixelHeaders(from: options)
}

// MARK: - Start/Stop Tunnel

override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
super.stopTunnel(with: reason) {
Task {
completionHandler()

// From what I'm seeing in my tests the next call to start the tunnel is MUCH
// less likely to fail if we force this extension to exit when the tunnel is killed.
//
// Ref: https://app.asana.com/0/72649045549333/1204668639086684/f
//
exit(EXIT_SUCCESS)
Copy link
Contributor Author

@diegoreymendez diegoreymendez Apr 24, 2024

Choose a reason for hiding this comment

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

I found that after our recent changes, stopping the VPN works best when this is removed. Sometimes it was taking a while to stop with this still here.

I'll be testing this in macOS 11 on the intel mac mini shortly.

}
}
}

override func cancelTunnelWithError(_ error: Error?) {
Task {
super.cancelTunnelWithError(error)
exit(EXIT_SUCCESS)
}
}

// MARK: - Pixels

private func setupPixels(defaultHeaders: [String: String] = [:]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import PixelKit

final class MacTransparentProxyProvider: TransparentProxyProvider {

static var vpnProxyLogger = Logger(subsystem: OSLog.subsystem, category: "VPN Proxy")
static var vpnProxyLogger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "DuckDuckGo", category: "VPN Proxy")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to avoid the dependency with Logging.swift.


private var cancellables = Set<AnyCancellable>()

Expand Down