Explorar o código

[metrics] Add new auth metric

Bug: b/358442026
Change-Id: If91494b52fe27177f68e42ec40977fd8ca1fd4cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5786166
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Allen Li hai 1 ano
pai
achega
04a2e71a92
Modificáronse 4 ficheiros con 26 adicións e 3 borrados
  1. 2 0
      metrics.README.md
  2. 13 1
      metrics.py
  3. 8 2
      metrics_utils.py
  4. 3 0
      tests/metrics_test.py

+ 2 - 0
metrics.README.md

@@ -70,6 +70,8 @@ The metrics we're collecting are:
   - What argument names (but not values) were passed to the program.
     (e.g. --checkout but not the branch name).
   - What was the exit code?
+- Information about the enablement status of experimental feature flags, when
+  such experiments are being run.
 
 The list of all known strings we collect can be found at
 https://source.chromium.org/chromium/infra/infra/+/HEAD:go/src/infra/appengine/depot_tools_metrics/metrics/constants.go

+ 13 - 1
metrics.py

@@ -1,4 +1,3 @@
-#!/usr/bin/env python3
 # Copyright (c) 2018 The Chromium Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
@@ -16,6 +15,7 @@ import urllib.request
 import detect_host_arch
 import gclient_utils
 import metrics_utils
+import newauth
 import subprocess2
 import utils
 
@@ -251,6 +251,18 @@ class MetricsCollector(object):
         if bot_metrics:
             self.add('bot_metrics', bot_metrics)
 
+        # TODO(b/347085702): Remove this variable when dogfood is over.
+        new_auth_enabled = 'DEFAULT'
+        if newauth.Enabled():
+            new_auth_enabled = 'TRUE'
+        elif newauth.ExplicitlyDisabled():
+            new_auth_enabled = 'FALSE'
+        if new_auth_enabled != 'DEFAULT':
+            self.add_repeated('env_vars', {
+                'name': 'DOGFOOD_NEW_AUTH',
+                'value': new_auth_enabled,
+            })
+
         self._upload_metrics_data()
         if exception:
             gclient_utils.reraise(exception[0], exception[1], exception[2])

+ 8 - 2
metrics_utils.py

@@ -1,4 +1,3 @@
-#!/usr/bin/env python3
 # Copyright (c) 2018 The Chromium Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
@@ -13,7 +12,7 @@ import urllib.parse
 # 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 = 2
+CURRENT_VERSION = 3
 
 APP_URL = 'https://cit-cli-metrics.appspot.com'
 
@@ -73,6 +72,13 @@ def get_change_notice(version):
             'authenticated as bot service accounts.',
         ]
 
+    if version == 3:
+        return [
+            'We will start collecting metrics for experiment flags.',
+            'These are boolean or enum values that show whether',
+            'you have opted in to or out of experimental features',
+        ]
+
 
 KNOWN_PROJECT_URLS = {
     'https://chrome-internal.googlesource.com/chrome/ios_internal',

+ 3 - 0
tests/metrics_test.py

@@ -66,6 +66,9 @@ class MetricsCollectorTest(unittest.TestCase):
         mock.patch('metrics_utils.get_repo_timestamp', lambda _: 1234).start()
         mock.patch('metrics_utils.get_git_version', lambda: '2.18.1').start()
 
+        mock.patch('newauth.Enabled', lambda: False).start()
+        mock.patch('newauth.ExplicitlyDisabled', lambda: False).start()
+
         self.maxDiff = None
         self.default_metrics = {
             "metrics_version": 0,