From dd82867ac5aaa580e46875be5f308c0805f4d986 Mon Sep 17 00:00:00 2001 From: xiaodong-ji Date: Wed, 18 Jun 2025 02:22:13 +0800 Subject: [PATCH 1/7] fix obdiag workflow --- _cmd.py | 4 ++++ core.py | 2 +- plugins/oceanbase-diagnostic-tool/1.0/diag.py | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/_cmd.py b/_cmd.py index 7e1f3590..df255f51 100644 --- a/_cmd.py +++ b/_cmd.py @@ -125,6 +125,8 @@ def _process_long_opt(self, rargs, values): value = rargs[0] OptionParser._process_long_opt(self, rargs, values) except BadOptionError as e: + if self.prog.split()[-1] == "obdiag": + return if self.allow_undefine: key = e.opt_str value = value[len(key)+1:] @@ -138,6 +140,8 @@ def _process_short_opts(self, rargs, values): value = rargs[0] OptionParser._process_short_opts(self, rargs, values) except BadOptionError as e: + if self.prog.split()[-1] == "obdiag": + return if self.allow_undefine: key = e.opt_str value = value[len(key)+1:] diff --git a/core.py b/core.py index e52d4750..6ccd9df5 100644 --- a/core.py +++ b/core.py @@ -4775,7 +4775,7 @@ def obdiag_func(self, args, deploy_name): self._call_stdio('error', err.EC_OBDIAG_NOT_CONTAIN_DEPEND_COMPONENT.format(components=allow_components)) return False cluster_config = deploy_config.components[component_name] - deploy_config.components = {tool_name: cluster_config} + deploy_config.components[tool_name] = cluster_config workflow_name='diag' pkg = self.mirror_manager.get_best_pkg(name=tool_name) diff --git a/plugins/oceanbase-diagnostic-tool/1.0/diag.py b/plugins/oceanbase-diagnostic-tool/1.0/diag.py index 91264e6b..4fb4f5f5 100644 --- a/plugins/oceanbase-diagnostic-tool/1.0/diag.py +++ b/plugins/oceanbase-diagnostic-tool/1.0/diag.py @@ -16,6 +16,7 @@ from __future__ import absolute_import, division, print_function from ssh import LocalClient import _errno as err +import re def diag(plugin_context, *args, **kwargs): @@ -31,4 +32,9 @@ def local_execute_command(command, env=None, timeout=None): if not ret: stdio.error(err.EC_OBDIAG_NOT_FOUND.format()) return plugin_context.return_false() - stdio.print(ret.stdout) + fixed_output = re.sub( + r'Usage: /.*?/obdiag', + 'Usage: obd obdiag', + ret.stdout + ) + stdio.print(fixed_output) From c1ccabf1534fa9495db742e8569cfc1f003cbb45 Mon Sep 17 00:00:00 2001 From: xiaodong-ji Date: Wed, 18 Jun 2025 05:13:26 +0800 Subject: [PATCH 2/7] add obproxy port --- plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py b/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py index b59d2917..8100a6cd 100644 --- a/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py +++ b/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py @@ -66,6 +66,7 @@ def get_obdiag_config(): nodeItem["ssh_password"] = parse_empty(user_config.password) nodeItem["private_key"] = parse_empty(user_config.key_file) server_config = obproxy.get_server_conf(server) + obproxy_config["obproxy_port"] = server_config.get("listen_port") nodeItem["home_path"] = server_config.get("home_path") obproxy_nodes.append(nodeItem) obproxy_config["servers"] = {"nodes": obproxy_nodes, "global": {}} @@ -98,6 +99,10 @@ def get_obdiag_config(): obcluster_config["servers"] = {"nodes": observer_nodes, "global": {}} if len(obproxy_nodes) > 0: config={"obcluster": obcluster_config, "obproxy": obproxy_config} + if obproxy_config["obproxy_port"] == None: + obcluster_config["db_port"] = 2883 + else: + obcluster_config["db_port"] = obproxy_config["obproxy_port"] else: config={"obcluster": obcluster_config} return config From cd0a7155a849c0a5727c3295769f575670568895 Mon Sep 17 00:00:00 2001 From: xiaodong-ji Date: Thu, 19 Jun 2025 00:13:57 +0800 Subject: [PATCH 3/7] optimize output content --- core.py | 2 +- plugins/oceanbase-diagnostic-tool/1.0/diag.py | 17 +++++++++++++++++ .../3.2.0/generate_config.py | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core.py b/core.py index 6ccd9df5..840a7122 100644 --- a/core.py +++ b/core.py @@ -4790,7 +4790,7 @@ def obdiag_func(self, args, deploy_name): workflows = self.get_workflows(workflow_name, [repository]) return self.run_workflow(workflows, deploy_config.components, [repository], **{const.COMP_OCEANBASE_DIAGNOSTIC_TOOL: {"full_cmd": args, "deploy_config": deploy_config}}) else: - self._call_stdio('error', err.EC_OBDIAG_FUNCTION_FAILED.format(function=workflow_name)) + self._call_stdio('error', err.EC_OBDIAG_NOT_FOUND.format()) return False def obdiag_deploy(self, fuction_type): diff --git a/plugins/oceanbase-diagnostic-tool/1.0/diag.py b/plugins/oceanbase-diagnostic-tool/1.0/diag.py index 4fb4f5f5..d5f845c2 100644 --- a/plugins/oceanbase-diagnostic-tool/1.0/diag.py +++ b/plugins/oceanbase-diagnostic-tool/1.0/diag.py @@ -32,9 +32,26 @@ def local_execute_command(command, env=None, timeout=None): if not ret: stdio.error(err.EC_OBDIAG_NOT_FOUND.format()) return plugin_context.return_false() + + fixed_output= "" + if kwargs["full_cmd"][-1] == "list": + command_to_replace = kwargs["full_cmd"][0] + pattern = rf'(\s*)obdiag\s+{re.escape(command_to_replace)}(\s|$)' + replacement = rf'\1obd obdiag {command_to_replace}\2' + fixed_output = re.sub( + pattern, + replacement, + ret.stdout, + flags=re.MULTILINE | re.IGNORECASE + ) fixed_output = re.sub( r'Usage: /.*?/obdiag', 'Usage: obd obdiag', ret.stdout ) + fixed_output = re.sub( + r'()(\s+\[options\])', + r'\1 \2', + fixed_output + ) stdio.print(fixed_output) diff --git a/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py b/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py index 8100a6cd..8c71bb80 100644 --- a/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py +++ b/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py @@ -101,8 +101,10 @@ def get_obdiag_config(): config={"obcluster": obcluster_config, "obproxy": obproxy_config} if obproxy_config["obproxy_port"] == None: obcluster_config["db_port"] = 2883 + obcluster_config["db_host"] = obproxy_config["servers"]["nodes"][0]["ip"] else: obcluster_config["db_port"] = obproxy_config["obproxy_port"] + obcluster_config["db_host"] = obproxy_config["servers"]["nodes"][0]["ip"] else: config={"obcluster": obcluster_config} return config From 8b3efa15d2a1ffd04379040f48f57f789d5d678e Mon Sep 17 00:00:00 2001 From: xiaodong-ji Date: Thu, 19 Jun 2025 00:37:25 +0800 Subject: [PATCH 4/7] fix out context --- plugins/oceanbase-diagnostic-tool/1.0/diag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/oceanbase-diagnostic-tool/1.0/diag.py b/plugins/oceanbase-diagnostic-tool/1.0/diag.py index d5f845c2..7b069cba 100644 --- a/plugins/oceanbase-diagnostic-tool/1.0/diag.py +++ b/plugins/oceanbase-diagnostic-tool/1.0/diag.py @@ -47,7 +47,7 @@ def local_execute_command(command, env=None, timeout=None): fixed_output = re.sub( r'Usage: /.*?/obdiag', 'Usage: obd obdiag', - ret.stdout + fixed_output ) fixed_output = re.sub( r'()(\s+\[options\])', From 2b900c87e769f856b109ca911e0a8df182829d47 Mon Sep 17 00:00:00 2001 From: xiaodong-ji Date: Thu, 19 Jun 2025 03:27:59 +0800 Subject: [PATCH 5/7] fix diag plugin --- plugins/oceanbase-diagnostic-tool/1.0/diag.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/oceanbase-diagnostic-tool/1.0/diag.py b/plugins/oceanbase-diagnostic-tool/1.0/diag.py index 7b069cba..40f55e2e 100644 --- a/plugins/oceanbase-diagnostic-tool/1.0/diag.py +++ b/plugins/oceanbase-diagnostic-tool/1.0/diag.py @@ -28,12 +28,14 @@ def local_execute_command(command, env=None, timeout=None): exec_command = r"{install_dir}/{cmd}".format(install_dir=obdiag_install_dir, cmd=command) return LocalClient.execute_command(exec_command, env, timeout, stdio) + stdio.start_loading('obdiag working') ret = local_execute_command(f'{obdiag_bin} {" ".join(kwargs["full_cmd"])}') + stdio.stop_loading('obdiag working') if not ret: stdio.error(err.EC_OBDIAG_NOT_FOUND.format()) return plugin_context.return_false() - fixed_output= "" + fixed_output = ret.stdout if kwargs["full_cmd"][-1] == "list": command_to_replace = kwargs["full_cmd"][0] pattern = rf'(\s*)obdiag\s+{re.escape(command_to_replace)}(\s|$)' From ad16d377468bc739a9aafbbd455c9f8ecb156a23 Mon Sep 17 00:00:00 2001 From: xiaodong-ji Date: Thu, 19 Jun 2025 03:41:49 +0800 Subject: [PATCH 6/7] add auto install diag tool --- core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core.py b/core.py index 840a7122..32358283 100644 --- a/core.py +++ b/core.py @@ -4791,6 +4791,8 @@ def obdiag_func(self, args, deploy_name): return self.run_workflow(workflows, deploy_config.components, [repository], **{const.COMP_OCEANBASE_DIAGNOSTIC_TOOL: {"full_cmd": args, "deploy_config": deploy_config}}) else: self._call_stdio('error', err.EC_OBDIAG_NOT_FOUND.format()) + self._call_stdio('warn', '%s tool installation begins' % tool_name) + self.install_tool(tool_name) return False def obdiag_deploy(self, fuction_type): From 873e08960b5fefd0669cea2d5d67cee2ade0ada8 Mon Sep 17 00:00:00 2001 From: xiaodong-ji Date: Fri, 20 Jun 2025 22:22:13 +0800 Subject: [PATCH 7/7] replace get_server_conf with get_server_conf_with_default --- .../3.2.0/generate_config.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py b/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py index 8c71bb80..560b6cb4 100644 --- a/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py +++ b/plugins/oceanbase-diagnostic-tool/3.2.0/generate_config.py @@ -65,8 +65,8 @@ def get_obdiag_config(): nodeItem["ssh_username"] = parse_empty(user_config.username) nodeItem["ssh_password"] = parse_empty(user_config.password) nodeItem["private_key"] = parse_empty(user_config.key_file) - server_config = obproxy.get_server_conf(server) - obproxy_config["obproxy_port"] = server_config.get("listen_port") + server_config = obproxy.get_server_conf_with_default(server) + obproxy_config["obproxy_port"] = server_config.get("listen_port", 2883) nodeItem["home_path"] = server_config.get("home_path") obproxy_nodes.append(nodeItem) obproxy_config["servers"] = {"nodes": obproxy_nodes, "global": {}} @@ -99,12 +99,8 @@ def get_obdiag_config(): obcluster_config["servers"] = {"nodes": observer_nodes, "global": {}} if len(obproxy_nodes) > 0: config={"obcluster": obcluster_config, "obproxy": obproxy_config} - if obproxy_config["obproxy_port"] == None: - obcluster_config["db_port"] = 2883 - obcluster_config["db_host"] = obproxy_config["servers"]["nodes"][0]["ip"] - else: - obcluster_config["db_port"] = obproxy_config["obproxy_port"] - obcluster_config["db_host"] = obproxy_config["servers"]["nodes"][0]["ip"] + obcluster_config["db_port"] = obproxy_config["obproxy_port"] + obcluster_config["db_host"] = obproxy_config["servers"]["nodes"][0]["ip"] else: config={"obcluster": obcluster_config} return config