Hean-Chhinling commented on code in PR #8742: URL: https://github.com/apache/hadoop/pull/8742#discussion_r4103028465
########## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/resources/diagnostics/diagnostics_collector.py: ########## @@ -0,0 +1,358 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import logging +import os +import re +import socket +import subprocess +import sys +import time +import xml.etree.ElementTree as ET +from datetime import datetime, timedelta +from typing import List, Optional, Tuple + +logger = logging.getLogger(__name__) + +_TEMP_DIR = "/tmp" +_HADOOP_CONF_DIR: Optional[str] = None +_YARN_SITE_XML = "yarn-site.xml" +_RM_WEBAPP_HTTPS_ADDRESS_KEY = "yarn.resourcemanager.webapp.https.address" +_RM_WEBAPP_HTTP_ADDRESS_KEY = "yarn.resourcemanager.webapp.address" +_RM_ADDRESS: Optional[str] = None +_NODE_SCHEME = "http" + +_RM_LOG_REGEX = r"(?<=\")\/logs.+?RESOURCEMANAGER.+?(?=\")" +_NM_LOG_REGEX = r"(?<=\")\/logs.+?NODEMANAGER.+?(?=\")" +_INPUT_TIME_FORMAT = '%a %b %d %H:%M:%S %Z %Y' # e.g. Wed May 28 07:35:39 UTC 2025 +_OUTPUT_TIME_FORMAT = '%Y-%m-%d %H:%M:%S,%f' # e.g. 2025-05-28 11:57:05,435 +_OUTPUT_TIME_FORMAT_WITHOUT_SECOND = '%Y-%m-%d %H:%M' # e.g. 2025-05-28 11:57 +_NUMBER_OF_JSTACK = 3 + +args = None + + +def list_issues() -> None: + print("application_diagnostic:appId", "scheduler_related_issue", sep="\n") + + +def application_diagnostic() -> str: + """ + Application Logs, Application Info, Application Attempts + Multiple JStack of Hanging Containers and NodeManager + ResourceManager logs during job duration. + NodeManager logs from NodeManager where hanging containers of jobs run during the duration of containers. + """ + if args.arguments is None or len(args.arguments) == 0: + logger.error("Missing application or job id") + sys.exit(os.EX_USAGE) + + app_id = args.arguments[0] + logger.info("Collecting application diagnostics for %s", app_id) + output_path = _create_output_dir(os.path.join(_TEMP_DIR, app_id)) + + nm_address = _get_nodemanager_address(app_id) + app_jstack = _create_request( + _web_url(_NODE_SCHEME, nm_address, "ws/v1/node/apps/{}/jstack/{}".format(app_id, _NUMBER_OF_JSTACK)), + False) + _write_output(output_path, "application_jstack", app_jstack) + + nm_jstack = _create_request( + _web_url(_NODE_SCHEME, nm_address, "ws/v1/node/jstack/{}".format(_NUMBER_OF_JSTACK)), + False) + _write_output(output_path, "nm_{}_jstack".format(nm_address), nm_jstack) + + app_info = _create_request(_rm_url("ws/v1/cluster/apps/{}".format(app_id))) + _write_output(output_path, "application_info", app_info) + + app_attempts = _create_request(_rm_url("ws/v1/cluster/apps/{}/appattempts".format(app_id))) + _write_output(output_path, "application_attempts", app_attempts) + + start_time, end_time = _get_application_time(app_info) + + log_address = _get_node_log_address(_RM_ADDRESS, _RM_LOG_REGEX, _NODE_SCHEME) + _write_output(os.path.join(output_path, "node_log"), "resourcemanager_log", + _filter_node_log(log_address, start_time, end_time, _NODE_SCHEME)) + + if "amHostHttpAddress" in app_info: + app_info_xml = ET.fromstring(app_info) + nm_address = app_info_xml.find("amHostHttpAddress").text + log_address = _get_node_log_address(nm_address, _NM_LOG_REGEX, _NODE_SCHEME) + _write_output(os.path.join(output_path, "node_log"), "nodemanager_log", + _get_container_log(log_address, app_id, _NODE_SCHEME)) + + command = _run_cmd_and_save_output(os.path.join(output_path, "app_logs"), app_id, + "yarn", "logs", "-applicationId", app_id) + command.communicate() + logger.info("Application diagnostics written to %s", output_path) + return output_path + + +def scheduler_related_issue() -> str: + """ + ResourceManager Scheduler Logs with DEBUG enabled for 2 minutes. + Multiple Jstack of ResourceManager + YARN and Scheduler Configuration + Cluster Scheduler API /ws/v1/cluster/scheduler and Cluster Nodes API /ws/v1/cluster/nodes response + Scheduler Activities /ws/v1/cluster/scheduler/bulk-activities response + """ + logger.info("Collecting scheduler-related diagnostics") + output_path = _create_output_dir( + os.path.join(_TEMP_DIR, "scheduler_related_issue" + str(time.time()).split(".")[0])) + + rm_jstack = _create_request(_rm_url("ws/v1/node/jstack/{}".format(_NUMBER_OF_JSTACK)), False) Review Comment: Jstack is part of the design document: <img width="1277" height="650" alt="Screenshot 2026-09-25 at 15 44 30" src="https://github.com/user-attachments/assets/86c81ab7-7f4e-4aca-bd8c-a5d9fb20e8a3" /> There is no easy way to collect Jstack nor is there a trivial way to do. Therefore, I created 3 new endpoints to collect Jstack for Application containers, NodeManager and ResourceManager. This PR is depend on this PR: https://github.com/apache/hadoop/pull/8123 I will correct the endpoint here from `ws/v1/node/jstack` -> `ws/v1/cluster/jstack` since this is the right one for RM. >Additionally, curl does not currently fail on HTTP error responses, so a 404 response could be saved as a successful *_jstack result. Good idea, at this moment it will just write the 404 to the file. But at the same time, this a better than an error in the console log because the user would just download the necessary files instead of viewing the console. But please let me know what do you think :) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
