From 6293c3dfeed8df6bda37aad25659d1293054eef2 Mon Sep 17 00:00:00 2001 From: Jaime Wren Date: Thu, 14 May 2020 18:43:01 +0000 Subject: [PATCH] Update telemetry.dart with the most recent environment variables from the flutter tooling. Also: a TODO has been added to check for Azure bot usage. Change-Id: I2ead645694d599ee393a60db4880c7fa4eb8a3be Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147660 Commit-Queue: Jaime Wren Reviewed-by: Devon Carew --- pkg/telemetry/lib/telemetry.dart | 73 ++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/pkg/telemetry/lib/telemetry.dart b/pkg/telemetry/lib/telemetry.dart index 6df3990c77e..2da8ecc2df5 100644 --- a/pkg/telemetry/lib/telemetry.dart +++ b/pkg/telemetry/lib/telemetry.dart @@ -160,34 +160,63 @@ class _DisabledAnalytics extends AnalyticsMock { /// Detect whether we're running on a bot or in a continuous testing /// environment. /// -/// We should periodically keep this code up to date with -/// https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/base/utils.dart#L20. +/// We should periodically keep this code up to date with: +/// https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/base/bot_detector.dart#L30 +/// and +/// https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/reporting/usage.dart#L200. bool isRunningOnBot() { final Map env = Platform.environment; - return env['BOT'] != 'false' && - (env['BOT'] == 'true' - // https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables + if ( + // Explicitly stated to not be a bot. + env['BOT'] == 'false' + // Set by the IDEs to the IDE name, so a strong signal that this is not a bot. || - env['TRAVIS'] == 'true' || - env['CONTINUOUS_INTEGRATION'] == 'true' || - env.containsKey('CI') // Travis and AppVeyor + env.containsKey('FLUTTER_HOST') + // When set, GA logs to a local file (normally for tests) so we don't need to filter. + || + env.containsKey('FLUTTER_ANALYTICS_LOG_FILE')) { + return false; + } - // https://www.appveyor.com/docs/environment-variables/ - || - env.containsKey('APPVEYOR') + return env['BOT'] == 'true' + // https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables + || + env['TRAVIS'] == 'true' || + env['CONTINUOUS_INTEGRATION'] == 'true' || + env.containsKey('CI') // Travis and AppVeyor - // https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html - || - (env.containsKey('AWS_REGION') && - env.containsKey('CODEBUILD_INITIATOR')) + // https://www.appveyor.com/docs/environment-variables/ + || + env.containsKey('APPVEYOR') - // https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables - || - env.containsKey('JENKINS_URL') + // https://cirrus-ci.org/guide/writing-tasks/#environment-variables + || + env.containsKey('CIRRUS_CI') - // Properties on Flutter's Chrome Infra bots. - || - env['CHROME_HEADLESS'] == '1' || - env.containsKey('BUILDBOT_BUILDERNAME')); + // https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html + || + (env.containsKey('AWS_REGION') && env.containsKey('CODEBUILD_INITIATOR')) + + // https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables + || + env.containsKey('JENKINS_URL') + + // https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables + || + env.containsKey('GITHUB_ACTIONS') + + // Properties on Flutter's Chrome Infra bots. + || + env['CHROME_HEADLESS'] == '1' || + env.containsKey('BUILDBOT_BUILDERNAME') || + env.containsKey('SWARMING_TASK_ID') + + // Property when running on borg. + || + env.containsKey('BORG_ALLOC_DIR'); + + // TODO(jwren): Azure detection -- each call for this detection requires an + // http connection, the flutter cli tool captures the result on the first + // run, we should consider the same caching here. }