Remove legacy datastore and destination (#278)

This commit is contained in:
Yuqian Li
2021-02-03 14:10:18 -08:00
committed by GitHub
parent 93ae0899bb
commit 586cae93a8
7 changed files with 7 additions and 209 deletions

View File

@ -1,3 +1,6 @@
# 0.0.9
- Remove legacy datastore and destination.
# 0.0.8
- Allow tests to override LegacyFlutterDestination GCP project id.

View File

@ -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';

View File

@ -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<FlutterDestination> makeFromCredentialsJson(
Map<String, dynamic> 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<FlutterDestination> 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<void> update(List<MetricPoint> points) async {
await _legacyDestination.update(points);
await _skiaPerfDestination.update(points);
}
final LegacyFlutterDestination _legacyDestination;
final SkiaPerfDestination _skiaPerfDestination;
}

View File

@ -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<DatastoreDB> datastoreFromCredentialsJson(Map<String, dynamic> 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));
}

View File

@ -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<String> {
/// 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(<String, dynamic>{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<String> 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<LegacyFlutterDestination> makeFromCredentialsJson(
Map<String, dynamic> 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<void> update(List<MetricPoint> points) async {
final List<LegacyMetricPointModel> 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;
}

View File

@ -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:

View File

@ -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<String, dynamic> credentialsJson = getTestGcpCredentialsJson();
test(
'LegacyFlutterDestination integration test: '
'update does not crash.', () async {
final LegacyFlutterDestination dst =
await LegacyFlutterDestination.makeFromCredentialsJson(credentialsJson);
await dst.update(<MetricPoint>[MetricPoint(1.0, const <String, String>{})]);
}, 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>[MetricPoint(1.0, const <String, String>{})]);
}, 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>[MetricPoint(1.0, const <String, String>{})]);
}, skip: credentialsJson == null);
}