From b2802257c7cd2cf253847d67da5ddcc780a5b85f Mon Sep 17 00:00:00 2001 From: Richard Samuels Date: Thu, 20 May 2021 09:48:06 -0400 Subject: [PATCH] SERVER-56528 hang analyzer should always run when supplied a pid --- .../resmokelib/hang_analyzer/hang_analyzer.py | 16 +++++++--------- .../resmokelib/hang_analyzer/process_list.py | 9 +++++++-- .../hang_analyzer/test_process_list.py | 11 ++++------- etc/pip/components/resmoke.req | 1 + 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/buildscripts/resmokelib/hang_analyzer/hang_analyzer.py b/buildscripts/resmokelib/hang_analyzer/hang_analyzer.py index 68ae72e716d..162c21cd1a7 100755 --- a/buildscripts/resmokelib/hang_analyzer/hang_analyzer.py +++ b/buildscripts/resmokelib/hang_analyzer/hang_analyzer.py @@ -17,8 +17,10 @@ import re import signal import sys import traceback +import getpass import psutil +import distro from buildscripts.resmokelib.hang_analyzer import extractor from buildscripts.resmokelib.hang_analyzer import dumper @@ -168,22 +170,18 @@ class HangAnalyzer(Subcommand): try: if sys.platform == "win32" or sys.platform == "cygwin": - distro = platform.win32_ver() - self.root_logger.info("Windows Distribution: %s", distro) + self.root_logger.info("Windows Distribution: %s", platform.win32_ver()) else: - distro = platform.linux_distribution() - self.root_logger.info("Linux Distribution: %s", distro) + self.root_logger.info("Linux Distribution: %s", distro.linux_distribution()) except AttributeError: self.root_logger.warning("Cannot determine Linux distro since Python is too old") try: - uid = os.getuid() - self.root_logger.info("Current User: %s", uid) - current_login = os.getlogin() + current_login = getpass.getuser() self.root_logger.info("Current Login: %s", current_login) - except OSError: - self.root_logger.warning("Cannot determine Unix Current Login") + uid = os.getuid() + self.root_logger.info("Current UID: %s", uid) except AttributeError: self.root_logger.warning( "Cannot determine Unix Current Login, not supported on Windows") diff --git a/buildscripts/resmokelib/hang_analyzer/process_list.py b/buildscripts/resmokelib/hang_analyzer/process_list.py index 5628c762bcd..4704e7ba5cc 100644 --- a/buildscripts/resmokelib/hang_analyzer/process_list.py +++ b/buildscripts/resmokelib/hang_analyzer/process_list.py @@ -50,14 +50,19 @@ def get_processes(process_ids, interesting_processes, process_match, logger): processes_to_keep = [] for process in all_processes: + # skip self if process.pidv == os.getpid(): continue + # if we've been given a list of pids, and the pid isn't in that list + # skip it if process_ids and process.pidv not in process_ids: continue - if interesting_processes and not _pname_match(process_match, process.name, - interesting_processes): + # if we don't have a list of pids, make sure the process matches + # the list of interesting processes + if not process_ids and interesting_processes and not _pname_match( + process_match, process.name, interesting_processes): continue processes_to_keep.append(process) diff --git a/buildscripts/tests/resmokelib/hang_analyzer/test_process_list.py b/buildscripts/tests/resmokelib/hang_analyzer/test_process_list.py index d38dd51e026..5c5801f3f5d 100644 --- a/buildscripts/tests/resmokelib/hang_analyzer/test_process_list.py +++ b/buildscripts/tests/resmokelib/hang_analyzer/test_process_list.py @@ -48,13 +48,9 @@ class TestGetProcesses(unittest.TestCase): @patch(ns("_get_lister")) def test_interesting_processes_and_process_ids(self, lister_mock, os_mock): os_mock.return_value = -1 - lister_mock.return_value.dump_processes.return_value = [ - (1, "python"), - (2, "mongo"), - (3, "python"), - (4, "mongod"), - (5, "java") # this should be ignored. - ] + lister_mock.return_value.dump_processes.return_value = [(1, "python"), (2, "mongo"), + (3, "python"), (4, "mongod"), + (5, "java")] process_ids = [1, 2, 5] interesting_processes = ['python', 'mongo', 'mongod'] @@ -66,6 +62,7 @@ class TestGetProcesses(unittest.TestCase): self.assertCountEqual(processes, [ Pinfo(name="python", pidv=[1]), Pinfo(name="mongo", pidv=[2]), + Pinfo(name="java", pidv=[5]), ]) @patch(ns("os.getpid")) diff --git a/etc/pip/components/resmoke.req b/etc/pip/components/resmoke.req index 96eee4725e7..339fdd63e21 100644 --- a/etc/pip/components/resmoke.req +++ b/etc/pip/components/resmoke.req @@ -14,3 +14,4 @@ googleapis-common-protos == 1.53.0 blackduck == 1.0.1 PyGithub == 1.53 urllib3 >= 1.26.0 +distro == 1.5.0