mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
move pkg/telemetry to using package:lints
Change-Id: I75130cc8d5964ef0f95a672858da8bbce8ffd78c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200520 Commit-Queue: Devon Carew <devoncarew@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
parent
37a24ac3fa
commit
b8f4b252ef
|
@ -201,7 +201,7 @@ class Driver implements ServerStarter {
|
|||
final crashReportSender =
|
||||
CrashReportSender.prod(crashProductId, shouldSendCallback);
|
||||
|
||||
if (telemetry.SHOW_ANALYTICS_UI) {
|
||||
if (telemetry.showAnalyticsUI) {
|
||||
if (results.wasParsed(ANALYTICS_FLAG)) {
|
||||
analytics.enabled = results[ANALYTICS_FLAG];
|
||||
print(telemetry.createAnalyticsStatusMessage(analytics.enabled));
|
||||
|
@ -537,7 +537,7 @@ class Driver implements ServerStarter {
|
|||
print('Supported flags are:');
|
||||
print(parser.usage);
|
||||
|
||||
if (telemetry.SHOW_ANALYTICS_UI) {
|
||||
if (telemetry.showAnalyticsUI) {
|
||||
// Print analytics status and information.
|
||||
if (fromHelp) {
|
||||
print('');
|
||||
|
@ -648,11 +648,11 @@ class Driver implements ServerStarter {
|
|||
//
|
||||
parser.addFlag(ANALYTICS_FLAG,
|
||||
help: 'enable or disable sending analytics information to Google',
|
||||
hide: !telemetry.SHOW_ANALYTICS_UI);
|
||||
hide: !telemetry.showAnalyticsUI);
|
||||
parser.addFlag(SUPPRESS_ANALYTICS_FLAG,
|
||||
negatable: false,
|
||||
help: 'suppress analytics for this session',
|
||||
hide: !telemetry.SHOW_ANALYTICS_UI);
|
||||
hide: !telemetry.showAnalyticsUI);
|
||||
|
||||
//
|
||||
// Hidden; these are for internal development.
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
include: package:lints/recommended.yaml
|
||||
|
||||
analyzer:
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
linter:
|
||||
rules:
|
||||
- annotate_overrides
|
||||
- empty_constructor_bodies
|
||||
- empty_statements
|
||||
- unawaited_futures
|
||||
- unnecessary_brace_in_string_interps
|
||||
- valid_regexps
|
||||
|
|
|
@ -45,7 +45,7 @@ class CrashReportSender {
|
|||
final String crashProductId;
|
||||
final EnablementCallback shouldSend;
|
||||
final http.Client _httpClient;
|
||||
final Stopwatch _processStopwatch = new Stopwatch()..start();
|
||||
final Stopwatch _processStopwatch = Stopwatch()..start();
|
||||
|
||||
final ThrottlingBucket _throttle = ThrottlingBucket(10, Duration(minutes: 1));
|
||||
int _reportsSent = 0;
|
||||
|
@ -56,8 +56,8 @@ class CrashReportSender {
|
|||
this.shouldSend, {
|
||||
http.Client? httpClient,
|
||||
String endpointPath = _crashEndpointPathStaging,
|
||||
}) : _httpClient = httpClient ?? new http.Client(),
|
||||
_baseUri = new Uri(
|
||||
}) : _httpClient = httpClient ?? http.Client(),
|
||||
_baseUri = Uri(
|
||||
scheme: 'https', host: _crashServerHost, path: endpointPath);
|
||||
|
||||
/// Create a new [CrashReportSender] connected to the staging endpoint.
|
||||
|
@ -120,7 +120,7 @@ class CrashReportSender {
|
|||
},
|
||||
);
|
||||
|
||||
final http.MultipartRequest req = new http.MultipartRequest('POST', uri);
|
||||
final http.MultipartRequest req = http.MultipartRequest('POST', uri);
|
||||
|
||||
Map<String, String> fields = req.fields;
|
||||
fields['product'] = crashProductId;
|
||||
|
@ -144,9 +144,9 @@ class CrashReportSender {
|
|||
fields['weight'] = weight.toString();
|
||||
}
|
||||
|
||||
final Chain chain = new Chain.forTrace(stackTrace);
|
||||
final Chain chain = Chain.forTrace(stackTrace);
|
||||
req.files.add(
|
||||
new http.MultipartFile.fromString(
|
||||
http.MultipartFile.fromString(
|
||||
_stackTraceFileField,
|
||||
chain.terse.toString(),
|
||||
filename: _stackTraceFilename,
|
||||
|
@ -155,7 +155,7 @@ class CrashReportSender {
|
|||
|
||||
for (var attachment in attachments) {
|
||||
req.files.add(
|
||||
new http.MultipartFile.fromString(
|
||||
http.MultipartFile.fromString(
|
||||
attachment._field,
|
||||
attachment._value,
|
||||
filename: attachment._field,
|
||||
|
@ -200,4 +200,4 @@ class CrashReportAttachment {
|
|||
|
||||
/// A typedef to allow crash reporting to query as to whether it should send a
|
||||
/// crash report.
|
||||
typedef bool EnablementCallback();
|
||||
typedef EnablementCallback = bool Function();
|
||||
|
|
|
@ -15,7 +15,7 @@ class ThrottlingBucket {
|
|||
final Duration replenishDuration;
|
||||
|
||||
late int _drops = bucketSize;
|
||||
late int _lastReplenish = new DateTime.now().millisecondsSinceEpoch;
|
||||
late int _lastReplenish = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
ThrottlingBucket(this.bucketSize, this.replenishDuration);
|
||||
|
||||
|
@ -31,7 +31,7 @@ class ThrottlingBucket {
|
|||
}
|
||||
|
||||
void _checkReplenish() {
|
||||
int now = new DateTime.now().millisecondsSinceEpoch;
|
||||
int now = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
int replenishMillis = replenishDuration.inMilliseconds;
|
||||
|
||||
|
|
|
@ -6,8 +6,11 @@ import 'dart:io';
|
|||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
// ignore: implementation_imports
|
||||
import 'package:usage/src/usage_impl.dart';
|
||||
// ignore: implementation_imports
|
||||
import 'package:usage/src/usage_impl_io.dart';
|
||||
// ignore: implementation_imports
|
||||
import 'package:usage/src/usage_impl_io.dart' as usage_io show getDartVersion;
|
||||
import 'package:usage/usage.dart';
|
||||
import 'package:usage/usage_io.dart';
|
||||
|
@ -15,7 +18,7 @@ import 'package:usage/usage_io.dart';
|
|||
export 'package:usage/usage.dart' show Analytics;
|
||||
|
||||
// TODO(devoncarew): Don't show the UI until we're ready to ship.
|
||||
final bool SHOW_ANALYTICS_UI = false;
|
||||
final bool showAnalyticsUI = false;
|
||||
|
||||
final String _dartDirectoryName = '.dart';
|
||||
final String _settingsFileName = 'analytics.json';
|
||||
|
@ -38,7 +41,7 @@ final String analyticsNotice =
|
|||
/// be disabled with --no-analytics).'`
|
||||
String createAnalyticsStatusMessage(
|
||||
bool enabled, {
|
||||
String command: 'analytics',
|
||||
String command = 'analytics',
|
||||
}) {
|
||||
String currentState = enabled ? 'enabled' : 'disabled';
|
||||
String toggleState = enabled ? 'disabled' : 'enabled';
|
||||
|
@ -63,7 +66,7 @@ Analytics createAnalyticsInstance(
|
|||
if (dir == null) {
|
||||
// Some systems don't support user home directories; for those, fail
|
||||
// gracefully by returning a disabled analytics object.
|
||||
return new _DisabledAnalytics(trackingId, applicationName);
|
||||
return _DisabledAnalytics(trackingId, applicationName);
|
||||
}
|
||||
|
||||
if (!dir.existsSync()) {
|
||||
|
@ -72,12 +75,12 @@ Analytics createAnalyticsInstance(
|
|||
} catch (e) {
|
||||
// If we can't create the directory for the analytics settings, fail
|
||||
// gracefully by returning a disabled analytics object.
|
||||
return new _DisabledAnalytics(trackingId, applicationName);
|
||||
return _DisabledAnalytics(trackingId, applicationName);
|
||||
}
|
||||
}
|
||||
|
||||
File settingsFile = new File(path.join(dir.path, _settingsFileName));
|
||||
return new _TelemetryAnalytics(
|
||||
File settingsFile = File(path.join(dir.path, _settingsFileName));
|
||||
return _TelemetryAnalytics(
|
||||
trackingId,
|
||||
applicationName,
|
||||
getDartVersion(),
|
||||
|
@ -96,10 +99,10 @@ Analytics createAnalyticsInstance(
|
|||
/// directory does not exist.
|
||||
@visibleForTesting
|
||||
Directory? getDartStorageDirectory() {
|
||||
Directory homeDirectory = new Directory(userHomeDir());
|
||||
Directory homeDirectory = Directory(userHomeDir());
|
||||
if (!homeDirectory.existsSync()) return null;
|
||||
|
||||
return new Directory(path.join(homeDirectory.path, _dartDirectoryName));
|
||||
return Directory(path.join(homeDirectory.path, _dartDirectoryName));
|
||||
}
|
||||
|
||||
/// Return the version of the Dart SDK.
|
||||
|
@ -118,8 +121,8 @@ class _TelemetryAnalytics extends AnalyticsImpl {
|
|||
required this.forceEnabled,
|
||||
}) : super(
|
||||
trackingId,
|
||||
new IOPersistentProperties.fromFile(settingsFile),
|
||||
new IOPostHandler(),
|
||||
IOPersistentProperties.fromFile(settingsFile),
|
||||
IOPostHandler(),
|
||||
applicationName: applicationName,
|
||||
applicationVersion: applicationVersion,
|
||||
) {
|
||||
|
|
|
@ -18,20 +18,21 @@ void main() {
|
|||
late Request request;
|
||||
|
||||
setUp(() {
|
||||
mockClient = new MockClient((Request r) async {
|
||||
mockClient = MockClient((Request r) async {
|
||||
request = r;
|
||||
return new Response('crash-report-001', 200);
|
||||
return Response('crash-report-001', 200);
|
||||
});
|
||||
|
||||
analytics = new AnalyticsMock()..enabled = true;
|
||||
analytics = AnalyticsMock()..enabled = true;
|
||||
});
|
||||
|
||||
EnablementCallback shouldSend = () {
|
||||
EnablementCallback shouldSend;
|
||||
shouldSend = () {
|
||||
return true;
|
||||
};
|
||||
|
||||
test('general', () async {
|
||||
CrashReportSender sender = new CrashReportSender.prod(
|
||||
CrashReportSender sender = CrashReportSender.prod(
|
||||
analytics.trackingId, shouldSend,
|
||||
httpClient: mockClient);
|
||||
|
||||
|
@ -43,7 +44,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('reportsSent', () async {
|
||||
CrashReportSender sender = new CrashReportSender.prod(
|
||||
CrashReportSender sender = CrashReportSender.prod(
|
||||
analytics.trackingId, shouldSend,
|
||||
httpClient: mockClient);
|
||||
|
||||
|
@ -59,7 +60,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('contains message', () async {
|
||||
CrashReportSender sender = new CrashReportSender.prod(
|
||||
CrashReportSender sender = CrashReportSender.prod(
|
||||
analytics.trackingId, shouldSend,
|
||||
httpClient: mockClient);
|
||||
|
||||
|
@ -73,7 +74,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('has attachments', () async {
|
||||
CrashReportSender sender = new CrashReportSender.prod(
|
||||
CrashReportSender sender = CrashReportSender.prod(
|
||||
analytics.trackingId, shouldSend,
|
||||
httpClient: mockClient);
|
||||
|
||||
|
@ -94,7 +95,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('has ptime', () async {
|
||||
CrashReportSender sender = new CrashReportSender.prod(
|
||||
CrashReportSender sender = CrashReportSender.prod(
|
||||
analytics.trackingId, shouldSend,
|
||||
httpClient: mockClient);
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@ import 'package:test/test.dart';
|
|||
void main() {
|
||||
group('ThrottlingBucket', () {
|
||||
test('can send', () {
|
||||
ThrottlingBucket bucket = new ThrottlingBucket(10, Duration(minutes: 1));
|
||||
ThrottlingBucket bucket = ThrottlingBucket(10, Duration(minutes: 1));
|
||||
expect(bucket.removeDrop(), true);
|
||||
});
|
||||
|
||||
test("doesn't send too many", () {
|
||||
ThrottlingBucket bucket = new ThrottlingBucket(10, Duration(minutes: 1));
|
||||
ThrottlingBucket bucket = ThrottlingBucket(10, Duration(minutes: 1));
|
||||
for (int i = 0; i < 10; i++) {
|
||||
expect(bucket.removeDrop(), true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue