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: VPN Metadata Improvements #2704

Merged
merged 6 commits into from
Apr 26, 2024
Merged

Conversation

diegoreymendez
Copy link
Contributor

@diegoreymendez diegoreymendez commented Apr 25, 2024

Task/Issue URL: https://app.asana.com/0/0/1207169059489741/f

iOS: duckduckgo/iOS#2791
BSK: duckduckgo/BrowserServicesKit#799

Description

  • Add last IPC, controller, tunnel errors to VPN metadata
  • Updates VPN feedback metadata to include ipsec tunnel count.
  • Add lastExtensionVersionRun to VPN metadata in the App Store build

Testing

Test 1: IPC Failure in metadata

NOTE: in this test there a UI issue where the toggle is not becoming disabled until you hide and show the VPN popover, but is unrelaed to my changes

  1. Comment this line
  2. Start the app
  3. Remove the login item using launchctl remove <bundle_id>
  4. Try to start the VPN, it should fail
  5. Print the metadata to console and ensure you see the IPC error in it (Error domain=NSCocoaErrorDomain code=4099)

Test 2: Controller Failure in metadata

NOTE: in this test there a UI issue where the toggle is not becoming disabled until you hide and show the VPN popover, but is unrelaed to my changes

  1. Make sure the previously commented line is back to being uncommented
  2. Throw any error here (like StartError.noAuthToken)
  3. Start the app
  4. Try to start the VPN, it should fail
  5. Print the metadata to console and ensure you see the IPC error in it (Error domain=DuckDuckGoVPN.NetworkProtectionTunnelController.StartError code=0)

Test 3: Tunnel Failure in metadata

NOTE: in this test there a UI issue where the toggle is not becoming disabled until you hide and show the VPN popover, but is unrelaed to my changes

  1. Roll back the error we were force throwing in the previous test

  2. Add the following method to MacPacketTunnelProvider.swift

    override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) {
    super.startTunnel(options: options, completionHandler: completionHandler)

     Task {
         try await Task.sleep(interval: .seconds(5))
         cancelTunnelWithError(NSError(domain: "test", code: 5))
     }
    

    }

  3. Start the app

  4. Try to start the VPN, it should fail

  5. Wait at least 5 seconds

  6. Print the metadata to console and ensure you see the IPC error in it (Error domain=test code=5)


Internal references:

Pull Request Review Checklist
Software Engineering Expectations
Technical Design Template
Pull Request Documentation

@diegoreymendez diegoreymendez self-assigned this Apr 25, 2024
@github-actions github-actions bot added the bot: not in app board Added by automation for pull requests with tasks not added to macOS App Board Asana project label Apr 25, 2024
import NetworkProtectionIPC

@objc
final class ErrorInformation: NSObject, Codable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Privacy friendly error information for reports.

///
/// To be used in combination with ``VPNOperationErrorRecorder``
///
final class VPNOperationErrorHistory {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To query error history.

///
/// To be used in combination with ``VPNOperationErrorHistory``
///
final class VPNOperationErrorRecorder {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To store new error history.

@@ -222,7 +228,7 @@ final class DefaultVPNMetadataCollector: VPNMetadataCollector {
func collectVPNState() async -> VPNMetadata.VPNState {
let onboardingState: String

switch UserDefaults.netP.networkProtectionOnboardingStatus {
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 making the defaults injectable as we'll eventually want to test this class.

@@ -127,6 +127,19 @@ extension TunnelControllerIPCService: IPCServerInterface {
completion(nil)
}

func fetchLastError(completion: @escaping (Error?) -> Void) {
Task {
guard #available(macOS 13.0, *),
Copy link
Contributor Author

@diegoreymendez diegoreymendez Apr 25, 2024

Choose a reason for hiding this comment

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

This is necessary because fetchLastDisconnectError is not available before macOS 13.

I'm ok with not returning anything if this is not available, since I'm not sure we can properly return something that doesn't also introduce potential noise.

We can do follow-up work on this if necessary.

/// The earliest error is the one that best represents the latest failure
///
var lastStartError: ErrorInformation? {
lastIPCStartError ?? lastControllerStartError
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By doing this, we try to make the metadata easier to parse. If there's an IPC error we should report that because it means we never got to the controller (and error information there may be from a previous attempt).

But if there was no IPC error, we should report the controller start error instead.

@diegoreymendez diegoreymendez changed the title macOS | iOS: VPN Metadata Improvements macOS: VPN Metadata Improvements Apr 25, 2024
@diegoreymendez diegoreymendez marked this pull request as ready for review April 25, 2024 15:21
@diegoreymendez diegoreymendez removed the bot: not in app board Added by automation for pull requests with tasks not added to macOS App Board Asana project label Apr 25, 2024
@diegoreymendez diegoreymendez requested a review from graeme April 25, 2024 15:57
Copy link
Collaborator

@graeme graeme left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for the detailed test steps

diegoreymendez added a commit to duckduckgo/BrowserServicesKit that referenced this pull request Apr 26, 2024
Task/Issue URL: https://app.asana.com/0/0/1206897550778458/f

iOS PR: duckduckgo/iOS#2791
macOS PR: duckduckgo/macos-browser#2704
What kind of version bump will this require?: Minor

## Description

Adds some improved tracking of tunnel interfaces to include `ipsec` tunnels.
diegoreymendez added a commit to duckduckgo/iOS that referenced this pull request Apr 26, 2024
Task/Issue URL: https://app.asana.com/0/414235014887631/1207169059489741/f

macOS: duckduckgo/macos-browser#2704
BSK: duckduckgo/BrowserServicesKit#799

## Description

Updates VPN feedback metadata to include `ipsec` tunnel count.
@diegoreymendez diegoreymendez merged commit 429d897 into main Apr 26, 2024
19 checks passed
@diegoreymendez diegoreymendez deleted the diego/vpn-metadata-changes branch April 26, 2024 16:33
samsymons added a commit that referenced this pull request Apr 26, 2024
…utdown

# By Dax the Duck (9) and others
# Via GitHub (6) and others
* main: (47 commits)
  Update BSK to 141.1.1 (#2713)
  macOS: VPN Metadata Improvements (#2704)
  duck page suggestions (#2666)
  macOS: Add pixels to track VPN wake and stop attempts (#2694)
  Trusted url indicator (#2665)
  remove Tab.TabContent.url (#2647)
  Bump version to 1.85.0 (176)
  Update release automation to support Privacy Pro section in release notes (#2710)
  Fix for VPN stop issues. (#2689)
  Hard-codes the VPN waitlist flags to ON (#2709)
  Add subscription status to the macOS metadata (#2680)
  Bump version to 1.85.0 (175)
  Call finish in the correct place (#2702)
  Fix layout issue on DBP (#2700)
  Update autoconsent to v10.6.1 (#2618)
  Make Clear All History shortcut available without entering Main Menu (#2682)
  Fix DataBrokerProtectionProcessor.swift lint
  Fix SwiftLint
  Add parameter allowed encoding to error descriptions (#2691)
  Remove debug flags
  ...

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
#	DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants