Skip to content

Commit

Permalink
Merge pull request #17871 from redpanda-data/PESDLC-1129-fix-cloud-ra…
Browse files Browse the repository at this point in the history
…ise-onbadlogs

Update handling of bad logs for cloud deployments
  • Loading branch information
savex authored Apr 24, 2024
2 parents 02d597c + 3b1d079 commit 016d51a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions tests/rptest/services/cloud_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(self, pod, kubectl, logger) -> None:
# Backward compatibility
# Various classes will use this var to hash and compare nodes
self.account = self._meta
# Mimic Ducktape cluster node hostname field
self.hostname = f"{self._spec['nodeName']}/{self.name}"

def _query_broker(self, path, port=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/rptest/services/redpanda.py
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ def raise_on_bad_logs(self, allow_list=None, test_start_time=None):
self.logger,
self.kubectl,
test_start_time=test_start_time)
lsearcher.search_logs(self.get_redpanda_pods())
lsearcher.search_logs(self.pods)


class RedpandaService(RedpandaServiceBase):
Expand Down
22 changes: 15 additions & 7 deletions tests/rptest/services/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
from typing import Generator, Optional

from rptest.clients.kubectl import KubectlTool, KubeNodeShell
from rptest.services.cloud_broker import CloudBroker


class BadLogLines(Exception):
def __init__(self, node_to_lines):
self.node_to_lines = node_to_lines

@staticmethod
def _get_hostname(node):
if isinstance(node, CloudBroker):
return node.hostname
else:
return node.account.hostname

def __str__(self):
# Pick the first line from the first node as an example, and include it
# in the string output so that for single line failures, it isn't necessary
Expand All @@ -20,7 +28,7 @@ def __str__(self):
example = next(iter(example_lines))

summary = ','.join([
f'{i[0].account.hostname}({len(i[1])})'
f'{self._get_hostname(i[0])}({len(i[1])})'
for i in self.node_to_lines.items()
])
return f"<BadLogLines nodes={summary} example=\"{example}\">"
Expand Down Expand Up @@ -154,6 +162,7 @@ def search_logs(self, nodes):
bad_loglines = self._search(nodes)
# If anything, raise exception
if bad_loglines:
# Call class overriden method to get proper Exception class
raise BadLogLines(bad_loglines)


Expand Down Expand Up @@ -195,8 +204,7 @@ def parse_k8s_time(logline, tz):

# Load log, output is in binary form
loglines = []
pod_name = self._get_hostname(pod)
node_name = pod['spec']['nodeName']
node_name = pod._spec['nodeName']
tz = "+00:00"
with KubeNodeShell(self.kubectl, node_name) as ksh:
try:
Expand All @@ -208,16 +216,16 @@ def parse_k8s_time(logline, tz):
# Find all log files for target pod
logfiles = ksh(f"find /var/log/pods -type f")
for logfile in logfiles:
if pod_name in logfile and \
if pod.name in logfile and \
'redpanda-configurator' not in logfile:
self.logger.info(f"Inspecting '{logfile}'")
lines = ksh(f"cat {logfile} | grep {expr}")
loglines += lines
except Exception as e:
self.logger.warning(f"Error getting logs for {pod_name}: {e}")
self.logger.warning(f"Error getting logs for {pod.name}: {e}")
else:
_size = len(loglines)
self.logger.debug(f"Received {_size}B of data from {pod_name}")
self.logger.debug(f"Received {_size}B of data from {pod.name}")

# check log lines for proper timing.
# Log lines will have two timing objects:
Expand All @@ -238,4 +246,4 @@ def parse_k8s_time(logline, tz):
yield line

def _get_hostname(self, host) -> str:
return host['metadata']['name']
return host.hostname

0 comments on commit 016d51a

Please sign in to comment.