metrics: Report bot metrics if DEPOT_TOOLS_REPORT_BUILD is set
If the DEPOT_TOOLS_REPORT_BUILD envvar is set, Depot Tools will
report information about the builder running the command
(e.g. buildbucket project, bucket, builder and build id).
It will also authenticate to the metrics server, and ignore any
requests not made by ChOps service accounts.
Change-Id: I078a4c2170b4226086c42f289fa449bdebc87179
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2861213
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
diff --git a/metrics.py b/metrics.py
index 69c19e4..df366a4 100644
--- a/metrics.py
+++ b/metrics.py
@@ -117,12 +117,16 @@
@property
def should_collect_metrics(self):
- # Don't collect the metrics unless the user is a googler, the user has opted
- # in, or the countdown has expired.
+ # DEPOT_TOOLS_REPORT_BUILD is set on bots to report metrics.
+ if os.getenv(metrics_utils.DEPOT_TOOLS_REPORT_BUILD):
+ return True
+ # Don't report metrics if user is not a Googler.
if not self.is_googler:
return False
+ # Don't report metrics if user has opted out.
if self.opted_in is False:
return False
+ # Don't report metrics if countdown hasn't reached 0.
if self.opted_in is None and self.countdown > 0:
return False
return True
@@ -227,6 +231,10 @@
if git_version:
self.add('git_version', git_version)
+ bot_metrics = metrics_utils.get_bot_metrics()
+ if bot_metrics:
+ self.add('bot_metrics', bot_metrics)
+
self._upload_metrics_data()
if exception:
gclient_utils.reraise(exception[0], exception[1], exception[2])