diff --git a/packages/metrics_center/CHANGELOG.md b/packages/metrics_center/CHANGELOG.md index 8684e94aed..63cf5593f9 100644 --- a/packages/metrics_center/CHANGELOG.md +++ b/packages/metrics_center/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.0.9 +- Remove legacy datastore and destination. + # 0.0.8 - Allow tests to override LegacyFlutterDestination GCP project id. diff --git a/packages/metrics_center/lib/src/constants.dart b/packages/metrics_center/lib/src/constants.dart index ba32171da6..49c8244bb2 100644 --- a/packages/metrics_center/lib/src/constants.dart +++ b/packages/metrics_center/lib/src/constants.dart @@ -29,10 +29,6 @@ const String kProjectId = 'project_id'; /// Timeline key in JSON. const String kSourceTimeMicrosName = 'sourceTimeMicros'; -/// The size of 500 is currently limited by Google datastore. It cannot write -/// more than 500 entities in a single call. -const int kMaxBatchSize = 500; - /// The prod bucket name for Flutter's instance of Skia Perf. const String kBucketName = 'flutter-skia-perf-prod'; diff --git a/packages/metrics_center/lib/src/flutter.dart b/packages/metrics_center/lib/src/flutter.dart index e98814131f..af2a8ad02b 100644 --- a/packages/metrics_center/lib/src/flutter.dart +++ b/packages/metrics_center/lib/src/flutter.dart @@ -4,8 +4,6 @@ import 'common.dart'; import 'constants.dart'; -import 'legacy_datastore.dart'; -import 'legacy_flutter.dart'; import 'skiaperf.dart'; /// Convenient class to capture the benchmarks in the Flutter engine repo. @@ -31,50 +29,32 @@ class FlutterEngineMetricPoint extends MetricPoint { /// All Flutter performance metrics (framework, engine, ...) should be written /// to this destination. class FlutterDestination extends MetricDestination { - // TODO(liyuqian): change the implementation of this class (without changing - // its public APIs) to remove `LegacyFlutterDestination` and directly use - // `SkiaPerfDestination` once the migration is fully done. - FlutterDestination._(this._legacyDestination, this._skiaPerfDestination); + FlutterDestination._(this._skiaPerfDestination); /// Creates a [FlutterDestination] from service account JSON. static Future makeFromCredentialsJson( Map json, {bool isTesting = false}) async { - // Specify the project id for LegacyFlutterDestination as we may get a - // service account json from another GCP project. - // - // When we're testing, let projectId be null so we'll still use the test - // project specified by the credentials json. - // - // This is completed, but fortunately we'll be able to remove all this - // once the migration is fully done. - final LegacyFlutterDestination legacyDestination = - await LegacyFlutterDestination.makeFromCredentialsJson(json, - projectId: isTesting ? null : 'flutter-cirrus'); final SkiaPerfDestination skiaPerfDestination = await SkiaPerfDestination.makeFromGcpCredentials(json, isTesting: isTesting); - return FlutterDestination._(legacyDestination, skiaPerfDestination); + return FlutterDestination._(skiaPerfDestination); } /// Creates a [FlutterDestination] from an OAuth access token. static Future makeFromAccessToken( String accessToken, String projectId, {bool isTesting = false}) async { - final LegacyFlutterDestination legacyDestination = LegacyFlutterDestination( - datastoreFromAccessToken(accessToken, projectId)); final SkiaPerfDestination skiaPerfDestination = await SkiaPerfDestination.makeFromAccessToken(accessToken, projectId, isTesting: isTesting); - return FlutterDestination._(legacyDestination, skiaPerfDestination); + return FlutterDestination._(skiaPerfDestination); } @override Future update(List points) async { - await _legacyDestination.update(points); await _skiaPerfDestination.update(points); } - final LegacyFlutterDestination _legacyDestination; final SkiaPerfDestination _skiaPerfDestination; } diff --git a/packages/metrics_center/lib/src/legacy_datastore.dart b/packages/metrics_center/lib/src/legacy_datastore.dart deleted file mode 100644 index 1095ef125f..0000000000 --- a/packages/metrics_center/lib/src/legacy_datastore.dart +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// TODO(liyuqian): Remove this file once the migration is fully done and we no -// longer need to fall back to the datastore. - -import 'package:gcloud/db.dart'; -import 'package:googleapis_auth/auth.dart'; -import 'package:googleapis_auth/auth_io.dart'; - -// The official pub.dev/packages/gcloud documentation uses datastore_impl -// so we have to ignore implementation_imports here. -// ignore: implementation_imports -import 'package:gcloud/src/datastore_impl.dart'; - -import 'common.dart'; -import 'constants.dart'; - -/// Creates a [DatastoreDB] connection from JSON service account credentials. -/// -/// We allow specifying a project id as we may use the service account from one -/// project to write into the datastore of another project. -Future datastoreFromCredentialsJson(Map json, - {String projectId}) async { - final AutoRefreshingAuthClient client = await clientViaServiceAccount( - ServiceAccountCredentials.fromJson(json), DatastoreImpl.SCOPES); - return DatastoreDB( - DatastoreImpl(client, projectId ?? json[kProjectId] as String)); -} - -/// Creates a [DatastoreDB] from an auth token. -DatastoreDB datastoreFromAccessToken(String token, String projectId) { - final AuthClient client = - authClientFromAccessToken(token, DatastoreImpl.SCOPES); - return DatastoreDB(DatastoreImpl(client, projectId)); -} diff --git a/packages/metrics_center/lib/src/legacy_flutter.dart b/packages/metrics_center/lib/src/legacy_flutter.dart deleted file mode 100644 index a153fbe68f..0000000000 --- a/packages/metrics_center/lib/src/legacy_flutter.dart +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// TODO(liyuqian): Remove this legacy file once the migration is fully done. -// See go/flutter-metrics-center-migration for detailed plans. -import 'dart:convert'; -import 'dart:math'; - -import 'package:gcloud/db.dart'; - -import 'common.dart'; -import 'constants.dart'; -import 'legacy_datastore.dart'; - -/// This model corresponds to the existing data model 'MetricPoint' used in the -/// flutter-cirrus GCP project. -/// -/// The originId and sourceTimeMicros fields are no longer used but we are still -/// providing valid values to them so it's compatible with old code and services -/// during the migration. -@Kind(name: 'MetricPoint', idType: IdType.String) -class LegacyMetricPointModel extends Model { - /// Initializes a metrics point data model for the flutter-cirrus GCP project. - LegacyMetricPointModel({MetricPoint fromMetricPoint}) { - if (fromMetricPoint != null) { - id = fromMetricPoint.id; - value = fromMetricPoint.value; - originId = 'legacy-flutter'; - sourceTimeMicros = null; - tags = fromMetricPoint.tags.keys - .map((String key) => - jsonEncode({key: fromMetricPoint.tags[key]})) - .toList(); - } - } - - /// The value of this metric. - @DoubleProperty(required: true, indexed: false) - double value; - - /// Any tags associated with this metric. - @StringListProperty() - List tags; - - /// The origin of this metric, which is no longer used. - @StringProperty(required: true) - String originId; - - /// The sourceTimeMicros field, which is no longer used. - @IntProperty(propertyName: kSourceTimeMicrosName) - int sourceTimeMicros; -} - -/// A [FlutterDestination] that is backwards compatible with the flutter-cirrus -/// GCP project. -class LegacyFlutterDestination extends MetricDestination { - /// Creates a legacy destination compatible with the flutter-cirrus GCP - /// project. - LegacyFlutterDestination(this._db); - - /// Creates this destination from a service account credentials JSON file. - static Future makeFromCredentialsJson( - Map json, { - String projectId, - }) async { - return LegacyFlutterDestination( - await datastoreFromCredentialsJson(json, projectId: projectId)); - } - - /// Creates this destination to authorize with an OAuth access token. - static LegacyFlutterDestination makeFromAccessToken( - String accessToken, String projectId) { - return LegacyFlutterDestination( - datastoreFromAccessToken(accessToken, projectId)); - } - - @override - Future update(List points) async { - final List flutterCenterPoints = points - .map((MetricPoint p) => LegacyMetricPointModel(fromMetricPoint: p)) - .toList(); - - for (int start = 0; start < points.length; start += kMaxBatchSize) { - final int end = min(start + kMaxBatchSize, points.length); - await _db.withTransaction((Transaction tx) async { - tx.queueMutations(inserts: flutterCenterPoints.sublist(start, end)); - await tx.commit(); - }); - } - } - - final DatastoreDB _db; -} diff --git a/packages/metrics_center/pubspec.yaml b/packages/metrics_center/pubspec.yaml index 72e360d1b8..68284e0768 100644 --- a/packages/metrics_center/pubspec.yaml +++ b/packages/metrics_center/pubspec.yaml @@ -1,5 +1,5 @@ name: metrics_center -version: 0.0.7 +version: 0.0.9 description: Support multiple performance metrics sources/formats and destinations. homepage: diff --git a/packages/metrics_center/test/legacy_flutter_test.dart b/packages/metrics_center/test/legacy_flutter_test.dart deleted file mode 100644 index b5e5d04450..0000000000 --- a/packages/metrics_center/test/legacy_flutter_test.dart +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:gcloud/src/datastore_impl.dart'; -import 'package:googleapis_auth/auth_io.dart'; -import 'package:metrics_center/src/constants.dart'; -import 'package:metrics_center/src/common.dart'; -import 'package:metrics_center/src/legacy_flutter.dart'; - -import 'common.dart'; -import 'utility.dart'; - -const String kTestSourceId = 'test'; - -void main() { - final Map credentialsJson = getTestGcpCredentialsJson(); - test( - 'LegacyFlutterDestination integration test: ' - 'update does not crash.', () async { - final LegacyFlutterDestination dst = - await LegacyFlutterDestination.makeFromCredentialsJson(credentialsJson); - await dst.update([MetricPoint(1.0, const {})]); - }, skip: credentialsJson == null); - - test( - 'LegacyFlutterDestination integration test: ' - 'can specify datastore project id.', () async { - final LegacyFlutterDestination dst = - await LegacyFlutterDestination.makeFromCredentialsJson(credentialsJson, - projectId: 'flutter-test-262600'); - await dst.update([MetricPoint(1.0, const {})]); - }, skip: credentialsJson == null); - - test( - 'LegacyFlutterDestination integration test: ' - 'can update with an access token.', () async { - final AutoRefreshingAuthClient client = await clientViaServiceAccount( - ServiceAccountCredentials.fromJson(credentialsJson), - DatastoreImpl.SCOPES, - ); - final String token = client.credentials.accessToken.data; - final LegacyFlutterDestination dst = - LegacyFlutterDestination.makeFromAccessToken( - token, - credentialsJson[kProjectId] as String, - ); - await dst.update([MetricPoint(1.0, const {})]); - }, skip: credentialsJson == null); -}