metrics: Add a mechanism to notify users when we want to collect additional metrics.

When we change the version number in metrics_utils:

If the user is not a Googler, or has opted out explicitly, nothing happens
and we still don't collect metrics.

If we're collecting metrics from the user, we stop collecting metrics
and display a notice telling them what has changed.
That notice will be displayed ten times, after which we will
resume collecting metrics. A notice telling them we're collecting metrics
will still be displayed.

Bug: None
Change-Id: If1cc12b2fc06f0d6237714c4f182367b1afdf9fb
Reviewed-on: https://chromium-review.googlesource.com/c/1285395
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
This commit is contained in:
Edward Lemur
2018-10-18 02:08:06 +00:00
committed by Commit Bot
parent 3e002fb862
commit 488362624b
4 changed files with 243 additions and 27 deletions

View File

@@ -12,8 +12,16 @@ import sys
from third_party import colorama
# Current version of metrics recording.
# When we add new metrics, the version number will be increased, we display the
# user what has changed, and ask the user to agree again.
CURRENT_VERSION = 0
APP_URL = 'https://cit-cli-metrics.appspot.com'
EMPTY_LINE = (
'* *'
)
NOTICE_COUNTDOWN_HEADER = (
'*****************************************************\n'
'* METRICS COLLECTION WILL START IN %2d EXECUTIONS *'
@@ -22,14 +30,23 @@ NOTICE_COLLECTION_HEADER = (
'*****************************************************\n'
'* METRICS COLLECTION IS TAKING PLACE *'
)
NOTICE_VERSION_CHANGE_HEADER = (
'*****************************************************\n'
'* WE ARE COLLECTING ADDITIONAL METRICS *'
)
NOTICE_FOOTER = (
'* *\n'
'* For more information, and for how to disable this *\n'
'* message, please see metrics.README.md in your *\n'
'* depot_tools checkout. *\n'
'*****************************************************\n'
)
CHANGE_NOTICE = {
# No changes for version 0
0: '',
}
KNOWN_PROJECT_URLS = {
'https://chrome-internal.googlesource.com/chrome/ios_internal',
'https://chrome-internal.googlesource.com/infra/infra_internal',
@@ -105,9 +122,21 @@ def get_repo_timestamp(path_to_repo):
def print_notice(countdown):
"""Print a notice to let the user know the status of metrics collection."""
colorama.init()
print(colorama.Fore.RED + '\033[1m', file=sys.stderr)
print(colorama.Fore.RED + '\033[1m', file=sys.stderr, end='')
if countdown:
print(NOTICE_COUNTDOWN_HEADER % countdown, file=sys.stderr)
else:
print(NOTICE_COLLECTION_HEADER, file=sys.stderr)
print(EMPTY_LINE, file=sys.stderr)
print(NOTICE_FOOTER + colorama.Style.RESET_ALL, file=sys.stderr)
def print_version_change(config_version):
"""Print a notice to let the user know we are collecting more metrics."""
colorama.init()
print(colorama.Fore.RED + '\033[1m', file=sys.stderr, end='')
print(NOTICE_VERSION_CHANGE_HEADER, file=sys.stderr)
print(EMPTY_LINE, file=sys.stderr)
for version in range(config_version + 1, CURRENT_VERSION + 1):
print(CHANGE_NOTICE[version], file=sys.stderr)
print(EMPTY_LINE, file=sys.stderr)