Skip to content

Commit

Permalink
fix(logcollection): save schema info output
Browse files Browse the repository at this point in the history
This commit brings the few fixes:
1. save schema info on the runner locally and collect it in SCT folder
2. use silence decorator for every run of schema info command. It's
to prevent stop info collection on failure
3. collect schema info from one live node
  • Loading branch information
juliayakovlev committed Dec 12, 2024
1 parent 246f303 commit 23ecadd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
6 changes: 0 additions & 6 deletions sdcm/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,6 @@ def __init__(self, name, parent_cluster, ssh_login_info=None, base_logdir=None,
self._node_rack = None
self._is_zero_token_node = False

def save_cqlsh_output_in_file(self, cmd: str, log_file: str):
self.log.info("Save command '%s' output in the file. Node %s", cmd, self.name)
result_tables = self.run_cqlsh(cmd, split=True)
for line in result_tables:
self.remoter.run(f"echo '{line}' >> {log_file}")

def _is_node_ready_run_scylla_commands(self) -> bool:
"""
When node is just created and started to configure, during first node initializing, it is impossible to connect to the node yet and
Expand Down
11 changes: 6 additions & 5 deletions sdcm/logcollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ def collect_logs_per_node(node):
try:
log_entity.collect(node, local_node_dir, remote_node_dir, local_search_path=local_search_path)
except Exception as details: # pylint: disable=unused-variable, broad-except # noqa: BLE001
LOGGER.error("Error occured during collecting on host: %s\n%s", node.name, details)
LOGGER.error("Error occured during collecting of %s on host: %s\n%s",
log_entity.name, node.name, details)

LOGGER.debug("Nodes list %s", [node.name for node in self.nodes])

Expand Down Expand Up @@ -749,10 +750,6 @@ class ScyllaLogCollector(LogCollector):
command='cat /var/log/cloud-init-output.log'),
CommandLog(name='cloud-init.log',
command='cat /var/log/cloud-init.log'),
CommandLog(name='schema.log',
command='cat schema.log'),
CommandLog(name='system_schema_tables.log',
command='cat system_schema_tables.log'),
]

cmd = "test -f /etc/scylla/ssl_conf/{0} && cat /etc/scylla/ssl_conf/{0}"
Expand Down Expand Up @@ -954,6 +951,10 @@ class BaseSCTLogCollector(LogCollector):
search_locally=True),
FileLog(name='junit.xml',
search_locally=True),
FileLog(name='schema.log',
search_locally=True),
FileLog(name='system_schema_tables.log',
search_locally=True),
]
cluster_log_type = 'sct-runner-events'
cluster_dir_prefix = 'sct-runner-events'
Expand Down
31 changes: 26 additions & 5 deletions sdcm/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2961,16 +2961,37 @@ def clean_resources(self):

self.destroy_credentials()

@silence(name='Save node schema')
def save_cqlsh_output_in_file(self, node, cmd: str, log_file: str):
self.log.info("Save command '%s' output in the file. Node %s", cmd, node.name)
log_file_path = Path(self.logdir) / log_file
self.log.debug("Schema file path: %s", log_file_path)
if not (result := node.run_cqlsh(cmd).stdout):
return

with open(log_file_path, "w", encoding="utf-8") as res_file:
res_file.write(result.strip())

def save_nodes_schema(self):
if self.db_cluster is None:
self.log.info("No nodes found in the Scylla cluster")
self.log.error("Didn't find the nodes in the cluster for saving the schema.")
return

self.log.info("Save nodes user schema in the files")
# Collect schema info from one node only. Not need to collect from every node
found_live_node = False
for node in self.db_cluster.nodes:
node.save_cqlsh_output_in_file(cmd="desc schema", log_file="schema.log")
node.save_cqlsh_output_in_file(cmd="select JSON * from system_schema.tables",
log_file="system_schema_tables.log")
if not node._is_node_ready_run_scylla_commands():
continue
found_live_node = True
with silence(name=f"Save node '{node.name}' schema", raise_error_event=False):
self.save_cqlsh_output_in_file(node=node, cmd="desc schema", log_file="schema.log")
with silence(name=f"Save node '{node.name}' system_schema.tables", raise_error_event=False):
self.save_cqlsh_output_in_file(
node=node, cmd="select JSON * from system_schema.tables", log_file="system_schema_tables.log")
break

if not found_live_node:
self.log.error("Didn't find any live node for saving the schema.")

def tearDown(self):
self.teardown_started = True
Expand Down

0 comments on commit 23ecadd

Please sign in to comment.