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

Add connection tester failure pixels #3049

Merged
merged 5 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading