Skip to content

Commit e89e482

Browse files
authored
Add workflow for obdiag (#216)
* add workflow for obdiag rca list * obdiag workflow begin start * obdiag command transparent transmission * review fix * remove old file * add file_map.yaml for obdiag 3.2.0 * git remove file_map * fix obdiag plugin cmd options * update workflow for obdiag * test * add ob-ce components * add help option in generate_config * fix generate_config * fix bugs
1 parent 5913010 commit e89e482

29 files changed

+255
-1544
lines changed

_cmd.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import json
2424
import glob
2525
import datetime
26+
import copy
2627
from uuid import uuid1 as uuid, UUID
2728
from optparse import OptionParser, BadOptionError, Option, IndentedHelpFormatter
2829

@@ -187,6 +188,8 @@ def do_command(self):
187188
raise NotImplementedError
188189

189190
def _show_help(self, *args, **kwargs):
191+
if self.name == "obdiag":
192+
return
190193
ROOT_IO.print(self._mk_usage())
191194
self.parser.exit(1)
192195

@@ -1964,7 +1967,28 @@ def _do_command(self, obd):
19641967
return True
19651968

19661969

1967-
class ObdiagCommand(MajorCommand):
1970+
class ObdiagCommand(ObdCommand):
1971+
1972+
def __init__(self):
1973+
super(ObdiagCommand, self).__init__('obdiag', 'Oceanbase Diagnostic Tool')
1974+
1975+
def _do_command(self, obd):
1976+
args = copy.copy(self.args)
1977+
for i in range(len(self.args)):
1978+
if isinstance(self.args[i], str) and (self.args[i].startswith('--') or self.args[i].startswith('-')):
1979+
if self.args[i] == "--help" or self.args[i] == "-h":
1980+
return obd.obdiag_func(self.args, None)
1981+
else:
1982+
args.remove(self.args[i-1])
1983+
return obd.obdiag_func(args, self.args[i-1])
1984+
if len(self.args) > 0:
1985+
args.remove(self.args[-1])
1986+
return obd.obdiag_func(args, self.args[-1])
1987+
else:
1988+
return self._show_help()
1989+
1990+
1991+
class ObdiagCommandBak(MajorCommand):
19681992

19691993
def __init__(self):
19701994
super(ObdiagCommand, self).__init__('obdiag', 'Oceanbase Diagnostic Tool')

_errno.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class InitDirFailedErrorMessage(object):
263263
EC_OBDIAG_NOT_FOUND = OBDErrorCodeTemplate(6000, 'Failed to executable obdiag command, you may not have obdiag installed')
264264
EC_OBDIAG_NOT_CONTAIN_DEPEND_COMPONENT = OBDErrorCodeTemplate(6001, 'obdiag must contain depend components {components}')
265265
EC_OBDIAG_OPTIONS_FORMAT_ERROR = OBDErrorCodeTemplate(6002, 'obdiag options {option} format error, please check the value : {value}')
266-
EC_OBDIAG_FUCYION_FAILED = OBDErrorCodeTemplate(6003, 'Failed to execute obdiag function {fuction}')
266+
EC_OBDIAG_FUNCTION_FAILED = OBDErrorCodeTemplate(6003, 'Failed to execute obdiag function {function}')
267267

268268
# obshell
269269
EC_OBSHELL_GENERAL_ERROR = OBDErrorCodeTemplate(6100, 'OBSHELL: {msg}')

core.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4730,7 +4730,7 @@ def obdiag_online_func(self, name, fuction_type, opts):
47304730
obdiag_plugin = self.plugin_manager.get_best_py_script_plugin(fuction_type, diagnostic_component_name, tool.config.version)
47314731
return self.call_plugin(obdiag_plugin, target_repository)
47324732
else:
4733-
self._call_stdio('error', err.EC_OBDIAG_FUCYION_FAILED.format(fuction=fuction_type))
4733+
self._call_stdio('error', err.EC_OBDIAG_FUNCTION_FAILED.format(function=fuction_type))
47344734
return False
47354735

47364736

@@ -4749,7 +4749,48 @@ def obdiag_offline_func(self, fuction_type, opts):
47494749
obdiag_plugin = self.plugin_manager.get_best_py_script_plugin(fuction_type, tool_name, repository.version)
47504750
return self.call_plugin(obdiag_plugin, repository, clients={})
47514751
else:
4752-
self._call_stdio('error', err.EC_OBDIAG_FUCYION_FAILED.format(fuction=fuction_type))
4752+
self._call_stdio('error', err.EC_OBDIAG_FUNCTION_FAILED.format(function=fuction_type))
4753+
return False
4754+
4755+
def obdiag_func(self, args, deploy_name):
4756+
tool_name = COMP_OCEANBASE_DIAGNOSTIC_TOOL
4757+
deploy_config = DeployConfig('', config_parser_manager=object())
4758+
if deploy_name:
4759+
self._global_ex_lock()
4760+
self._call_stdio('verbose', 'Get Deploy by name')
4761+
deploy = self.deploy_manager.get_deploy_config(deploy_name, read_only=True)
4762+
if not deploy:
4763+
self._call_stdio('error', 'No such deploy: %s.' % deploy_name)
4764+
return False
4765+
self.set_deploy(deploy)
4766+
self._call_stdio('verbose', 'Get deploy configuration')
4767+
deploy_config = deploy.deploy_config
4768+
allow_components = const.COMPS_OB
4769+
component_name = ""
4770+
for component in deploy_config.components:
4771+
if component in allow_components:
4772+
component_name = component
4773+
break
4774+
if component_name == "":
4775+
self._call_stdio('error', err.EC_OBDIAG_NOT_CONTAIN_DEPEND_COMPONENT.format(components=allow_components))
4776+
return False
4777+
cluster_config = deploy_config.components[component_name]
4778+
deploy_config.components = {tool_name: cluster_config}
4779+
4780+
workflow_name='diag'
4781+
pkg = self.mirror_manager.get_best_pkg(name=tool_name)
4782+
if not pkg:
4783+
self._call_stdio('critical', '%s package not found' % tool_name)
4784+
return False
4785+
repository = self.repository_manager.create_instance_repository(pkg.name, pkg.version, pkg.md5)
4786+
deployed = self.obdiag_deploy(workflow_name)
4787+
tool = self.tool_manager.get_tool_config_by_name(tool_name)
4788+
if deployed and tool:
4789+
self.repositories = [repository]
4790+
workflows = self.get_workflows(workflow_name, [repository])
4791+
return self.run_workflow(workflows, deploy_config.components, [repository], **{const.COMP_OCEANBASE_DIAGNOSTIC_TOOL: {"full_cmd": args, "deploy_config": deploy_config}})
4792+
else:
4793+
self._call_stdio('error', err.EC_OBDIAG_FUNCTION_FAILED.format(function=workflow_name))
47534794
return False
47544795

47554796
def obdiag_deploy(self, fuction_type):
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# coding: utf-8
2+
# Copyright (c) 2025 OceanBase.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from __future__ import absolute_import, division, print_function
17+
from ssh import LocalClient
18+
import _errno as err
19+
20+
21+
def diag(plugin_context, *args, **kwargs):
22+
stdio = plugin_context.stdio
23+
obdiag_install_dir=kwargs.get("repository").repository_dir
24+
obdiag_bin = "obdiag"
25+
26+
def local_execute_command(command, env=None, timeout=None):
27+
exec_command = r"{install_dir}/{cmd}".format(install_dir=obdiag_install_dir, cmd=command)
28+
return LocalClient.execute_command(exec_command, env, timeout, stdio)
29+
30+
ret = local_execute_command(f'{obdiag_bin} {" ".join(kwargs["full_cmd"])}')
31+
if not ret:
32+
stdio.error(err.EC_OBDIAG_NOT_FOUND.format())
33+
return plugin_context.return_false()
34+
stdio.print(ret.stdout)

plugins/oceanbase-diagnostic-tool/1.0/gather_all.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

plugins/oceanbase-diagnostic-tool/1.0/gather_clog.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

plugins/oceanbase-diagnostic-tool/1.0/gather_log.py

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)