Skip to content
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

2.4.0 silent print #388

Merged
merged 39 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
485ac87
update io: add stderr
wayyoungboy Jul 29, 2024
7595ea7
update io: add stderr
wayyoungboy Jul 29, 2024
6dcb146
add --inner_config
wayyoungboy Jul 30, 2024
0978a85
Merge remote-tracking branch 'refs/remotes/origin/master' into 2.4.0-…
wayyoungboy Jul 30, 2024
7d59f25
support remote_client_sudo
wayyoungboy Jul 30, 2024
454f803
build test package
wayyoungboy Jul 30, 2024
90697d9
fix --inner_config
wayyoungboy Jul 31, 2024
e2c2250
fix io stream
wayyoungboy Jul 31, 2024
15cca2c
test
wayyoungboy Aug 1, 2024
9789b87
test
wayyoungboy Aug 1, 2024
3e4cf73
test
wayyoungboy Aug 1, 2024
3e5ba94
test
wayyoungboy Aug 2, 2024
0f0ea77
test
wayyoungboy Aug 2, 2024
3329cbd
取消测试分支打包
wayyoungboy Aug 5, 2024
4785d96
test
wayyoungboy Aug 7, 2024
6848ba5
test
wayyoungboy Aug 7, 2024
7c1e546
test
wayyoungboy Aug 7, 2024
a74175a
test
wayyoungboy Aug 7, 2024
5a1b507
test
wayyoungboy Aug 9, 2024
8e251cf
add new io buffer
wayyoungboy Aug 12, 2024
39ce3a1
add new io buffer
wayyoungboy Aug 12, 2024
28c358c
Merge remote-tracking branch 'refs/remotes/origin/master' into 2.4.0-…
wayyoungboy Aug 12, 2024
6fd4148
Merge remote-tracking branch 'refs/remotes/origin/2.4.0-fix-get_obpro…
wayyoungboy Aug 13, 2024
769418f
build test package
wayyoungboy Aug 13, 2024
7ecfdcd
silent change
wayyoungboy Aug 13, 2024
ec8d4a8
delete init.sh cp gather dir more
wayyoungboy Aug 13, 2024
3d36734
Merge remote-tracking branch 'refs/remotes/origin/master' into 2.4.0-…
wayyoungboy Aug 13, 2024
8fc9a51
update
wayyoungboy Aug 14, 2024
93a7e4f
update
wayyoungboy Aug 14, 2024
79accd8
update
wayyoungboy Aug 14, 2024
f645126
update
wayyoungboy Aug 14, 2024
dc4f61b
update
wayyoungboy Aug 14, 2024
9b7f1eb
update
wayyoungboy Aug 14, 2024
40d6cd2
update
wayyoungboy Aug 15, 2024
53dfb46
update
wayyoungboy Aug 16, 2024
8f6876f
fix some bug
wayyoungboy Aug 19, 2024
667ed18
delete build tag
wayyoungboy Aug 19, 2024
ef80ab3
delete silent note
wayyoungboy Aug 20, 2024
4521c72
code fix
wayyoungboy Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- master
- 2.4.0-silent-print
Teingi marked this conversation as resolved.
Show resolved Hide resolved

env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
Expand Down
16 changes: 8 additions & 8 deletions common/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ def get_obproxy_version(context):
obproxy_version_info = ssh_client.exec_cmd(cmd)
stdio.verbose("get obproxy version, run cmd = [{0}] ".format(cmd))
if obproxy_version_info is not None:
ob_version = re.findall(r'[(]OceanBase.(.+? +?)[)]', obproxy_version_info)
pattern = r"(\d+\.\d+\.\d+\.\d+)"
ob_version = re.findall(pattern, obproxy_version_info)
if len(ob_version) > 0:
return ob_version[0]
else:
Expand All @@ -295,7 +296,6 @@ def get_obproxy_version(context):
stdio.verbose("get obproxy version with LD_LIBRARY_PATH,cmd:{0}, result:{1}".format(cmd, obproxy_version_info))
if "REVISION" not in obproxy_version_info:
raise Exception("Please check conf about proxy,{0}".format(obproxy_version_info))
pattern = r"(\d+\.\d+\.\d+\.\d+)"
match = re.search(pattern, obproxy_version_info)
if match:
obproxy_version_info = match.group(1)
Expand Down Expand Up @@ -405,12 +405,12 @@ def is_empty_file(ssh_client, file_path, stdio=None):
return False


def get_obdiag_display(log_dir, trace_id, stdio=None):
cmd = 'grep -h "\[{}\]" {}* | sed "s/\[{}\] //g" '.format(trace_id, log_dir, trace_id)
stdout = LocalClient(stdio).run(cmd)
print_stdout = str(stdout).replace('\\n', '\n').replace('\\t', '\t')
if len(print_stdout) > 0:
print(print_stdout)
# def get_obdiag_display(log_dir, trace_id, stdio=None):
# cmd = 'grep -h "\[{}\]" {}* | sed "s/\[{}\] //g" '.format(trace_id, log_dir, trace_id)
# stdout = LocalClient(stdio).run(cmd)
# print_stdout = str(stdout).replace('\\n', '\n').replace('\\t', '\t')
# if len(print_stdout) > 0:
# print(print_stdout)


def uzip_dir_local(uzip_dir, stdio=None):
Expand Down
2 changes: 1 addition & 1 deletion common/config_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def build_configuration(self):
self.save_old_configuration(old_config)
# rewrite config
ob_cluster_name = self.get_cluster_name()
print("\033[33mPlease enter the following configuration !!!\033[0m")
self.stdio.print("\033[33mPlease enter the following configuration !!!\033[0m")
global_ssh_username = self.input_with_default("oceanbase host ssh username", "")
global_ssh_password = self.input_password_with_default("oceanbase host ssh password", "")
global_ssh_port = self.input_with_default("oceanbase host ssh_port", "22")
Expand Down
1 change: 0 additions & 1 deletion common/ssh_client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def progress_bar(self, transferred, to_be_transferred, suffix=''):
sys.stdout.write('Downloading [%s] %s%s%s %s %s\r' % (bar, '\033[32;1m%s\033[0m' % print_percents, '% [', self.translate_byte(transferred), ']', suffix))
if transferred == to_be_transferred:
sys.stdout.write('Downloading [%s] %s%s%s %s %s\r' % (bar, '\033[32;1m%s\033[0m' % print_percents, '% [', self.translate_byte(transferred), ']', suffix))
print()

def translate_byte(self, B):
if B < 0:
Expand Down
1 change: 0 additions & 1 deletion common/ssh_client/remote_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def progress_bar(self, transferred, to_be_transferred, suffix=''):
sys.stdout.write('Downloading [%s] %s%s%s %s %s\r' % (bar, '\033[32;1m%s\033[0m' % print_percents, '% [', self.translate_byte(transferred), ']', suffix))
if transferred == to_be_transferred:
sys.stdout.write('Downloading [%s] %s%s%s %s %s\r' % (bar, '\033[32;1m%s\033[0m' % print_percents, '% [', self.translate_byte(transferred), ']', suffix))
print()

def upload(self, remote_path, local_path):
transport = self._ssh_fd.get_transport()
Expand Down
16 changes: 8 additions & 8 deletions common/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,26 +1358,26 @@ def convert_to_number(s, stdio=None):
return s

@staticmethod
def print_scene(scene_dict, stdio=None):
def print_scene(scene_dict, stdio):
columns_to_print = ['command', 'info_en', 'info_cn']
keys = columns_to_print
table_data = [[value[key] for key in keys] for value in scene_dict.values()]
column_widths = [max(len(str(item)) * (StringUtils.is_chinese(item) or 1) for item in column) for column in zip(*table_data)]
table_data.insert(0, keys)
Util.print_line(length=sum(column_widths) + 5)
Util.print_line(length=sum(column_widths) + 5, stdio=stdio)
for i in range(len(table_data)):
print(Fore.GREEN + " ".join(f"{item:<{width}}" for item, width in zip(table_data[i], column_widths)) + Style.RESET_ALL)
stdio.print(Fore.GREEN + " ".join(f"{item:<{width}}" for item, width in zip(table_data[i], column_widths)) + Style.RESET_ALL)
if i == 0:
Util.print_line(length=sum(column_widths) + 5)
Util.print_line(length=sum(column_widths) + 5)
Util.print_line(length=sum(column_widths) + 5, stdio=stdio)
Util.print_line(length=sum(column_widths) + 5, stdio=stdio)

@staticmethod
def print_line(char='-', length=50, stdio=None):
print(char * length)
stdio.print(char * length)

@staticmethod
def print_title(name, stdio=None):
print("\n[{0}]:".format(name))
def print_title(name, stdio):
stdio.print("\n[{0}]:".format(name))

@staticmethod
def gen_password(length=8, chars=string.ascii_letters + string.digits, stdio=None):
Expand Down
1 change: 1 addition & 0 deletions conf/inner_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ obdiag:
mode: obdiag
stdout_handler_log_level: INFO
error_stream: sys.stdout
silent: false
ssh_client:
remote_client_sudo: 0
check:
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
'mode': 'obdiag',
'stdout_handler_log_level': 'INFO',
'error_stream': 'sys.stdout',
'silent': False,
},
'ssh_client': {
'remote_client_sudo': False,
Expand Down
68 changes: 42 additions & 26 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from handler.gather.gather_tabledump import GatherTableDumpHandler
from handler.gather.gather_parameters import GatherParametersHandler
from handler.gather.gather_variables import GatherVariablesHandler
from result_type import ObdiagResult
from telemetry.telemetry import telemetry
from update.update import UpdateHandler
from colorama import Fore, Style
Expand All @@ -72,10 +73,19 @@ def __init__(self, stdio=None, config_path=os.path.expanduser('~/.obdiag/config.
self.set_stdio(stdio)
self.context = None
self.inner_config_manager = InnerConfigManager(stdio=stdio, inner_config_change_map=inner_config_change_map)
# obdiag.logger.error_stream
if self.inner_config_manager.config.get("obdiag") is not None and self.inner_config_manager.config.get("obdiag").get("basic") is not None and self.inner_config_manager.config.get("obdiag").get("basic").get("print_type") is not None:
stdio.set_err_stream(self.inner_config_manager.config.get("obdiag").get("logger").get("error_stream"))

# obdiag.logger.silent
if self.inner_config_manager.config.get("obdiag") is not None and self.inner_config_manager.config.get("obdiag").get("logger") is not None and self.inner_config_manager.config.get("obdiag").get("logger").get("silent") is not None:
stdio.set_silent(self.inner_config_manager.config.get("obdiag").get("logger").get("silent"))
self.set_stdio(stdio)
if config_path:
if os.path.exists(os.path.abspath(config_path)):
config_path = config_path
else:
stdio.error('The option you provided with -c: {0} is not exist.'.format(config_path))
return
self.config_manager = ConfigManager(config_path, stdio)
if (
self.inner_config_manager.config.get("obdiag") is not None
Expand Down Expand Up @@ -191,7 +201,7 @@ def gather_function(self, function_type, opt):
config = self.config_manager
if not config:
self._call_stdio('error', 'No such custum config')
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='No such custum config')
else:
self.stdio.print("{0} start ...".format(function_type))
self.set_context(function_type, 'gather', config)
Expand Down Expand Up @@ -230,8 +240,7 @@ def gather_function(self, function_type, opt):
handler_log = GatherLogHandler(self.context)
handler_log.handle()
handler_obproxy = GatherObProxyLogHandler(self.context)
handler_obproxy.handle()
return True
return handler_obproxy.handle()
elif function_type == 'gather_sysstat':
handler = GatherOsInfoHandler(self.context)
return handler.handle()
Expand All @@ -252,13 +261,13 @@ def gather_function(self, function_type, opt):
return handler.handle()
else:
self._call_stdio('error', 'Not support gather function: {0}'.format(function_type))
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='Not support gather function: {0}'.format(function_type))

def gather_obproxy_log(self, opt):
config = self.config_manager
if not config:
self._call_stdio('error', 'No such custum config')
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='No such custum config')
else:
self.set_context_skip_cluster_conn('gather_obproxy_log', 'gather', config)
handler = GatherObProxyLogHandler(self.context)
Expand All @@ -273,33 +282,34 @@ def analyze_fuction(self, function_type, opt):
config = self.config_manager
if not config:
self._call_stdio('error', 'No such custum config')
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='No such custum config')
else:
self.stdio.print("{0} start ...".format(function_type))
if function_type == 'analyze_log':
self.set_context(function_type, 'analyze', config)
handler = AnalyzeLogHandler(self.context)
handler.handle()
return handler.handle()
elif function_type == 'analyze_log_offline':
self.set_context_skip_cluster_conn(function_type, 'analyze', config)
handler = AnalyzeLogHandler(self.context)
handler.handle()
return handler.handle()
elif function_type == 'analyze_flt_trace':
self.set_context(function_type, 'analyze', config)
handler = AnalyzeFltTraceHandler(self.context)
handler.handle()
return handler.handle()
elif function_type == 'analyze_parameter_default':
self.set_context(function_type, 'analyze', config)
handler = AnalyzeParameterHandler(self.context, 'default')
handler.handle()
return handler.handle()
elif function_type == 'analyze_parameter_diff':
self.set_context_skip_cluster_conn(function_type, 'analyze', config)
handler = AnalyzeParameterHandler(self.context, 'diff')
handler.handle()
return handler.handle()
elif function_type == 'analyze_variable_diff':
self.set_context(function_type, 'analyze', config)
handler = AnalyzeVariableHandler(self.context, 'diff')
handler.handle()
return handler.handle()
# todo not support silent
elif function_type == 'analyze_sql':
self.set_context(function_type, 'analyze', config)
handler = AnalyzeSQLHandler(self.context)
Expand All @@ -310,26 +320,29 @@ def analyze_fuction(self, function_type, opt):
handler.handle()
else:
self._call_stdio('error', 'Not support analyze function: {0}'.format(function_type))
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='Not support analyze function: {0}'.format(function_type))

def check(self, opts):
config = self.config_manager
if not config:
self._call_stdio('error', 'No such custum config')
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='No such custum config')
else:
self.stdio.print("check start ...")
self.set_context('check', 'check', config)
obproxy_check_handler = None
observer_check_handler = None
result_data = {}
if self.context.obproxy_config.get("servers") is not None and len(self.context.obproxy_config.get("servers")) > 0:
obproxy_check_handler = CheckHandler(self.context, check_target_type="obproxy")
obproxy_check_handler.handle()
obproxy_check_handler.execute()
obproxy_result = obproxy_check_handler.execute()
result_data['obproxy'] = obproxy_result
if self.context.cluster_config.get("servers") is not None and len(self.context.cluster_config.get("servers")) > 0:
observer_check_handler = CheckHandler(self.context, check_target_type="observer")
observer_check_handler.handle()
observer_check_handler.execute()
observer_result = observer_check_handler.execute()
result_data['observer'] = observer_result
if obproxy_check_handler is not None:
obproxy_report_path = os.path.expanduser(obproxy_check_handler.report.get_report_path())
if os.path.exists(obproxy_report_path):
Expand All @@ -338,59 +351,62 @@ def check(self, opts):
observer_report_path = os.path.expanduser(observer_check_handler.report.get_report_path())
if os.path.exists(observer_report_path):
self.stdio.print("Check observer finished. For more details, please run cmd'" + Fore.YELLOW + " cat {0} ".format(observer_check_handler.report.get_report_path()) + Style.RESET_ALL + "'")
return ObdiagResult(ObdiagResult.SUCCESS_CODE, data=result_data)

def check_list(self, opts):
config = self.config_manager
if not config:
self._call_stdio('error', 'No such custum config')
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='No such custum config')
else:
self.set_offline_context('check_list', 'check_list')
handler = CheckListHandler(self.context)
handler.handle()
return handler.handle()

def rca_run(self, opts):
config = self.config_manager
if not config:
self._call_stdio('error', 'No such custum config')
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='No such custum config')
else:
self.set_context('rca_run', 'rca_run', config)
try:
handler = RCAHandler(self.context)
handler.handle()
handler.execute()
return handler.execute()
except Exception as e:
self.stdio.error("rca run Exception: {0}".format(e))
self.stdio.verbose(traceback.format_exc())
return ObdiagResult(ObdiagResult.SERVER_ERROR_CODE, error_data="rca run Exception: {0}".format(e))

def rca_list(self, opts):
config = self.config_manager
if not config:
self._call_stdio('error', 'No such custum config')
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='No such custum config')
else:
self.set_offline_context('rca_list', 'rca_list')
handler = RcaScenesListHandler(context=self.context)
handler.handle()
return handler.handle()

def update(self, opts):
config = self.config_manager
if not config:
self._call_stdio('error', 'No such custum config')
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='No such custum config')
else:
self.stdio.print("update start ...")
self.set_offline_context('update', 'update')
handler = UpdateHandler(self.context)
handler.execute()
return handler.execute()

def config(self, opt):
config = self.config_manager
if not config:
self._call_stdio('error', 'No such custum config')
return False
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='No such custum config')
else:
self.set_offline_context('config', 'config')
config_helper = ConfigHelper(context=self.context)
config_helper.build_configuration()
return ObdiagResult(ObdiagResult.SUCCESS_CODE, data={"msg": "config success"})
Loading
Loading