Skip to content

Commit acece00

Browse files
authored
Allow parse_and_send to use access tokens (#22019)
1 parent e61e8c2 commit acece00

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

.cirrus.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,9 @@ task:
4040
ninja -C out/host_release
4141
benchmark_host_script: |
4242
cd $ENGINE_PATH/src/out/host_release/
43-
./txt_benchmarks --benchmark_format=json > txt_benchmarks.json
44-
./fml_benchmarks --benchmark_format=json > fml_benchmarks.json
45-
./shell_benchmarks --benchmark_format=json > shell_benchmarks.json
46-
./ui_benchmarks --benchmark_format=json > ui_benchmarks.json
43+
$ENGINE_PATH/src/flutter/testing/benchmark/generate_metrics.sh
4744
cd $ENGINE_PATH/src/flutter/testing/benchmark
48-
pub get
49-
dart bin/parse_and_send.dart ../../../out/host_release/txt_benchmarks.json
50-
dart bin/parse_and_send.dart ../../../out/host_release/fml_benchmarks.json
51-
dart bin/parse_and_send.dart ../../../out/host_release/shell_benchmarks.json
52-
dart bin/parse_and_send.dart ../../../out/host_release/ui_benchmarks.json
45+
upload_metrics.sh
5346
5447
# The following test depends on Flutter framework repo. It may fail if the
5548
# framework repo is currently broken.

testing/benchmark/bin/parse_and_send.dart

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,33 @@ Future<List<FlutterEngineMetricPoint>> _parse(String jsonFileName) async {
3838
return points;
3939
}
4040

41+
Future<FlutterDestination> connectFlutterDestination() async {
42+
const String kTokenPath = 'TOKEN_PATH';
43+
const String kGcpProject = 'GCP_PROJECT';
44+
final Map<String, String> env = Platform.environment;
45+
if (env.containsKey(kTokenPath) && env.containsKey(kGcpProject)) {
46+
return FlutterDestination.makeFromAccessToken(
47+
File(env[kTokenPath]).readAsStringSync(),
48+
env[kGcpProject],
49+
);
50+
}
51+
return await FlutterDestination.makeFromCredentialsJson(
52+
jsonDecode(Platform.environment['BENCHMARK_GCP_CREDENTIALS'])
53+
as Map<String, dynamic>,
54+
);
55+
}
56+
4157
Future<void> main(List<String> args) async {
4258
if (args.length != 1) {
4359
throw 'Must have one argument: <benchmark_json_file>';
4460
}
4561
final List<FlutterEngineMetricPoint> points = await _parse(args[0]);
62+
4663
// The data will be sent to the Datastore of the GCP project specified through
47-
// environment variable BENCHMARK_GCP_CREDENTIALS. The engine Cirrus job has
48-
// currently configured the GCP project to flutter-cirrus for test. We'll
49-
// eventually migrate to flutter-infra project once the test is done.
50-
final FlutterDestination destination =
51-
await FlutterDestination.makeFromCredentialsJson(
52-
jsonDecode(Platform.environment['BENCHMARK_GCP_CREDENTIALS']),
53-
);
64+
// environment variable BENCHMARK_GCP_CREDENTIALS, or TOKEN_PATH/GCP_PROJECT.
65+
// The engine Cirrus job has currently configured the GCP project to
66+
// flutter-cirrus for test. We'll eventually migrate to flutter-infra project
67+
// once the test is done.
68+
final FlutterDestination destination = await connectFlutterDestination();
5469
await destination.update(points);
5570
}

testing/benchmark/test/parse_and_send_test.dart

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
// found in the LICENSE file.
44

55
// @dart = 2.6
6+
import 'dart:convert';
67
import 'dart:io';
78

9+
import 'package:gcloud/src/datastore_impl.dart';
10+
import 'package:googleapis_auth/auth_io.dart';
11+
import 'package:path/path.dart' as path;
812
import 'package:test/test.dart';
913

1014
void main() {
11-
// In order to run this test, one should download a service account
15+
// In order to run these tests, one should download a service account
1216
// credentials json from a test GCP project, and put that json as
1317
// `secret/test_gcp_credentials.json`. There's a `flutter-test` project for
1418
// Flutter team members.
@@ -22,4 +26,25 @@ void main() {
2226
'BENCHMARK_GCP_CREDENTIALS': testCred,
2327
});
2428
});
29+
30+
test('parse_and_send succeeds with access token.', () async {
31+
final dynamic testCred =
32+
jsonDecode(File('secret/test_gcp_credentials.json').readAsStringSync())
33+
as Map<String, dynamic>;
34+
final AutoRefreshingAuthClient client = await clientViaServiceAccount(
35+
ServiceAccountCredentials.fromJson(testCred),
36+
DatastoreImpl.SCOPES,
37+
);
38+
final String tokenPath =
39+
path.join(Directory.systemTemp.absolute.path, 'parse_and_send_token');
40+
File(tokenPath).writeAsStringSync(client.credentials.accessToken.data);
41+
final ProcessResult result = Process.runSync('dart', <String>[
42+
'bin/parse_and_send.dart',
43+
'example/txt_benchmarks.json',
44+
], environment: <String, String>{
45+
'TOKEN_PATH': tokenPath,
46+
'GCP_PROJECT': testCred['project_id'] as String,
47+
});
48+
expect(result.exitCode, 0);
49+
});
2550
}

0 commit comments

Comments
 (0)