Unverified Commit d73dd6b3 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tools] Rework iOS vmservice handshake failure usage event (#51419)

parent 1ec2a436
...@@ -6,6 +6,7 @@ import 'package:meta/meta.dart'; ...@@ -6,6 +6,7 @@ import 'package:meta/meta.dart';
import 'package:vm_service/vm_service.dart'; import 'package:vm_service/vm_service.dart';
import 'package:vm_service/vm_service_io.dart' as vm_service_io; import 'package:vm_service/vm_service_io.dart' as vm_service_io;
import '../base/io.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../device.dart'; import '../device.dart';
import '../mdns_discovery.dart'; import '../mdns_discovery.dart';
...@@ -120,19 +121,14 @@ class FallbackDiscovery { ...@@ -120,19 +121,14 @@ class FallbackDiscovery {
} on Exception catch (err) { } on Exception catch (err) {
_logger.printTrace(err.toString()); _logger.printTrace(err.toString());
_logger.printTrace('Failed to connect directly, falling back to mDNS'); _logger.printTrace('Failed to connect directly, falling back to mDNS');
UsageEvent( _sendFailureEvent(err, assumedDevicePort);
_kEventName,
'failure',
label: err.toString(),
value: hostPort,
).send();
return null; return null;
} }
// Attempt to connect to the VM service 5 times. // Attempt to connect to the VM service 5 times.
int attempts = 0; int attempts = 0;
const int kDelaySeconds = 2; const int kDelaySeconds = 2;
Object firstException; Exception firstException;
while (attempts < 5) { while (attempts < 5) {
try { try {
final VmService vmService = await _vmServiceConnectUri(assumedWsUri.toString()); final VmService vmService = await _vmServiceConnectUri(assumedWsUri.toString());
...@@ -163,12 +159,27 @@ class FallbackDiscovery { ...@@ -163,12 +159,27 @@ class FallbackDiscovery {
attempts += 1; attempts += 1;
} }
_logger.printTrace('Failed to connect directly, falling back to mDNS'); _logger.printTrace('Failed to connect directly, falling back to mDNS');
_sendFailureEvent(firstException, assumedDevicePort);
return null;
}
void _sendFailureEvent(Exception err, int assumedDevicePort) {
String eventAction;
String eventLabel;
if (err == null) {
eventAction = 'failure-attempts-exhausted';
eventLabel = assumedDevicePort.toString();
} else if (err is HttpException) {
eventAction = 'failure-http';
eventLabel = '${err.message}, device port = $assumedDevicePort';
} else {
eventAction = 'failure-other';
eventLabel = '$err, device port = $assumedDevicePort';
}
UsageEvent( UsageEvent(
_kEventName, _kEventName,
'failure', eventAction,
label: firstException?.toString() ?? 'Connection attempts exhausted', label: eventLabel,
value: hostPort,
).send(); ).send();
return null;
} }
} }
...@@ -643,7 +643,7 @@ void main() { ...@@ -643,7 +643,7 @@ void main() {
expect(launchResult.hasObservatory, isFalse); expect(launchResult.hasObservatory, isFalse);
verify(mockUsage.sendEvent( verify(mockUsage.sendEvent(
'ios-handshake', 'ios-handshake',
'failure', 'failure-other',
label: anyNamed('label'), label: anyNamed('label'),
value: anyNamed('value'), value: anyNamed('value'),
)).called(1); )).called(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment