Skip to content

Add workflow for obdiag #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
26 changes: 25 additions & 1 deletion _cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import json
import glob
import datetime
import copy
from uuid import uuid1 as uuid, UUID
from optparse import OptionParser, BadOptionError, Option, IndentedHelpFormatter

Expand Down Expand Up @@ -173,6 +174,8 @@ def do_command(self):
raise NotImplementedError

def _show_help(self, *args, **kwargs):
if self.name == "obdiag":
return
ROOT_IO.print(self._mk_usage())
self.parser.exit(1)

Expand Down Expand Up @@ -1726,7 +1729,28 @@ def _do_command(self, obd):
return True


class ObdiagCommand(MajorCommand):
class ObdiagCommand(ObdCommand):

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

def _do_command(self, obd):
args = copy.copy(self.args)
for i in range(len(self.args)):
if isinstance(self.args[i], str) and (self.args[i].startswith('--') or self.args[i].startswith('-')):
if self.args[i] == "--help" or self.args[i] == "-h":
return obd.obdiag_func(self.args, None)
else:
args.remove(self.args[i-1])
return obd.obdiag_func(args, self.args[i-1])
if len(self.args) > 0:
args.remove(self.args[-1])
return obd.obdiag_func(args, self.args[-1])
else:
return self._show_help()


class ObdiagCommandBak(MajorCommand):

def __init__(self):
super(ObdiagCommand, self).__init__('obdiag', 'Oceanbase Diagnostic Tool')
Expand Down
2 changes: 1 addition & 1 deletion _errno.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class InitDirFailedErrorMessage(object):
EC_OBDIAG_NOT_FOUND = OBDErrorCodeTemplate(6000, 'Failed to executable obdiag command, you may not have obdiag installed')
EC_OBDIAG_NOT_CONTAIN_DEPEND_COMPONENT = OBDErrorCodeTemplate(6001, 'obdiag must contain depend components {components}')
EC_OBDIAG_OPTIONS_FORMAT_ERROR = OBDErrorCodeTemplate(6002, 'obdiag options {option} format error, please check the value : {value}')
EC_OBDIAG_FUCYION_FAILED = OBDErrorCodeTemplate(6003, 'Failed to execute obdiag function {fuction}')
EC_OBDIAG_FUNCTION_FAILED = OBDErrorCodeTemplate(6003, 'Failed to execute obdiag function {function}')

# Unexpected exceptions code
EC_UNEXPECTED_EXCEPTION = OBDErrorCodeTemplate(9999, 'Unexpected exception: need to be posted on "https://ask.oceanbase.com", and we will help you resolve them.')
Expand Down
3 changes: 3 additions & 0 deletions _plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ def _new_func(
kwargs = namespace_vars
if method:
target_servers = None
print("----------------------------------------------")
print(cluster_config)
print("----------------------------------------------")
if cluster_config:
servers = cluster_config.servers
target_servers = kwargs.get('target_servers')
Expand Down
35 changes: 33 additions & 2 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4457,7 +4457,7 @@ def obdiag_online_func(self, name, fuction_type, opts):
obdiag_plugin = self.plugin_manager.get_best_py_script_plugin(fuction_type, diagnostic_component_name, tool.config.version)
return self.call_plugin(obdiag_plugin, target_repository)
else:
self._call_stdio('error', err.EC_OBDIAG_FUCYION_FAILED.format(fuction=fuction_type))
self._call_stdio('error', err.EC_OBDIAG_FUNCTION_FAILED.format(function=fuction_type))
return False


Expand All @@ -4476,7 +4476,38 @@ def obdiag_offline_func(self, fuction_type, opts):
obdiag_plugin = self.plugin_manager.get_best_py_script_plugin(fuction_type, tool_name, repository.version)
return self.call_plugin(obdiag_plugin, repository, clients={})
else:
self._call_stdio('error', err.EC_OBDIAG_FUCYION_FAILED.format(fuction=fuction_type))
self._call_stdio('error', err.EC_OBDIAG_FUNCTION_FAILED.format(function=fuction_type))
return False

def obdiag_func(self, args, deploy_name):
tool_name = COMP_OCEANBASE_DIAGNOSTIC_TOOL
obdiag_config = Values()
setattr(obdiag_config, 'depends', [])
deploy_config = DeployConfig('', config_parser_manager=object())
if deploy_name:
self._global_ex_lock()
self._call_stdio('verbose', 'Get Deploy by name')
deploy = self.deploy_manager.get_deploy_config(deploy_name, read_only=True)
if not deploy:
self._call_stdio('error', 'No such deploy: %s.' % deploy_name)
return False
self.set_deploy(deploy)
self._call_stdio('verbose', 'Get deploy configuration')
deploy_config = deploy.deploy_config
deploy_config.components = {tool_name: obdiag_config}
workflow_name='diag'
pkg = self.mirror_manager.get_best_pkg(name=tool_name)
if not pkg:
self._call_stdio('critical', '%s package not found' % tool_name)
return False
repository = self.repository_manager.create_instance_repository(pkg.name, pkg.version, pkg.md5)
deployed = self.obdiag_deploy(workflow_name)
tool = self.tool_manager.get_tool_config_by_name(tool_name)
if deployed and tool:
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))
return False

def obdiag_deploy(self, fuction_type):
Expand Down
1 change: 1 addition & 0 deletions plugins/obproxy/3.1.0/3.1.0
1 change: 1 addition & 0 deletions plugins/obproxy/4.2.1/4.2.1
1 change: 1 addition & 0 deletions plugins/obproxy/4.2.3/4.2.3
1 change: 1 addition & 0 deletions plugins/obproxy/4.3.0/4.3.0
34 changes: 34 additions & 0 deletions plugins/oceanbase-diagnostic-tool/1.0/diag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# coding: utf-8
# Copyright (c) 2025 OceanBase.
#
# Licensed 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.

from __future__ import absolute_import, division, print_function
from ssh import LocalClient
import _errno as err


def diag(plugin_context, *args, **kwargs):
stdio = plugin_context.stdio
obdiag_install_dir=kwargs.get("repository").repository_dir
obdiag_bin = "obdiag"

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)

ret = local_execute_command(f'{obdiag_bin} {" ".join(kwargs["full_cmd"])}')
if not ret:
stdio.error(err.EC_OBDIAG_NOT_FOUND.format())
return plugin_context.return_false()
stdio.print(ret.stdout)
80 changes: 0 additions & 80 deletions plugins/oceanbase-diagnostic-tool/1.0/gather_all.py

This file was deleted.

76 changes: 0 additions & 76 deletions plugins/oceanbase-diagnostic-tool/1.0/gather_clog.py

This file was deleted.

Loading