Skip to content

Commit

Permalink
Adds pixels to track connection tester issues
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoreymendez committed Jul 5, 2024
1 parent 59eab6a commit a3074ad
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13182,7 +13182,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = revision;
revision = d27b9a59e72aff2dd14e6e019b2553f93306328f;
revision = 2da7466efc1ffc84c80d06f914ca2b104417d33a;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "d27b9a59e72aff2dd14e6e019b2553f93306328f"
"revision" : "2da7466efc1ffc84c80d06f914ca2b104417d33a"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 {

case networkProtectionConnectionTesterFailureDetected
case networkProtectionConnectionTesterFailureRecovered(failureCount: Int)

case networkProtectionConnectionTesterExtendedFailureDetected
case networkProtectionConnectionTesterExtendedFailureRecovered(failureCount: Int)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,35 @@ final class MacPacketTunnelProvider: PacketTunnelProvider {
withAdditionalParameters: [PixelKit.Parameters.vpnCohort: PixelKit.cohort(from: defaults.vpnFirstEnabled)],
includeAppVersionParameter: true)
case .connectionTesterStatusChange(let status):
vpnLogger.log(status)

switch status {
case .failed:
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionConnectionTesterFailureDetected,
frequency: .dailyAndCount,
includeAppVersionParameter: true)
case .recovered(let failureCount):
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionConnectionTesterFailureRecovered(failureCount: failureCount),
frequency: .dailyAndCount,
includeAppVersionParameter: true)
}
case .connectionTesterExtendedStatusChange(let status):
switch status {
case .failed:
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionConnectionTesterExtendedFailureDetected,
case .failed(let duration):
let pixel: NetworkProtectionPixelEvent = {
switch duration {
case .immediate:
return .networkProtectionConnectionTesterFailureDetected
case .extended:
return .networkProtectionConnectionTesterExtendedFailureDetected
}
}()

PixelKit.fire(
pixel,
frequency: .dailyAndCount,
includeAppVersionParameter: true)
case .recovered(let failureCount):
PixelKit.fire(
NetworkProtectionPixelEvent.networkProtectionConnectionTesterExtendedFailureRecovered(failureCount: failureCount),
case .recovered(let duration, let failureCount):
let pixel: NetworkProtectionPixelEvent = {
switch duration {
case .immediate:
return .networkProtectionConnectionTesterFailureRecovered(failureCount: failureCount)
case .extended:
return .networkProtectionConnectionTesterExtendedFailureRecovered(failureCount: failureCount)
}
}()

PixelKit.fire(
pixel,
frequency: .dailyAndCount,
includeAppVersionParameter: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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 @@ -63,6 +64,17 @@ public final class VPNLogger {
}
}

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

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

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

Expand Down

0 comments on commit a3074ad

Please sign in to comment.