Skip to content

Commit

Permalink
Add connection tester failure pixels (#3049)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1206580121312550/1207743877093953/f

macOS PR: duckduckgo/macos-browser#2948
BSK PR: duckduckgo/BrowserServicesKit#881

## Description

Adds pixels to track connection tester failures and recovery.  These should give us a better idea about how users are faring.
  • Loading branch information
diegoreymendez authored Jul 6, 2024
1 parent 3fba737 commit 094fdf3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ extension Pixel {
case networkProtectionServerMigrationAttemptSuccess
case networkProtectionServerMigrationAttemptFailure

case networkProtectionConnectionTesterFailureDetected
case networkProtectionConnectionTesterFailureRecovered(failureCount: Int)
case networkProtectionConnectionTesterExtendedFailureDetected
case networkProtectionConnectionTesterExtendedFailureRecovered(failureCount: Int)

case networkProtectionTunnelFailureDetected
case networkProtectionTunnelFailureRecovered

Expand Down Expand Up @@ -1043,6 +1048,10 @@ extension Pixel.Event {
case .networkProtectionEnableAttemptConnecting: return "m_netp_ev_enable_attempt"
case .networkProtectionEnableAttemptSuccess: return "m_netp_ev_enable_attempt_success"
case .networkProtectionEnableAttemptFailure: return "m_netp_ev_enable_attempt_failure"
case .networkProtectionConnectionTesterFailureDetected: return "m_netp_connection_tester_failure"
case .networkProtectionConnectionTesterFailureRecovered: return "m_netp_connection_tester_failure_recovered"
case .networkProtectionConnectionTesterExtendedFailureDetected: return "m_netp_connection_tester_extended_failure"
case .networkProtectionConnectionTesterExtendedFailureRecovered: return "m_netp_connection_tester_extended_failure_recovered"
case .networkProtectionTunnelFailureDetected: return "m_netp_ev_tunnel_failure"
case .networkProtectionTunnelFailureRecovered: return "m_netp_ev_tunnel_failure_recovered"
case .networkProtectionLatency(let quality): return "m_netp_ev_\(quality.rawValue)_latency"
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9946,7 +9946,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 167.0.0;
version = 167.0.1;
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "5954412504b0cf294f5c0d90d7a0c8dfcd009558",
"version" : "167.0.0"
"revision" : "0746af01b77d39a1e037bea93b46591534a13b5c",
"version" : "167.0.1"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,40 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
DailyPixel.fire(pixel: .networkProtectionActiveUser,
withAdditionalParameters: [PixelParameters.vpnCohort: UniquePixel.cohort(from: defaults.vpnFirstEnabled)],
includedParameters: [.appVersion, .atb])
case .connectionTesterStatusChange(let status, let server):
vpnLogger.log(status, server: server)

switch status {
case .failed(let duration):
let pixel: Pixel.Event = {
switch duration {
case .immediate:
return .networkProtectionConnectionTesterFailureDetected
case .extended:
return .networkProtectionConnectionTesterExtendedFailureDetected
}
}()

DailyPixel.fireDailyAndCount(pixel: pixel,
withAdditionalParameters: [PixelParameters.server: server],
includedParameters: [.appVersion, .atb])
case .recovered(let duration, let failureCount):
let pixel: Pixel.Event = {
switch duration {
case .immediate:
return .networkProtectionConnectionTesterFailureRecovered(failureCount: failureCount)
case .extended:
return .networkProtectionConnectionTesterExtendedFailureRecovered(failureCount: failureCount)
}
}()

DailyPixel.fireDailyAndCount(pixel: pixel,
withAdditionalParameters: [
PixelParameters.count: String(failureCount),
PixelParameters.server: server
],
includedParameters: [.appVersion, .atb])
}
case .reportConnectionAttempt(attempt: let attempt):
vpnLogger.log(attempt)

Expand Down
16 changes: 16 additions & 0 deletions PacketTunnelProvider/NetworkProtection/VPNLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import OSLog
public final class VPNLogger {
public typealias AttemptStep = PacketTunnelProvider.AttemptStep
public typealias ConnectionAttempt = PacketTunnelProvider.ConnectionAttempt
public typealias ConnectionTesterStatus = PacketTunnelProvider.ConnectionTesterStatus
public typealias LogCallback = (OSLogType, OSLogMessage) -> Void

public init() {}
Expand Down Expand Up @@ -64,6 +65,21 @@ public final class VPNLogger {
}
}

public func log(_ status: ConnectionTesterStatus, server: String) {
let log = OSLog.networkProtectionConnectionTesterLog

switch status {
case .failed(let duration):
os_log("🔴 Connection tester (%{public}@ - %{public}@) failure", log: log, type: .error, duration.rawValue, server)
case .recovered(let duration, let failureCount):
os_log("🟢 Connection tester (%{public}@ - %{public}@) recovery (after %{public}@ failures)",
log: log,
duration.rawValue,
server,
String(failureCount))
}
}

public func log(_ step: FailureRecoveryStep) {
let log = OSLog.networkProtectionTunnelFailureMonitorLog

Expand Down

0 comments on commit 094fdf3

Please sign in to comment.