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

fix(logcollection): save schema info output #9513

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
28 changes: 21 additions & 7 deletions sdcm/logcollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,17 @@ class BaseLogEntity: # pylint: disable=too-few-public-methods
collect_timeout = 300
_params = {}

def __init__(self, name, command="", search_locally=False):
def __init__(self, name, command="", search_locally=False, collect_from_parent=False):
"""
collect_from_parent: relevant for cluster:
- there are logs of every node
- there are logs that relevant for whole cluster
If this parameter is True - collect logs on cluster level (cluster folder), not under node folder
"""
self.name = name
self.cmd = command
self.search_locally = search_locally
self.collect_from_parent = collect_from_parent

def set_params(self, params):
self._params = params
Expand Down Expand Up @@ -622,11 +629,16 @@ def collect_logs_per_node(node):
LOGGER.info('Collecting logs on host: %s', node.name)
remote_node_dir = self.create_remote_storage_dir(node)
local_node_dir = os.path.join(self.local_dir, node.name)
local_parent_dir = self.local_dir
for log_entity in self.log_entities:
try:
log_entity.collect(node, local_node_dir, remote_node_dir, local_search_path=local_search_path)
log_entity.collect(node=node,
local_dst=local_parent_dir if log_entity.collect_from_parent else local_node_dir,
remote_dst=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 @@ -718,6 +730,12 @@ class ScyllaLogCollector(LogCollector):
search_locally=True),
FileLog(name='netstat_*',
search_locally=True),
FileLog(name='schema.log',
search_locally=True,
collect_from_parent=True),
FileLog(name='system_schema_tables.log',
search_locally=True,
collect_from_parent=True),
CommandLog(name='cpu_info',
command='cat /proc/cpuinfo'),
CommandLog(name='mem_info',
Expand Down Expand Up @@ -749,10 +767,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
33 changes: 27 additions & 6 deletions sdcm/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2961,22 +2961,43 @@ def clean_resources(self):

self.destroy_credentials()

@silence(name='Save node schema')
def save_nodes_schema(self):
@silence(name=f"Save node schema", raise_error_event=False)
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) / self.db_cluster.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_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",
if not node._is_node_ready_run_scylla_commands():
continue
found_live_node = True
self.save_cqlsh_output_in_file(node=node, cmd="desc schema", log_file="schema.log")
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
with silence(parent=self, name='Sending test end event'):
InfoEvent(message="TEST_END").publish()
self.save_nodes_schema()
self.save_schema()
self.log.info("Post test validators are starting...")
for validator_class in teardown_validators_list:
validator_class(self.params, self).validate()
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/test_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def stop_event_device(self):
time.sleep(0.5)
super().stop_event_device()

def save_nodes_schema(self):
def save_schema(self):
pass


Expand Down
Loading