From 43514a86544fbc69f6e99351bf551d85fd94d78a Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Thu, 23 Jan 2025 16:07:19 +0100 Subject: [PATCH] Remove unused resource-monitor code See https://bugzilla.mozilla.org/show_bug.cgi?id=1906899 --- src/taskgraph/run-task/run-task | 72 ------------------------ src/taskgraph/transforms/run/__init__.py | 37 ------------ 2 files changed, 109 deletions(-) diff --git a/src/taskgraph/run-task/run-task b/src/taskgraph/run-task/run-task index 715ad9e75..f54affbf4 100755 --- a/src/taskgraph/run-task/run-task +++ b/src/taskgraph/run-task/run-task @@ -1026,64 +1026,6 @@ def install_pip_requirements(repositories): run_required_command(b"pip-install", cmd) -def maybe_run_resource_monitoring(): - """Run the resource monitor if available. - - Discussion in https://github.com/taskcluster/taskcluster-rfcs/pull/160 - and https://bugzil.la/1648051 - - """ - if "MOZ_FETCHES" not in os.environ: - return - if "RESOURCE_MONITOR_OUTPUT" not in os.environ: - return - - prefix = b"resource_monitor" - - executable = "{}/resource-monitor/resource-monitor{}".format( - os.environ.get("MOZ_FETCHES_DIR"), ".exe" if IS_WINDOWS else "" - ) - - if not os.path.exists(executable) or not os.access(executable, os.X_OK): - print_line(prefix, b"%s not executable\n" % executable.encode("utf-8")) - return - args = [ - executable, - "-process", - str(os.getpid()), - "-output", - os.environ["RESOURCE_MONITOR_OUTPUT"], - ] - print_line(prefix, b"Resource monitor starting: %s\n" % str(args).encode("utf-8")) - # Avoid environment variables the payload doesn't need. - del os.environ["RESOURCE_MONITOR_OUTPUT"] - - # Without CREATE_NEW_PROCESS_GROUP Windows signals will attempt to kill run-task, too. - process = subprocess.Popen( - args, - # Disable buffering because we want to receive output - # as it is generated so timestamps in logs are - # accurate. - bufsize=0, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if IS_WINDOWS else 0, - cwd=os.getcwd(), - ) - - def capture_output(): - fh = io.TextIOWrapper(process.stdout, encoding="latin1") - while True: - data = fh.readline().encode("latin1") - if data == b"": - break - print_line(prefix, data) - - monitor_process = Thread(target=capture_output) - monitor_process.start() - return process - - def _display_python_version(): print_line( b"setup", b"Python version: %s\n" % platform.python_version().encode("utf-8") @@ -1332,7 +1274,6 @@ def main(args): b"%s is %s\n" % (k.encode("utf-8"), os.environ[k].encode("utf-8")), ) - resource_process = None try: if "MOZ_FETCHES" in os.environ: fetch_artifacts() @@ -1341,21 +1282,8 @@ def main(args): # fetches to grab dependencies. install_pip_requirements(repositories) - resource_process = maybe_run_resource_monitoring() - return run_command(b"task", task_args, cwd=args.task_cwd) finally: - if resource_process: - print_line(b"resource_monitor", b"terminating\n") - if IS_WINDOWS: - # .terminate() on Windows is not a graceful shutdown, due to - # differences in signals. CTRL_BREAK_EVENT will work provided - # the subprocess is in a different process group, so this script - # isn't also killed. - os.kill(resource_process.pid, signal.CTRL_BREAK_EVENT) - else: - resource_process.terminate() - resource_process.wait() fetches_dir = os.environ.get("MOZ_FETCHES_DIR") if fetches_dir and os.path.isdir(fetches_dir): print_line(b"fetches", b"removing %s\n" % fetches_dir.encode("utf-8")) diff --git a/src/taskgraph/transforms/run/__init__.py b/src/taskgraph/transforms/run/__init__.py index cf40bd1c0..685cbcf30 100644 --- a/src/taskgraph/transforms/run/__init__.py +++ b/src/taskgraph/transforms/run/__init__.py @@ -160,43 +160,6 @@ def set_label(config, tasks): yield task -@transforms.add -def add_resource_monitor(config, tasks): - for task in tasks: - if task.get("attributes", {}).get("resource-monitor"): - worker_implementation, worker_os = worker_type_implementation( - config.graph_config, task["worker-type"] - ) - # Normalise worker os so that linux-bitbar and similar use linux tools. - if worker_os: - worker_os = worker_os.split("-")[0] - if "win7" in task["worker-type"]: - arch = "32" - else: - arch = "64" - task.setdefault("fetches", {}) - task["fetches"].setdefault("toolchain", []) - task["fetches"]["toolchain"].append(f"{worker_os}{arch}-resource-monitor") - - if worker_implementation == "docker-worker": - artifact_source = "/builds/worker/monitoring/resource-monitor.json" - else: - artifact_source = "monitoring/resource-monitor.json" - task["worker"].setdefault("artifacts", []) - task["worker"]["artifacts"].append( - { - "name": "public/monitoring/resource-monitor.json", - "type": "file", - "path": artifact_source, - } - ) - # Set env for output file - task["worker"].setdefault("env", {}) - task["worker"]["env"]["RESOURCE_MONITOR_OUTPUT"] = artifact_source - - yield task - - def get_attribute(dict, key, attributes, attribute_name): """Get `attribute_name` from the given `attributes` dict, and if there is a corresponding value, set `key` in `dict` to that value."""