From 60934a5ce4476a54e8f212b3cdd80d4f500103de Mon Sep 17 00:00:00 2001 From: Yuqian Li Date: Tue, 20 Oct 2020 20:07:17 -0700 Subject: [PATCH 1/3] Allow parse_and_send to use access tokens Related issue: https://github.com/flutter/flutter/issues/67579 --- testing/benchmark/bin/parse_and_send.dart | 28 ++++++++++++++----- .../benchmark/test/parse_and_send_test.dart | 26 ++++++++++++++++- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/testing/benchmark/bin/parse_and_send.dart b/testing/benchmark/bin/parse_and_send.dart index 443280cd9ca87..160248d12cef3 100644 --- a/testing/benchmark/bin/parse_and_send.dart +++ b/testing/benchmark/bin/parse_and_send.dart @@ -38,18 +38,32 @@ Future> _parse(String jsonFileName) async { return points; } +Future connectFlutterDestination() async { + const String kTokenPath = 'TOKEN_PATH'; + const String kGcpProject = 'GCP_PROJECT'; + final Map env = Platform.environment; + if (env.containsKey(kTokenPath) && env.containsKey(kGcpProject)) { + return FlutterDestination.makeFromAccessToken( + env[kTokenPath], + env[kGcpProject], + ); + } + return await FlutterDestination.makeFromCredentialsJson( + jsonDecode(Platform.environment['BENCHMARK_GCP_CREDENTIALS']) as Map, + ); +} + Future main(List args) async { if (args.length != 1) { throw 'Must have one argument: '; } final List points = await _parse(args[0]); + // The data will be sent to the Datastore of the GCP project specified through - // environment variable BENCHMARK_GCP_CREDENTIALS. The engine Cirrus job has - // currently configured the GCP project to flutter-cirrus for test. We'll - // eventually migrate to flutter-infra project once the test is done. - final FlutterDestination destination = - await FlutterDestination.makeFromCredentialsJson( - jsonDecode(Platform.environment['BENCHMARK_GCP_CREDENTIALS']), - ); + // environment variable BENCHMARK_GCP_CREDENTIALS, or TOKEN_PATH/GCP_PROJECT. + // The engine Cirrus job has currently configured the GCP project to + // flutter-cirrus for test. We'll eventually migrate to flutter-infra project + // once the test is done. + final FlutterDestination destination = await connectFlutterDestination(); await destination.update(points); } diff --git a/testing/benchmark/test/parse_and_send_test.dart b/testing/benchmark/test/parse_and_send_test.dart index 43af537cf8a18..ffd2a1ea3a78a 100644 --- a/testing/benchmark/test/parse_and_send_test.dart +++ b/testing/benchmark/test/parse_and_send_test.dart @@ -3,12 +3,16 @@ // found in the LICENSE file. // @dart = 2.6 +import 'dart:convert'; import 'dart:io'; +import 'package:gcloud/src/datastore_impl.dart'; +import 'package:googleapis_auth/auth_io.dart'; +import 'package:path/path.dart' as path; import 'package:test/test.dart'; void main() { - // In order to run this test, one should download a service account + // In order to run these tests, one should download a service account // credentials json from a test GCP project, and put that json as // `secret/test_gcp_credentials.json`. There's a `flutter-test` project for // Flutter team members. @@ -22,4 +26,24 @@ void main() { 'BENCHMARK_GCP_CREDENTIALS': testCred, }); }); + + test('parse_and_send succeeds with access token.', () async { + final dynamic testCred = + jsonDecode(File('secret/test_gcp_credentials.json').readAsStringSync()) + as Map; + final AutoRefreshingAuthClient client = await clientViaServiceAccount( + ServiceAccountCredentials.fromJson(testCred), + DatastoreImpl.SCOPES, + ); + final String tokenPath = + path.join(Directory.systemTemp.absolute.path, 'parse_and_send_token'); + File(tokenPath).writeAsStringSync(client.credentials.accessToken.data); + Process.runSync('dart', [ + 'bin/parse_and_send.dart', + 'example/txt_benchmarks.json', + ], environment: { + 'TOKEN_PATH': tokenPath, + 'GCP_PROJECT': testCred['project_id'] as String, + }); + }); } From f86dc377eaac27d15db6b295f1696fb6d01e1fba Mon Sep 17 00:00:00 2001 From: Yuqian Li Date: Mon, 26 Oct 2020 13:35:53 -0700 Subject: [PATCH 2/3] Use new scripts --- .cirrus.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index ace33146a041c..b8a732be9e996 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -40,16 +40,9 @@ task: ninja -C out/host_release benchmark_host_script: | cd $ENGINE_PATH/src/out/host_release/ - ./txt_benchmarks --benchmark_format=json > txt_benchmarks.json - ./fml_benchmarks --benchmark_format=json > fml_benchmarks.json - ./shell_benchmarks --benchmark_format=json > shell_benchmarks.json - ./ui_benchmarks --benchmark_format=json > ui_benchmarks.json + $ENGINE_PATH/src/flutter/testing/benchmark/generate_metrics.sh cd $ENGINE_PATH/src/flutter/testing/benchmark - pub get - dart bin/parse_and_send.dart ../../../out/host_release/txt_benchmarks.json - dart bin/parse_and_send.dart ../../../out/host_release/fml_benchmarks.json - dart bin/parse_and_send.dart ../../../out/host_release/shell_benchmarks.json - dart bin/parse_and_send.dart ../../../out/host_release/ui_benchmarks.json + upload_metrics.sh # The following test depends on Flutter framework repo. It may fail if the # framework repo is currently broken. From 4e83e4df0fcab245b275324a25a94543017735af Mon Sep 17 00:00:00 2001 From: Yuqian Li Date: Tue, 27 Oct 2020 13:49:46 -0700 Subject: [PATCH 3/3] Fix bugs and tests --- testing/benchmark/bin/parse_and_send.dart | 5 +++-- testing/benchmark/test/parse_and_send_test.dart | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/testing/benchmark/bin/parse_and_send.dart b/testing/benchmark/bin/parse_and_send.dart index 160248d12cef3..da247e44c40a8 100644 --- a/testing/benchmark/bin/parse_and_send.dart +++ b/testing/benchmark/bin/parse_and_send.dart @@ -44,12 +44,13 @@ Future connectFlutterDestination() async { final Map env = Platform.environment; if (env.containsKey(kTokenPath) && env.containsKey(kGcpProject)) { return FlutterDestination.makeFromAccessToken( - env[kTokenPath], + File(env[kTokenPath]).readAsStringSync(), env[kGcpProject], ); } return await FlutterDestination.makeFromCredentialsJson( - jsonDecode(Platform.environment['BENCHMARK_GCP_CREDENTIALS']) as Map, + jsonDecode(Platform.environment['BENCHMARK_GCP_CREDENTIALS']) + as Map, ); } diff --git a/testing/benchmark/test/parse_and_send_test.dart b/testing/benchmark/test/parse_and_send_test.dart index ffd2a1ea3a78a..6db1aded44e8e 100644 --- a/testing/benchmark/test/parse_and_send_test.dart +++ b/testing/benchmark/test/parse_and_send_test.dart @@ -38,12 +38,13 @@ void main() { final String tokenPath = path.join(Directory.systemTemp.absolute.path, 'parse_and_send_token'); File(tokenPath).writeAsStringSync(client.credentials.accessToken.data); - Process.runSync('dart', [ + final ProcessResult result = Process.runSync('dart', [ 'bin/parse_and_send.dart', 'example/txt_benchmarks.json', ], environment: { 'TOKEN_PATH': tokenPath, 'GCP_PROJECT': testCred['project_id'] as String, }); + expect(result.exitCode, 0); }); }