Skip to content

Commit

Permalink
input_marameters supports input in kv format
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodong-ji committed Aug 9, 2024
1 parent cad1f70 commit 1503cba
Show file tree
Hide file tree
Showing 21 changed files with 529 additions and 15 deletions.
3 changes: 2 additions & 1 deletion context.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def return_false(self, *args, **kwargs):

class HandlerContext(object):

def __init__(self, handler_name=None, namespace=None, namespaces=None, cluster_config=None, obproxy_config=None, ocp_config=None, inner_config=None, cmd=None, options=None, stdio=None):
def __init__(self, handler_name=None, namespace=None, namespaces=None, cluster_config=None, obproxy_config=None, ocp_config=None, inner_config=None, cmd=None, options=None, stdio=None, rca_scene_parameters=None):
self.namespace = HandlerContextNamespace(namespace)
self.namespaces = namespaces
self.handler_name = handler_name
Expand All @@ -113,6 +113,7 @@ def __init__(self, handler_name=None, namespace=None, namespaces=None, cluster_c
self.cmds = cmd
self.options = options
self.stdio = stdio
self.rca_scene_parameters = rca_scene_parameters
self._return = HandlerReturn()

def get_return(self, handler_name=None, spacename=None):
Expand Down
4 changes: 3 additions & 1 deletion core.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

class ObdiagHome(object):

def __init__(self, stdio=None, config_path=os.path.expanduser('~/.obdiag/config.yml'), inner_config_change_map=None):
def __init__(self, stdio=None, config_path=os.path.expanduser('~/.obdiag/config.yml'), inner_config_change_map=None, scene_input_param_map=None):
self._optimize_manager = None
self.stdio = None
self._stdio_func = None
Expand All @@ -71,6 +71,7 @@ def __init__(self, stdio=None, config_path=os.path.expanduser('~/.obdiag/config.
self.namespaces = {}
self.set_stdio(stdio)
self.context = None
self.rca_scene_parameters = scene_input_param_map
self.inner_config_manager = InnerConfigManager(stdio=stdio, inner_config_change_map=inner_config_change_map)
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"))
Expand Down Expand Up @@ -128,6 +129,7 @@ def set_context(self, handler_name, namespace, config):
options=self.options,
stdio=self.stdio,
inner_config=self.inner_config_manager.config,
rca_scene_parameters=self.rca_scene_parameters,
)
telemetry.set_cluster_conn(config.get_ob_cluster_config)

Expand Down
58 changes: 56 additions & 2 deletions diag_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import sys
import textwrap
import re
import json
from uuid import uuid1 as uuid, UUID
from optparse import OptionParser, BadOptionError, Option, IndentedHelpFormatter
from core import ObdiagHome
Expand Down Expand Up @@ -262,7 +263,7 @@ def do_command(self):
else:
ROOT_IO.error('The option you provided with -c: {0} is a non-existent configuration file path.'.format(custom_config))
return
obdiag = ObdiagHome(stdio=ROOT_IO, config_path=config_path, inner_config_change_map=self.inner_config_change_map)
obdiag = ObdiagHome(stdio=ROOT_IO, config_path=config_path, inner_config_change_map=self.inner_config_change_map, scene_input_param_map=self.scene_input_param_map)
obdiag.set_options(self.opts)
obdiag.set_cmds(self.cmds)
ret = self._do_command(obdiag)
Expand Down Expand Up @@ -867,8 +868,61 @@ def __init__(self):
super(ObdiagRCARunCommand, self).__init__('run', 'root cause analysis')
self.parser.add_option('--scene', type='string', help="rca scene name. The argument is required.")
self.parser.add_option('--store_dir', type='string', help='the dir to store rca result, current dir by default.', default='./rca/')
self.parser.add_option('--input_parameters', type='string', help='input parameters of scene')
self.parser.add_option('--input_parameters', action='callback', type='string', callback=self._input_parameters_scene, help='input parameters of scene')
self.parser.add_option('-c', type='string', help='obdiag custom config', default=os.path.expanduser('~/.obdiag/config.yml'))
self.scene_input_param_map = {}

def _input_parameters_scene(self, option, opt_str, value, parser):
"""
input parameters of scene
"""
try:
# input_parameters option is json format
try:
self.scene_input_param_map = json.loads(value)
return
except Exception as e:
# raise Exception("Failed to parse input_parameters. Please check the option is json:{0}".format(value))
ROOT_IO.warn(f"input_parameters option {value} is not json.")

# input_parameters option is key=val format
key, val = value.split('=')
if key is None or key == "":
return
m = self._input_parameters_scene_set(key, val)

def _scene_input_param(param_map, scene_param_map):
for scene_param_map_key, scene_param_map_value in scene_param_map.items():
if scene_param_map_key in param_map:
if isinstance(scene_param_map_value, dict):
_scene_input_param(param_map[scene_param_map_key], scene_param_map_value)
else:
param_map[scene_param_map_key] = scene_param_map_value
else:
param_map[scene_param_map_key] = scene_param_map_value
return param_map

self.scene_input_param_map = _scene_input_param(self.scene_input_param_map, m)
except Exception as e:
raise Exception("Key or val ({1}) is illegal: {0}".format(e, value))

def _input_parameters_scene_set(self, key, val):
def recursion(param_map, key, val):
if key is None or key == "":
raise Exception("key is None")
if val is None or val == "":
raise Exception("val is None")
if key.startswith(".") or key.endswith("."):
raise Exception("Key starts or ends '.'")
if "." in key:
map_key = key.split(".")[0]
param_map[map_key] = recursion({}, key[len(map_key) + 1 :], val)
return param_map
else:
param_map[key] = val
return param_map

return recursion({}, key, val)

def init(self, cmd, args):
super(ObdiagRCARunCommand, self).init(cmd, args)
Expand Down
11 changes: 1 addition & 10 deletions handler/rca/rca_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def __init__(self, context):
all_scenes_info, all_scenes_item = rca_list.get_all_scenes()
self.context.set_variable("rca_deep_limit", len(all_scenes_info))
self.all_scenes = all_scenes_item
self.rca_scene_parameters = None
self.rca_scene = None
self.cluster = self.context.get_variable("ob_cluster")
self.nodes = self.context.get_variable("observer_nodes")
Expand All @@ -122,15 +121,7 @@ def __init__(self, context):
# init input parameters
self.report = None
self.tasks = None
rca_scene_parameters = Util.get_option(self.options, "input_parameters", "")
if rca_scene_parameters != "":
try:
rca_scene_parameters = json.loads(rca_scene_parameters)
except Exception as e:
raise Exception("Failed to parse input_parameters. Please check the option is json:{0}".format(rca_scene_parameters))
else:
rca_scene_parameters = {}
self.context.set_variable("input_parameters", rca_scene_parameters)
self.context.set_variable("input_parameters", self.context.rca_scene_parameters)
self.store_dir = Util.get_option(self.options, "store_dir", "./rca/")
self.context.set_variable("store_dir", self.store_dir)
self.stdio.verbose(
Expand Down
6 changes: 5 additions & 1 deletion handler/rca/scene/ddl_disk_full_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ def execute(self):
## if the action is add_index
sql = "select table_id from oceanbase.__all_virtual_table_history where tenant_id = '{0}' and data_table_id = '{1}' and table_name like '%{2}%';".format(self.tenant_id, self.table_id, self.index_name)
self.verbose("execute_sql is {0}".format(sql))
self.index_table_id = self.ob_connector.execute_sql_return_cursor_dictionary(sql).fetchall()[0]["table_id"]
sql_tables_data = self.ob_connector.execute_sql_return_cursor_dictionary(sql).fetchall()
if len(sql_tables_data) == 0:
self.stdio.error("can not find index table id by index name: {0}. Please check the index name.".format(self.index_name))
return
self.index_table_id = sql_tables_data[0]["table_id"]
self.verbose("index_table_id is {0}".format(self.index_table_id))
self.record.add_record("index_table_id is {0}".format(self.index_table_id))

Expand Down
14 changes: 14 additions & 0 deletions rca/obdiag_ddl_disk_full_20240808214810/record
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
+--------------------------------------------------------------------------------------------------+
| record |
+------+-------------------------------------------------------------------------------------------+
| step | info |
+------+-------------------------------------------------------------------------------------------+
| 1 | table_id is 500002 |
| 2 | tenant_id is 1002 |
| 3 | on 192.168.119.104:2882 tablet_size: 339 as 339.00 B |
| 4 | estimated_size is [{'svr_ip': '192.168.119.104', 'svr_port': 2882, 'estimated_data_size': |
| | Decimal('339')}] |
| 5 | index_name is k2 |
| 6 | action_type is add_index |
+------+-------------------------------------------------------------------------------------------+
The suggest:
14 changes: 14 additions & 0 deletions rca/obdiag_ddl_disk_full_20240808230040/record
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
+--------------------------------------------------------------------------------------------------+
| record |
+------+-------------------------------------------------------------------------------------------+
| step | info |
+------+-------------------------------------------------------------------------------------------+
| 1 | table_id is 500002 |
| 2 | tenant_id is 1002 |
| 3 | on 192.168.119.104:2882 tablet_size: 339 as 339.00 B |
| 4 | estimated_size is [{'svr_ip': '192.168.119.104', 'svr_port': 2882, 'estimated_data_size': |
| | Decimal('339')}] |
| 5 | index_name is k2 |
| 6 | action_type is add_index |
+------+-------------------------------------------------------------------------------------------+
The suggest:
31 changes: 31 additions & 0 deletions rca/obdiag_ddl_disk_full_20240809022732/record
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
+-----------------------------------------------------------------------------------------------------------+
| record |
+------+----------------------------------------------------------------------------------------------------+
| step | info |
+------+----------------------------------------------------------------------------------------------------+
| 1 | table_id is 500002 |
| 2 | tenant_id is 1002 |
| 3 | on 192.168.119.104:2882 tablet_size: 678 as 678.00 B |
| 4 | estimated_size is [{'svr_ip': '192.168.119.104', 'svr_port': 2882, 'estimated_data_size': |
| | Decimal('678')}] |
| 5 | index_name is k1 |
| 6 | action_type is add_index |
| 7 | index_table_id is 500003 |
| 8 | main_table_sum_of_data_length is 100 |
| 9 | index_table_sum_of_data_length is 0 |
| 10 | estimated_index_size without magnification 0B as 0B from: |
| | index_table_sum_of_data_length(0)/main_table_sum_of_data_length(100) * estimated_data_size(678) |
| 11 | magnification is 5.5 |
| 12 | estimated_index_size with magnification is 0B as 0B |
| 13 | On target_server_ip is 192.168.119.104, target_server_port is 2882, estimiated_index_size is 0B as |
| | 0B |
| 14 | On target_serveris 192.168.119.104:2882 |
| 15 | target_server_estimated_size is 0B as 0B |
| 16 | target_server_total_size is 21474836480B as 20.00 GB |
| 17 | target_server_used_size is 339738624B as 324.00 MB |
| 18 | data_disk_usage_limit_percentage is 90 |
| 19 | available_disk_space is 18987614208B as 17.68 GB |
| 20 | available_disk_space - target_server_estimated_size is 18987614208B as 17.68 GB |
+------+----------------------------------------------------------------------------------------------------+
The suggest: the disk space of server(192.168.119.104:2882) is enough. Don't warn. If there are still errors, please contact the OceanBase community.

31 changes: 31 additions & 0 deletions rca/obdiag_ddl_disk_full_20240809022752/record
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
+-----------------------------------------------------------------------------------------------------------+
| record |
+------+----------------------------------------------------------------------------------------------------+
| step | info |
+------+----------------------------------------------------------------------------------------------------+
| 1 | table_id is 500002 |
| 2 | tenant_id is 1002 |
| 3 | on 192.168.119.104:2882 tablet_size: 678 as 678.00 B |
| 4 | estimated_size is [{'svr_ip': '192.168.119.104', 'svr_port': 2882, 'estimated_data_size': |
| | Decimal('678')}] |
| 5 | index_name is k1 |
| 6 | action_type is add_index |
| 7 | index_table_id is 500003 |
| 8 | main_table_sum_of_data_length is 100 |
| 9 | index_table_sum_of_data_length is 0 |
| 10 | estimated_index_size without magnification 0B as 0B from: |
| | index_table_sum_of_data_length(0)/main_table_sum_of_data_length(100) * estimated_data_size(678) |
| 11 | magnification is 5.5 |
| 12 | estimated_index_size with magnification is 0B as 0B |
| 13 | On target_server_ip is 192.168.119.104, target_server_port is 2882, estimiated_index_size is 0B as |
| | 0B |
| 14 | On target_serveris 192.168.119.104:2882 |
| 15 | target_server_estimated_size is 0B as 0B |
| 16 | target_server_total_size is 21474836480B as 20.00 GB |
| 17 | target_server_used_size is 339738624B as 324.00 MB |
| 18 | data_disk_usage_limit_percentage is 90 |
| 19 | available_disk_space is 18987614208B as 17.68 GB |
| 20 | available_disk_space - target_server_estimated_size is 18987614208B as 17.68 GB |
+------+----------------------------------------------------------------------------------------------------+
The suggest: the disk space of server(192.168.119.104:2882) is enough. Don't warn. If there are still errors, please contact the OceanBase community.

Loading

0 comments on commit 1503cba

Please sign in to comment.