Skip to content

Commit

Permalink
issue: 4197110: Add the collectx versions to the to the PDF (#286)
Browse files Browse the repository at this point in the history
* Add the collectx versions to the to the PFD
* refactor
* fix ruff and pylint comments
  • Loading branch information
Miryam-Schwartz authored Dec 8, 2024
1 parent 3db6ab6 commit 658e078
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
12 changes: 3 additions & 9 deletions plugins/ufm_log_analyzer_plugin/src/loganalyze/log_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import traceback
from typing import Callable, List, Set, Tuple


from loganalyze.log_analyzers.base_analyzer import BaseImageCreator
from loganalyze.logs_extraction.directory_extractor import DirectoryExtractor
from loganalyze.log_analyzers.ufm_top_analyzer import UFMTopAnalyzer
Expand Down Expand Up @@ -369,7 +368,7 @@ def create_analyzer(
end = time.perf_counter()
log.LOGGER.debug(f"Took {end-start:.3f} to load the parsed data")

all_images_outputs_and_title, dataframes_for_pdf, txt_for_pdf = (
all_images_outputs_and_title, dataframes_for_pdf, lists_for_pdf, txt_for_pdf = (
ufm_top_analyzer.full_analysis_all_analyzers()
)

Expand All @@ -385,13 +384,8 @@ def create_analyzer(
pdf_path = os.path.join(args.destination, "UFM_Dump_analysis.pdf")
pdf_header = f"{os.path.basename(args.location)}, hours={args.hours}"

used_ufm_version = console_log_analyzer.ufm_versions
text_to_show_in_pdf = (
f"Used ufm version in console log {used_ufm_version}{os.linesep}"
)

pdf = PDFCreator(pdf_path, pdf_header, png_images, text_to_show_in_pdf)
pdf.create_pdf(dataframes_for_pdf, txt_for_pdf)
pdf = PDFCreator(pdf_path, pdf_header, png_images, txt_for_pdf)
pdf.create_pdf(dataframes_for_pdf, lists_for_pdf)

# Generated a report that can be located in the destination
log.LOGGER.info("Analysis is done, please see the following outputs:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, dest_image_path):
self._dest_image_path = dest_image_path
self._images_created = []
self._dataframes_for_pdf = []
self._lists_for_pdf = []
self._txt_for_pdf = []
self._funcs_for_analysis = set()

Expand Down Expand Up @@ -166,6 +167,9 @@ def get_images_created(self):
def get_dataframes_for_pdf(self):
return self._dataframes_for_pdf

def get_lists_for_pdf(self):
return self._lists_for_pdf

def get_txt_for_pdf(self):
return self._txt_for_pdf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def __init__(
self.fix_lines_with_no_timestamp(logs_csvs)
super().__init__(logs_csvs, hours, dest_image_path, sort_timestamp)
self._log_data_sorted.dropna(subset=["data"], inplace=True)
self._funcs_for_analysis = {self.print_exceptions_per_time_count}
self._funcs_for_analysis = {
self.print_exceptions_per_time_count,
self.save_ufm_versions,
}

@staticmethod
def _extract_ufm_version(logs_csvs):
Expand Down Expand Up @@ -106,6 +109,11 @@ def print_exceptions_per_time_count(self):
"Exceptions count",
)

def save_ufm_versions(self):
self._txt_for_pdf.append(
f"Used ufm version in console log {self.ufm_versions}{os.linesep}"
)

def full_analysis(self):
super().full_analysis()
self.print_exceptions()
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def __init__(
self.save_first_last_iteration_timestamp,
self.save_number_of_switches_and_ports,
self.save_number_of_core_dumps,
self.save_collectx_versions,
}

# Based on the log path, decided if this is primary or secondary
if "ufm_logs" in logs_csvs[0]:
self.telemetry_type = "primary"
Expand All @@ -52,11 +54,14 @@ def __init__(
self._first_timestamp_of_logs = None
self._last_timestamp_of_logs = None

def get_collectx_versions(self):
def save_collectx_versions(self):
unique_collectx_versions = self._log_data_sorted[
self._log_data_sorted["type"] == "collectx_version"
]["data"].unique()
return unique_collectx_versions
self._txt_for_pdf.append(
f"collectx versions found in {self.telemetry_type} telemetry log \
{set(unique_collectx_versions)}"
)

def save_number_of_switches_and_ports(self):
"""
Expand Down Expand Up @@ -217,7 +222,7 @@ def save_number_of_core_dumps(self):
self._log_data_sorted["type"] == "timeout_dump_core"
]
num = {"Amount": len(core_dumps)}
self._txt_for_pdf.append(
self._lists_for_pdf.append(
(
[num],
f"{self.telemetry_type} number of core dumps found in the logs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ def full_analysis_all_analyzers(self):

graphs_and_titles = []
dataframes = []
lists = []
txt = []
for analyzer in self._analyzers:
graphs_and_titles.extend(analyzer.get_images_created())
dataframes.extend(analyzer.get_dataframes_for_pdf())
lists.extend(analyzer.get_lists_for_pdf())
txt.extend(analyzer.get_txt_for_pdf())

return graphs_and_titles, dataframes, txt
return graphs_and_titles, dataframes, lists, txt
7 changes: 4 additions & 3 deletions plugins/ufm_log_analyzer_plugin/src/loganalyze/pdf_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@


class PDFCreator(FPDF):
def __init__(self, pdf_path, pdf_header, images_path, fabric_stats_list):
def __init__(self, pdf_path, pdf_header, images_path, txt_list):
super().__init__()
self._pdf_path = pdf_path
self._pdf_header = pdf_header
self._images_path = images_path
self._fabric_stats_list = fabric_stats_list
self._txt_list = txt_list

def header(self):
self.set_font("Arial", "B", 12)
Expand Down Expand Up @@ -60,7 +60,8 @@ def add_images(self):
def add_text(self):
self.set_font("Arial", "", 12)
output = StringIO()
print(self._fabric_stats_list, file=output)
for txt in self._txt_list:
print(txt, file=output)
text = output.getvalue().strip()
self.multi_cell(0, 10, text)

Expand Down

0 comments on commit 658e078

Please sign in to comment.