Enable telemetry flags for Google corp machines only.

Bug: b/348530235
Change-Id: I4ac32c60b806f44920bd06e31ec6c3b86a6a6964
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7104218
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
Reviewed-by: Junji Watanabe <jwata@google.com>
This commit is contained in:
Alex Ovsienko
2025-11-09 17:13:31 -08:00
committed by LUCI CQ
parent a8d3023ff0
commit 4e2be179a1
2 changed files with 29 additions and 5 deletions

View File

@@ -26,6 +26,7 @@ import sys
import time
import uuid
import warnings
from typing import Optional
import android_build_server_helper
import build_telemetry
@@ -275,7 +276,10 @@ def _check_reclient_cfgs(output_dir):
file=sys.stderr,
)
def _main_inner(input_args, build_id):
def _main_inner(input_args,
build_id,
telemetry_cfg: Optional[build_telemetry.Config] = None):
# If running in the Gemini CLI, automatically add --quiet if it's not
# already present to avoid filling the context window.
if os.environ.get('GEMINI_CLI') == '1':
@@ -494,7 +498,7 @@ def _main_inner(input_args, build_id):
# Print the command-line to reassure the user that the right
# settings are being used.
_print_cmd(args)
return siso.main(args)
return siso.main(args, telemetry_cfg)
if use_remoteexec:
if use_reclient and not t_specified:
# TODO: crbug.com/379584977 - Remove siso/reclient
@@ -683,15 +687,16 @@ def main(args):
# are not supported by autoninja, but that is not a real limitation.
input_args = args
exit_code = 127
telemetry_cfg = build_telemetry.load_config()
should_collect_logs = telemetry_cfg.enabled()
if sys.platform.startswith("win") and len(args) == 2:
input_args = args[:1] + args[1].split()
try:
exit_code = _main_inner(input_args, build_id)
exit_code = _main_inner(input_args, build_id, telemetry_cfg)
except KeyboardInterrupt:
exit_code = 1
finally:
# Check the log collection opt-in/opt-out status, and display notice if necessary.
should_collect_logs = build_telemetry.enabled()
if should_collect_logs:
warnings.simplefilter("ignore", ResourceWarning)
elapsed = time.time() - start

21
siso.py
View File

@@ -14,7 +14,9 @@ import signal
import shlex
import shutil
import sys
from typing import Optional
import build_telemetry
import caffeinate
import gclient_paths
@@ -68,6 +70,18 @@ def apply_metrics_labels(args: list[str]) -> list[str]:
return args + ["--metrics_labels", ",".join(result)]
def apply_telemetry_flags(args: list[str]) -> list[str]:
telemetry_flags = [
"enable_cloud_monitoring", "enable_cloud_profiler",
"enable_cloud_trace", "enable_cloud_logging"
]
flag_to_add = []
for flag in telemetry_flags:
if f"-{flag}" not in args and f"--{flag}" not in args:
flag_to_add.append(f"--{flag}")
return args + flag_to_add
def load_sisorc(rcfile):
if not os.path.exists(rcfile):
return [], {}
@@ -106,11 +120,14 @@ def _is_google_corp_machine():
return shutil.which("gcert") is not None
def main(args):
def main(args, telemetry_cfg: Optional[build_telemetry.Config] = None):
# Do not raise KeyboardInterrupt on SIGINT so as to give siso time to run
# cleanup tasks. Siso will be terminated immediately after the second
# Ctrl-C.
original_sigint_handler = signal.getsignal(signal.SIGINT)
if not telemetry_cfg:
telemetry_cfg = build_telemetry.load_config()
should_collect_logs = telemetry_cfg.enabled()
def _ignore(signum, frame):
try:
@@ -223,6 +240,8 @@ def main(args):
print('depot_tools/siso.py: %s' % shlex.join(new_args),
file=sys.stderr)
new_args = apply_metrics_labels(new_args)
if should_collect_logs:
new_args = apply_telemetry_flags(new_args)
return caffeinate.run([siso_path] + new_args, env=env)
print(
'depot_tools/siso.py: Could not find siso in third_party/siso '