From f776b1b0fea5a9527d9e40012181f21585a973d6 Mon Sep 17 00:00:00 2001 From: Teingi Date: Thu, 11 Jul 2024 11:46:37 +0800 Subject: [PATCH 1/9] table dump print pretty result --- core.py | 2 ++ handler/gather/gather_tabledump.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core.py b/core.py index 27297831..7d678312 100644 --- a/core.py +++ b/core.py @@ -239,6 +239,7 @@ def gather_function(self, function_type, opt): return handler.handle() elif function_type == 'gather_tabledump': handler = GatherTableDumpHandler(self.context) + return handler.handle() elif function_type == 'gather_parameters': handler = GatherParametersHandler(self.context) return handler.handle() @@ -290,6 +291,7 @@ def analyze_fuction(self, function_type, opt): elif function_type == 'analyze_sql_review': self.set_context(function_type, 'analyze', config) handler = AnalyzeSQLReviewHandler(self.context) + handler.handle() elif function_type == 'analyze_parameter_non_default': self.set_context(function_type, 'analyze', config) handler = AnalyzeParameterHandler(self.context, 'non_default') diff --git a/handler/gather/gather_tabledump.py b/handler/gather/gather_tabledump.py index 52ab0538..61196405 100644 --- a/handler/gather/gather_tabledump.py +++ b/handler/gather/gather_tabledump.py @@ -17,6 +17,7 @@ """ import os +import time from stdio import SafeStdio from common.ob_connector import OBConnector from common.tool import StringUtils @@ -93,12 +94,13 @@ def init_config(self): return False def handle(self): + self.start_time = time.time() if not self.init_config(): self.stdio.error('init config failed') return False self.execute() if not self.is_innner: - self.stdio.print("get table info finished. For more details, please run cmd '" + Fore.YELLOW + " cat {0} ".format(self.file_name) + Style.RESET_ALL + "'") + self.__print_result() def execute(self): try: @@ -227,3 +229,12 @@ def __extract_string(self, s): return s[at_index + 1 :] else: return s + + def __print_result(self): + self.end_time = time.time() + elapsed_time = self.end_time - self.start_time + data = [["Status", "Result Details", "Time"], ["Completed", self.file_name, f"{elapsed_time:.2f} s"]] + table = tabulate(data, headers="firstrow", tablefmt="grid") + self.stdio.print("\nAnalyze SQL Summary:") + self.stdio.print(table) + self.stdio.print("\n") From d77000a1b951b0ddc4f8e40132849d760aa2ec45 Mon Sep 17 00:00:00 2001 From: Teingi Date: Fri, 12 Jul 2024 11:29:52 +0800 Subject: [PATCH 2/9] Fix regression testing bugs --- dependencies/bin/obstack_x86_64_7 | Bin handler/analyzer/analyze_flt_trace.py | 3 ++- handler/gather/gather_obstack2.py | 1 - handler/gather/gather_perf.py | 9 +++++---- handler/gather/gather_plan_monitor.py | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) mode change 100644 => 100755 dependencies/bin/obstack_x86_64_7 diff --git a/dependencies/bin/obstack_x86_64_7 b/dependencies/bin/obstack_x86_64_7 old mode 100644 new mode 100755 diff --git a/handler/analyzer/analyze_flt_trace.py b/handler/analyzer/analyze_flt_trace.py index fb14ccae..8624baaf 100644 --- a/handler/analyzer/analyze_flt_trace.py +++ b/handler/analyzer/analyze_flt_trace.py @@ -192,7 +192,7 @@ def check_filename(filename): log_full_path = "{gather_path}/{log_name}".format(log_name=self.flt_trace_id, gather_path=gather_path) download_file(ssh_client, log_full_path, local_store_path, self.stdio) - def __get_offline_log_file(self, ssh_client, log_full_path, local_store_dir): + def __get_offline_log_file(self, ssh_client, log_path, local_store_dir): """ :param ssh_client, log_name :return: @@ -202,6 +202,7 @@ def __get_offline_log_file(self, ssh_client, log_full_path, local_store_dir): if self.flt_trace_id is not None and (len(log_name_list) > 0): grep_cmd = "grep -e '{grep_args}' {log_file} > {local_store_path} ".format(grep_args=self.flt_trace_id, log_file=' '.join(log_name_list), local_store_path=local_store_path) LocalClient(self.stdio).run(grep_cmd) + log_full_path = "{gather_path}/{log_name}".format(gather_path=log_path, log_name=self.flt_trace_id) download_file(ssh_client, log_full_path, local_store_path, self.stdio) def __get_log_name_list_offline(self): diff --git a/handler/gather/gather_obstack2.py b/handler/gather/gather_obstack2.py index 2178a51e..e1167ccb 100644 --- a/handler/gather/gather_obstack2.py +++ b/handler/gather/gather_obstack2.py @@ -224,7 +224,6 @@ def __gather_obstack2_info(self, ssh_client, user, observer_pid, remote_gather_d ssh_client.exec_cmd(chown_cmd) self.stdio.verbose("gather obstack info on server {0}, run cmd = [su {1}, {2}]".format(ssh_client.get_name(), user, cmd)) ssh_client.ssh_invoke_shell_switch_user(user, cmd, 10) - ssh_client.exec_cmd("rm -rf /tmp/{0}".format(remote_gather_dir)) @staticmethod def __get_overall_summary(node_summary_tuple): diff --git a/handler/gather/gather_perf.py b/handler/gather/gather_perf.py index e9244425..1c2a71cc 100644 --- a/handler/gather/gather_perf.py +++ b/handler/gather/gather_perf.py @@ -22,7 +22,7 @@ import tabulate from common.command import get_observer_pid, mkdir, zip_dir, get_file_size, download_file, delete_file_force -from common.command import LocalClient, SshClient +from common.command import SshClient from common.constant import const from handler.base_shell_handler import BaseShellHandler from common.tool import Util @@ -118,9 +118,6 @@ def __handle_from_node(self, node, local_stored_path): resp = {"skip": False, "error": "", "gather_pack_path": ""} remote_ip = node.get("ip") if self.is_ssh else NetUtils.get_inner_ip(self.stdio) remote_user = node.get("ssh_username") - remote_password = node.get("ssh_password") - remote_port = node.get("ssh_port") - remote_private_key = node.get("ssh_key_file") self.stdio.verbose("Sending Collect Shell Command to node {0} ...".format(remote_ip)) DirectoryUtil.mkdir(path=local_stored_path, stdio=self.stdio) now_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S') @@ -167,17 +164,20 @@ def __handle_from_node(self, node, local_stored_path): def __gather_perf_sample(self, ssh_client, gather_path, pid_observer): try: + self.stdio.start_loading('gather perf sample') cmd = "cd {gather_path} && perf record -o sample.data -e cycles -c 100000000 -p {pid} -g -- sleep 20".format(gather_path=gather_path, pid=pid_observer) self.stdio.verbose("gather perf sample, run cmd = [{0}]".format(cmd)) ssh_client.exec_cmd(cmd) generate_data = "cd {gather_path} && perf script -i sample.data -F ip,sym -f > sample.viz".format(gather_path=gather_path) self.stdio.verbose("generate perf sample data, run cmd = [{0}]".format(generate_data)) ssh_client.exec_cmd(generate_data) + self.stdio.stop_loading('gather perf sample') except: self.stdio.error("generate perf sample data on server [{0}] failed".format(ssh_client.get_name())) def __gather_perf_flame(self, ssh_client, gather_path, pid_observer): try: + self.stdio.start_loading('gather perf flame') perf_cmd = "cd {gather_path} && perf record -o flame.data -F 99 -p {pid} -g -- sleep 20".format(gather_path=gather_path, pid=pid_observer) self.stdio.verbose("gather perf, run cmd = [{0}]".format(perf_cmd)) ssh_client.exec_cmd(perf_cmd) @@ -185,6 +185,7 @@ def __gather_perf_flame(self, ssh_client, gather_path, pid_observer): generate_data = "cd {gather_path} && perf script -i flame.data > flame.viz".format(gather_path=gather_path) self.stdio.verbose("generate perf data, run cmd = [{0}]".format(generate_data)) ssh_client.exec_cmd(generate_data) + self.stdio.stop_loading('gather perf flame') except: self.stdio.error("generate perf data on server [{0}] failed".format(ssh_client.get_name())) diff --git a/handler/gather/gather_plan_monitor.py b/handler/gather/gather_plan_monitor.py index 454c49a5..38683d8e 100644 --- a/handler/gather/gather_plan_monitor.py +++ b/handler/gather/gather_plan_monitor.py @@ -259,7 +259,7 @@ def get_table_info(self, file_path): data = f.read() return data except Exception as e: - self.stdio.error(e) + self.stdio.warn(e) return None def report_schema(self, sql, tenant_name): From c46510ac129ae1e94f7807a070967472d836a3e3 Mon Sep 17 00:00:00 2001 From: Teingi Date: Fri, 12 Jul 2024 11:32:31 +0800 Subject: [PATCH 3/9] Fix regression testing bugs --- dependencies/bin/obstack_x86_64_7 | Bin 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 dependencies/bin/obstack_x86_64_7 diff --git a/dependencies/bin/obstack_x86_64_7 b/dependencies/bin/obstack_x86_64_7 old mode 100755 new mode 100644 From b62132f66452fab929dd98071a9c3f7855e1bda8 Mon Sep 17 00:00:00 2001 From: Teingi Date: Fri, 12 Jul 2024 11:47:07 +0800 Subject: [PATCH 4/9] Optimize logs --- dependencies/bin/obstack_x86_64_7 | Bin diag_cmd.py | 2 +- handler/analyzer/analyze_log.py | 2 +- handler/analyzer/analyze_parameter.py | 4 ++-- handler/analyzer/analyze_sql.py | 2 +- handler/analyzer/analyze_sql_review.py | 2 +- handler/analyzer/analyze_variable.py | 2 +- handler/gather/gather_ash_report.py | 2 +- handler/gather/gather_awr.py | 2 +- handler/gather/gather_log.py | 2 +- handler/gather/gather_obadmin.py | 2 +- handler/gather/gather_obproxy_log.py | 2 +- handler/gather/gather_obstack2.py | 2 +- handler/gather/gather_parameters.py | 2 +- handler/gather/gather_perf.py | 2 +- handler/gather/gather_scenes.py | 2 +- handler/gather/gather_sysstat.py | 2 +- handler/gather/gather_variables.py | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) mode change 100644 => 100755 dependencies/bin/obstack_x86_64_7 diff --git a/dependencies/bin/obstack_x86_64_7 b/dependencies/bin/obstack_x86_64_7 old mode 100644 new mode 100755 diff --git a/diag_cmd.py b/diag_cmd.py index 49b31fb1..24f8a6ec 100644 --- a/diag_cmd.py +++ b/diag_cmd.py @@ -744,7 +744,7 @@ def _do_command(self, obdiag): class ObdiagAnalyzeSQLReviewCommand(ObdiagOriginCommand): def __init__(self): - super(ObdiagAnalyzeSQLReviewCommand, self).__init__('sql_review', 'Analyze oceanbase sql from sql_audit ') + super(ObdiagAnalyzeSQLReviewCommand, self).__init__('sql_review', 'Analyze oceanbase sql from file') self.parser.add_option('--host', type='string', help="tenant connection host") self.parser.add_option('--port', type='string', help="tenant connection port") self.parser.add_option('--password', type='string', help="tenant connection user password", default='') diff --git a/handler/analyzer/analyze_log.py b/handler/analyzer/analyze_log.py index 0d4a9646..434211e6 100644 --- a/handler/analyzer/analyze_log.py +++ b/handler/analyzer/analyze_log.py @@ -110,7 +110,7 @@ def init_option(self): self.stdio.print('analyze log from_time: {0}, to_time: {1}'.format(self.from_time_str, self.to_time_str)) if store_dir_option is not None: if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('Error: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.gather_pack_dir = os.path.abspath(store_dir_option) if grep_option is not None: diff --git a/handler/analyzer/analyze_parameter.py b/handler/analyzer/analyze_parameter.py index 97ca13cc..96c8c836 100644 --- a/handler/analyzer/analyze_parameter.py +++ b/handler/analyzer/analyze_parameter.py @@ -82,7 +82,7 @@ def init_option_non_default(self): offline_file_option = Util.get_option(options, 'file') if store_dir_option and store_dir_option != "./": if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.export_report_path = os.path.abspath(store_dir_option) else: @@ -105,7 +105,7 @@ def init_option_diff(self): offline_file_option = Util.get_option(options, 'file') if store_dir_option and store_dir_option != "./": if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.export_report_path = os.path.abspath(store_dir_option) else: diff --git a/handler/analyzer/analyze_sql.py b/handler/analyzer/analyze_sql.py index d54168e3..e6ab6374 100644 --- a/handler/analyzer/analyze_sql.py +++ b/handler/analyzer/analyze_sql.py @@ -161,7 +161,7 @@ def init_option(self): store_dir_option = Util.get_option(options, 'store_dir') if store_dir_option is not None: if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('Error: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.local_stored_parrent_path = os.path.abspath(store_dir_option) output_option = Util.get_option(options, 'output') diff --git a/handler/analyzer/analyze_sql_review.py b/handler/analyzer/analyze_sql_review.py index 1b69f3eb..c4253705 100644 --- a/handler/analyzer/analyze_sql_review.py +++ b/handler/analyzer/analyze_sql_review.py @@ -91,7 +91,7 @@ def init_option(self): store_dir_option = Util.get_option(options, 'store_dir') if store_dir_option is not None: if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('Error: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.local_stored_parrent_path = os.path.abspath(store_dir_option) output_option = Util.get_option(options, 'output') diff --git a/handler/analyzer/analyze_variable.py b/handler/analyzer/analyze_variable.py index 43fc8d32..cf88e64f 100644 --- a/handler/analyzer/analyze_variable.py +++ b/handler/analyzer/analyze_variable.py @@ -75,7 +75,7 @@ def init_option(self): if store_dir_option and store_dir_option != "./": if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.export_report_path = os.path.abspath(store_dir_option) else: diff --git a/handler/gather/gather_ash_report.py b/handler/gather/gather_ash_report.py index f6aa955e..fc1e4eb1 100644 --- a/handler/gather/gather_ash_report.py +++ b/handler/gather/gather_ash_report.py @@ -153,7 +153,7 @@ def init_option(self): self.stdio.print('gather from_time: {0}, to_time: {1}'.format(self.from_time_str, self.to_time_str)) if store_dir_option: if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.gather_pack_dir = os.path.abspath(store_dir_option) if sql_id_option: diff --git a/handler/gather/gather_awr.py b/handler/gather/gather_awr.py index 9e58d106..bec5b9e6 100644 --- a/handler/gather/gather_awr.py +++ b/handler/gather/gather_awr.py @@ -270,7 +270,7 @@ def init_option(self): self.stdio.print('gather log from_time: {0}, to_time: {1}'.format(self.from_time_str, self.to_time_str)) if store_dir_option and store_dir_option != "./": if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.gather_pack_dir = os.path.abspath(store_dir_option) return True diff --git a/handler/gather/gather_log.py b/handler/gather/gather_log.py index 8bbbf412..f368cab5 100644 --- a/handler/gather/gather_log.py +++ b/handler/gather/gather_log.py @@ -118,7 +118,7 @@ def init_option(self): self.stdio.print('gather log from_time: {0}, to_time: {1}'.format(self.from_time_str, self.to_time_str)) if store_dir_option is not None and store_dir_option != './': if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.gather_pack_dir = os.path.abspath(store_dir_option) if scope_option: diff --git a/handler/gather/gather_obadmin.py b/handler/gather/gather_obadmin.py index 39169fc5..a7c3da04 100644 --- a/handler/gather/gather_obadmin.py +++ b/handler/gather/gather_obadmin.py @@ -106,7 +106,7 @@ def init_option(self): self.stdio.print('gather from_time: {0}, to_time: {1}'.format(self.from_time_str, self.to_time_str)) if store_dir_option and store_dir_option != './': if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('Error: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.local_stored_path = os.path.abspath(store_dir_option) if encrypt_option == "true": diff --git a/handler/gather/gather_obproxy_log.py b/handler/gather/gather_obproxy_log.py index 265e6446..efd54b37 100644 --- a/handler/gather/gather_obproxy_log.py +++ b/handler/gather/gather_obproxy_log.py @@ -121,7 +121,7 @@ def init_option(self): self.stdio.print('gather from_time: {0}, to_time: {1}'.format(self.from_time_str, self.to_time_str)) if store_dir_option and store_dir_option != './': if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.gather_pack_dir = os.path.abspath(store_dir_option) if scope_option: diff --git a/handler/gather/gather_obstack2.py b/handler/gather/gather_obstack2.py index e1167ccb..2ca09f70 100644 --- a/handler/gather/gather_obstack2.py +++ b/handler/gather/gather_obstack2.py @@ -69,7 +69,7 @@ def init_option(self): store_dir_option = Util.get_option(options, 'store_dir') if store_dir_option and store_dir_option != './': if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.local_stored_path = os.path.abspath(store_dir_option) return True diff --git a/handler/gather/gather_parameters.py b/handler/gather/gather_parameters.py index bec7463e..066179c9 100644 --- a/handler/gather/gather_parameters.py +++ b/handler/gather/gather_parameters.py @@ -66,7 +66,7 @@ def init_option(self): store_dir_option = Util.get_option(options, 'store_dir') if store_dir_option and store_dir_option != "./": if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.gather_pack_dir = os.path.abspath(store_dir_option) return True diff --git a/handler/gather/gather_perf.py b/handler/gather/gather_perf.py index 1c2a71cc..db792d3d 100644 --- a/handler/gather/gather_perf.py +++ b/handler/gather/gather_perf.py @@ -70,7 +70,7 @@ def init_option(self): store_dir_option = Util.get_option(options, 'store_dir') if store_dir_option and store_dir_option != './': if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.local_stored_path = os.path.abspath(store_dir_option) self.scope_option = Util.get_option(options, 'scope') diff --git a/handler/gather/gather_scenes.py b/handler/gather/gather_scenes.py index b782c672..d54e2f57 100644 --- a/handler/gather/gather_scenes.py +++ b/handler/gather/gather_scenes.py @@ -209,7 +209,7 @@ def init_option(self): self.stdio.print('gather from_time: {0}, to_time: {1}'.format(self.from_time_str, self.to_time_str)) if store_dir_option: if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.gather_pack_dir = os.path.abspath(store_dir_option) if scene_option: diff --git a/handler/gather/gather_sysstat.py b/handler/gather/gather_sysstat.py index f9299c7d..a77dff57 100644 --- a/handler/gather/gather_sysstat.py +++ b/handler/gather/gather_sysstat.py @@ -71,7 +71,7 @@ def init_option(self): store_dir_option = Util.get_option(options, 'store_dir') if store_dir_option and store_dir_option != './': if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.local_stored_path = os.path.abspath(store_dir_option) self.scope_option = Util.get_option(options, 'scope') diff --git a/handler/gather/gather_variables.py b/handler/gather/gather_variables.py index 55c790ba..f1e2ea99 100644 --- a/handler/gather/gather_variables.py +++ b/handler/gather/gather_variables.py @@ -64,7 +64,7 @@ def init_option(self): store_dir_option = Util.get_option(options, 'store_dir') if store_dir_option and store_dir_option != "./": if not os.path.exists(os.path.abspath(store_dir_option)): - self.stdio.warn('warn: args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + self.stdio.warn('args --store_dir [{0}] incorrect: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) os.makedirs(os.path.abspath(store_dir_option)) self.gather_pack_dir = os.path.abspath(store_dir_option) return True From 6228ba39199a34c14994fdd2e9dbbb0495b3f187 Mon Sep 17 00:00:00 2001 From: Teingi Date: Fri, 12 Jul 2024 11:47:28 +0800 Subject: [PATCH 5/9] Optimize logs --- dependencies/bin/obstack_x86_64_7 | Bin 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 dependencies/bin/obstack_x86_64_7 diff --git a/dependencies/bin/obstack_x86_64_7 b/dependencies/bin/obstack_x86_64_7 old mode 100755 new mode 100644 From 6b286e42b56f886294880cadd3d94309acf230a5 Mon Sep 17 00:00:00 2001 From: Teingi Date: Fri, 12 Jul 2024 11:55:25 +0800 Subject: [PATCH 6/9] Optimize logs --- handler/analyzer/analyze_parameter.py | 4 ++-- handler/analyzer/analyze_variable.py | 4 ++-- handler/gather/gather_parameters.py | 14 +++++++------- handler/gather/gather_tabledump.py | 2 +- handler/gather/gather_variables.py | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/handler/analyzer/analyze_parameter.py b/handler/analyzer/analyze_parameter.py index 96c8c836..47b51480 100644 --- a/handler/analyzer/analyze_parameter.py +++ b/handler/analyzer/analyze_parameter.py @@ -59,8 +59,8 @@ def get_version(self): try: observer_version = get_observer_version_by_sql(self.ob_cluster, self.stdio) except Exception as e: - self.stdio.warn("AnalyzeHandler Failed to get observer version:{0}".format(e)) - self.stdio.verbose("AnalyzeHandler.init get observer version: {0}".format(observer_version)) + self.stdio.warn("failed to get observer version:{0}".format(e)) + self.stdio.verbose("get observer version: {0}".format(observer_version)) return observer_version def handle(self): diff --git a/handler/analyzer/analyze_variable.py b/handler/analyzer/analyze_variable.py index cf88e64f..478c3c3d 100644 --- a/handler/analyzer/analyze_variable.py +++ b/handler/analyzer/analyze_variable.py @@ -48,8 +48,8 @@ def __init__(self, context): database="oceanbase", ) except Exception as e: - self.stdio.error("Failed to connect to database: {0}".format(e)) - raise OBDIAGFormatException("Failed to connect to database: {0}".format(e)) + self.stdio.error("failed to connect to database: {0}".format(e)) + raise OBDIAGFormatException("failed to connect to database: {0}".format(e)) def handle(self): if not self.init_option(): diff --git a/handler/gather/gather_parameters.py b/handler/gather/gather_parameters.py index 066179c9..ea553faf 100644 --- a/handler/gather/gather_parameters.py +++ b/handler/gather/gather_parameters.py @@ -47,8 +47,8 @@ def __init__(self, context, gather_pack_dir='./'): database="oceanbase", ) except Exception as e: - self.stdio.error("Failed to connect to database: {0}".format(e)) - raise OBDIAGFormatException("Failed to connect to database: {0}".format(e)) + self.stdio.error("failed to connect to database: {0}".format(e)) + raise OBDIAGFormatException("failed to connect to database: {0}".format(e)) def handle(self): if not self.init_option(): @@ -76,8 +76,8 @@ def get_version(self): try: observer_version = get_observer_version_by_sql(self.ob_cluster, self.stdio) except Exception as e: - self.stdio.warn("GatherHandler Failed to get observer version:{0}".format(e)) - self.stdio.verbose("GatherHandler.init get observer version: {0}".format(observer_version)) + self.stdio.warn("failed to get observer version:{0}".format(e)) + self.stdio.verbose("get observer version: {0}".format(observer_version)) return observer_version def get_cluster_name(self): @@ -87,8 +87,8 @@ def get_cluster_name(self): cluster_info = self.obconn.execute_sql(sql) cluster_name = cluster_info[0][0] except Exception as e: - self.stdio.warn("RCAHandler Failed to get oceanbase cluster name:{0}".format(e)) - self.stdio.verbose("RCAHandler.init get oceanbase cluster name {0}".format(cluster_name)) + self.stdio.warn("failed to get oceanbase cluster name:{0}".format(e)) + self.stdio.verbose("get oceanbase cluster name {0}".format(cluster_name)) return cluster_name def get_parameters_info(self): @@ -121,7 +121,7 @@ def get_parameters_info(self): writer.writerow(row) self.stdio.print("Gather parameters finished. For more details, please run cmd '" + Fore.YELLOW + "cat {0}".format(self.parameter_file_name) + Style.RESET_ALL + "'") else: - self.stdio.warn("Failed to retrieve the database version. Please check if the database connection is normal.") + self.stdio.warn("failed to retrieve the database version. Please check if the database connection is normal.") def execute(self): try: diff --git a/handler/gather/gather_tabledump.py b/handler/gather/gather_tabledump.py index 61196405..834c80c4 100644 --- a/handler/gather/gather_tabledump.py +++ b/handler/gather/gather_tabledump.py @@ -112,7 +112,7 @@ def execute(self): self.__get_table_info_v3() except Exception as e: self.stdio.error("report sql result to file: {0} failed, error: ".format(self.file_name)) - self.stdio.error("StepSQLHandler execute Exception: {0}".format(e).strip()) + self.stdio.error("GatherTableDumpHandler execute Exception: {0}".format(e).strip()) def __get_table_schema(self): sql = "show create table " + self.database + "." + self.table diff --git a/handler/gather/gather_variables.py b/handler/gather/gather_variables.py index f1e2ea99..34729a3b 100644 --- a/handler/gather/gather_variables.py +++ b/handler/gather/gather_variables.py @@ -46,8 +46,8 @@ def __init__(self, context, gather_pack_dir='./'): database="oceanbase", ) except Exception as e: - self.stdio.error("Failed to connect to database: {0}".format(e)) - raise OBDIAGFormatException("Failed to connect to database: {0}".format(e)) + self.stdio.error("failed to connect to database: {0}".format(e)) + raise OBDIAGFormatException("failed to connect to database: {0}".format(e)) def handle(self): if not self.init_option(): @@ -76,8 +76,8 @@ def get_cluster_name(self): cluster_info = self.obconn.execute_sql(sql) cluster_name = cluster_info[0][0] except Exception as e: - self.stdio.warn("RCAHandler Failed to get oceanbase cluster name:{0}".format(e)) - self.stdio.verbose("RCAHandler.init get oceanbase cluster name {0}".format(cluster_name)) + self.stdio.warn("failed to get oceanbase cluster name:{0}".format(e)) + self.stdio.verbose("get oceanbase cluster name {0}".format(cluster_name)) return cluster_name def get_variables_info(self): From 615f04da277d3b7f240e960af00c51071daf3a87 Mon Sep 17 00:00:00 2001 From: Teingi Date: Mon, 15 Jul 2024 17:03:36 +0800 Subject: [PATCH 7/9] fix: gather tabledump --- dependencies/bin/obstack_x86_64_7 | Bin diag_cmd.py | 2 +- handler/gather/gather_tabledump.py | 27 ++++++++++++++------------- 3 files changed, 15 insertions(+), 14 deletions(-) mode change 100644 => 100755 dependencies/bin/obstack_x86_64_7 diff --git a/dependencies/bin/obstack_x86_64_7 b/dependencies/bin/obstack_x86_64_7 old mode 100644 new mode 100755 diff --git a/diag_cmd.py b/diag_cmd.py index 24f8a6ec..06d83d65 100644 --- a/diag_cmd.py +++ b/diag_cmd.py @@ -622,7 +622,7 @@ def __init__(self): self.parser.add_option('--table', type='string', help="Specifies the name of the table in the database to operate on.") self.parser.add_option('--user', type='string', help="The username to use for the database connection.") self.parser.add_option('--password', type='string', help="The password for the database user. If not specified, an attempt will be made to connect without a password.", default='') - self.parser.add_option('--store_dir', type='string', help='the dir to store gather result, current dir by default.', default='./gather_report') + self.parser.add_option('--store_dir', type='string', help='the dir to store gather result, current dir by default.', default='./obdiag_gather_report') self.parser.add_option('-c', type='string', help='obdiag custom config', default=os.path.expanduser('~/.obdiag/config.yml')) def init(self, cmd, args): diff --git a/handler/gather/gather_tabledump.py b/handler/gather/gather_tabledump.py index 834c80c4..3b4484f2 100644 --- a/handler/gather/gather_tabledump.py +++ b/handler/gather/gather_tabledump.py @@ -44,18 +44,12 @@ def __init__(self, context, store_dir="./obdiag_gather_report", is_inner=False): self.result_list = [] self.store_dir = store_dir self.is_innner = is_inner - try: - if not os.path.exists(store_dir): - os.makedirs(store_dir) - except Exception as e: - self.stdio.error("init gather_report {0}".format(e)) - raise Exception("int gather_report {0}".format(e)) if self.context.get_variable("gather_timestamp", None): self.gather_timestamp = self.context.get_variable("gather_timestamp") else: self.gather_timestamp = TimeUtils.get_current_us_timestamp() - def init_config(self): + def init(self): try: self.ob_cluster = self.context.cluster_config self.obproxy_nodes = self.context.obproxy_config['servers'] @@ -68,7 +62,15 @@ def init_config(self): self.table = Util.get_option(options, 'table') user = Util.get_option(options, 'user') password = Util.get_option(options, 'password') - self.store_dir = Util.get_option(options, 'store_dir') + if not (self.database and self.database and user and password): + self.stdio.error("option --database/--table/--user/--password not found, please provide") + return False + store_dir_option = Util.get_option(options, 'store_dir') + if store_dir_option is not None and store_dir_option != './': + if not os.path.exists(os.path.abspath(store_dir_option)): + self.stdio.warn('args --store_dir [{0}]: No such directory, Now create it'.format(os.path.abspath(store_dir_option))) + os.makedirs(os.path.abspath(store_dir_option)) + self.store_dir = os.path.abspath(store_dir_option) if self.context.get_variable("gather_database", None): self.database = self.context.get_variable("gather_database") if self.context.get_variable("gather_table", None): @@ -87,7 +89,7 @@ def init_config(self): ip=self.ob_cluster.get("db_host"), port=self.ob_cluster.get("db_port"), username=self.ob_cluster.get("tenant_sys").get("user"), password=self.ob_cluster.get("tenant_sys").get("password"), stdio=self.stdio, timeout=100 ) self.tenant_connector = OBConnector(ip=self.ob_cluster.get("db_host"), port=self.ob_cluster.get("db_port"), username=user, password=password, stdio=self.stdio, timeout=100) - self.file_name = "{0}/obdiag_tabledump_result_{1}.txt".format(self.store_dir, self.gather_timestamp) + self.file_name = "{0}/obdiag_tabledump_result_{1}.txt".format(self.store_dir, TimeUtils.timestamp_to_filename_time(self.gather_timestamp)) return True except Exception as e: self.stdio.error(e) @@ -95,8 +97,8 @@ def init_config(self): def handle(self): self.start_time = time.time() - if not self.init_config(): - self.stdio.error('init config failed') + if not self.init(): + self.stdio.error('init failed') return False self.execute() if not self.is_innner: @@ -111,8 +113,7 @@ def execute(self): else: self.__get_table_info_v3() except Exception as e: - self.stdio.error("report sql result to file: {0} failed, error: ".format(self.file_name)) - self.stdio.error("GatherTableDumpHandler execute Exception: {0}".format(e).strip()) + self.stdio.error("report sql result to file: {0} failed, error: {1}".format(self.file_name, e)) def __get_table_schema(self): sql = "show create table " + self.database + "." + self.table From 38f0b69b6f6b621e6531187f3a784553d6d468ec Mon Sep 17 00:00:00 2001 From: Teingi Date: Mon, 15 Jul 2024 17:04:18 +0800 Subject: [PATCH 8/9] fix: gather tabledump --- dependencies/bin/obstack_x86_64_7 | Bin 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 dependencies/bin/obstack_x86_64_7 diff --git a/dependencies/bin/obstack_x86_64_7 b/dependencies/bin/obstack_x86_64_7 old mode 100755 new mode 100644 From 832e27a725dae29363e190d731087b26a88d7798 Mon Sep 17 00:00:00 2001 From: Teingi Date: Tue, 16 Jul 2024 11:23:43 +0800 Subject: [PATCH 9/9] fix analyze flt_trace offline --- handler/analyzer/analyze_flt_trace.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/handler/analyzer/analyze_flt_trace.py b/handler/analyzer/analyze_flt_trace.py index 8624baaf..cac530a1 100644 --- a/handler/analyzer/analyze_flt_trace.py +++ b/handler/analyzer/analyze_flt_trace.py @@ -202,8 +202,6 @@ def __get_offline_log_file(self, ssh_client, log_path, local_store_dir): if self.flt_trace_id is not None and (len(log_name_list) > 0): grep_cmd = "grep -e '{grep_args}' {log_file} > {local_store_path} ".format(grep_args=self.flt_trace_id, log_file=' '.join(log_name_list), local_store_path=local_store_path) LocalClient(self.stdio).run(grep_cmd) - log_full_path = "{gather_path}/{log_name}".format(gather_path=log_path, log_name=self.flt_trace_id) - download_file(ssh_client, log_full_path, local_store_path, self.stdio) def __get_log_name_list_offline(self): """