Skip to content

Commit

Permalink
encapsulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Miryam-Schwartz committed Dec 1, 2024
1 parent 1df655b commit 7853db1
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,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, lists_to_add = (
all_images_outputs_and_title, dataframes_for_pdf, txt_for_pdf = (
ufm_top_analyzer.full_analysis_all_analyzers()
)

Expand All @@ -393,7 +393,7 @@ def create_analyzer(
pdf = PDFCreator(pdf_path, pdf_header, png_images, text_to_show_in_pdf)

# PDF creator gets all the images and to add to the report
pdf.create_pdf(dataframes_for_pdf, lists_to_add)
pdf.create_pdf(dataframes_for_pdf, txt_for_pdf)
# Generated a report that can be located in the destination
log.LOGGER.info("Analysis is done, please see the following outputs:")
for image, title in images_and_title_to_present:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ class BaseImageCreator:
def __init__(self, dest_image_path):
self._dest_image_path = dest_image_path
self._images_created = []
self._dataframes_for_pdf = []
self._txt_for_pdf = []
self._funcs_for_analysis = set()

def _save_data_based_on_timestamp(
self, data_to_plot, x_label, y_label, title, large_sample=False
):
if len(data_to_plot) == 0:
if data_to_plot.empty:
return
with plt.ion():
log.LOGGER.debug(f"saving {title}")
Expand Down Expand Up @@ -157,9 +159,16 @@ def full_analysis(self):
)
except: # pylint: disable=bare-except
pass

return self._images_created if len(self._images_created) > 0 else [], [], []

return

def get_images_created(self):
return self._images_created

def get_dataframes_for_pdf(self):
return self._dataframes_for_pdf

def get_txt_for_pdf(self):
return self._txt_for_pdf

class BaseAnalyzer(BaseImageCreator):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ def full_analysis(self):
Returns a list of all the graphs created and their title
"""
self.print_exceptions()
return super().full_analysis()
super().full_analysis()
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,11 @@ def plot_link_up_down_count_per_aggregation_time(self):
)

def full_analysis(self):
images, _, _ = super().full_analysis()
super().full_analysis()
critical_events_headers = ["timestamp", "event_type", "event", "count"]
lists = [
(
self.get_critical_event_bursts(),
"More than 5 events burst over a minute",
critical_events_headers,
)
]
return images, [], lists
txt_to_add = (
self.get_critical_event_bursts(),
"More than 5 events burst over a minute",
critical_events_headers,
)
self._txt_for_pdf.append(txt_to_add)
Original file line number Diff line number Diff line change
Expand Up @@ -195,35 +195,32 @@ def get_number_of_core_dumps(self):
return {"Amount": len(core_dumps)}

def full_analysis(self):
images, _, _ = super().full_analysis()
dataframes_for_pdf = []
lists_to_add = []
dataframes_for_pdf.append(
super().full_analysis()
self._dataframes_for_pdf.append(
(
f"{self.telemetry_type} Telemetry iteration time",
self.get_last_iterations_time_stats(),
)
)

dataframes_for_pdf.append(
self._dataframes_for_pdf.append(
(
f"{self.telemetry_type} "
"Telemetry iteration first and last timestamps",
self.get_first_last_iteration_timestamp(),
)
)
dataframes_for_pdf.append(
self._dataframes_for_pdf.append(
(
f"{self.telemetry_type} Telemetry fabric size",
self.get_number_of_switches_and_ports(),
)
)

lists_to_add.append(
self._txt_for_pdf.append(
(
[self.get_number_of_core_dumps()],
f"{self.telemetry_type} " "number of core dumps found in the logs",
["Amount"],
)
)
return images, dataframes_for_pdf, lists_to_add
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ def full_analysis(self):
"""
self.print_fabric_size()
fabric_info = self.get_fabric_size()
tmp_df = [("Fabric info", fabric_info)]
return [], tmp_df, []
self._dataframes_for_pdf.append(("Fabric info", fabric_info))
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pathlib import Path
import pandas as pd
from utils.netfix.link_flapping import get_link_flapping
from loganalyze.log_analyzers.base_analyzer import BaseImageCreator
from loganalyze.log_analyzers.base_analyzer import BaseAnalyzer, BaseImageCreator
import loganalyze.logger as log

FILE_NAME_PATTERN = r"^secondary_(5m|1h|1d|1w)_(\d{14})\.gz$"
Expand Down Expand Up @@ -142,12 +142,12 @@ def plot_link_flapping_last_week(self):
)

def full_analysis(self):
super().full_analysis()
link_flapping_last_week = self.get_link_flapping_last_week()
images, _, _ = super().full_analysis()
df = [
(
"Link Flapping last week",
link_flapping_last_week,
link_flapping_last_week
)
]
return images, df, []
self._dataframes_for_pdf.extend(df)
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@ def full_analysis_all_analyzers(self):
"""
Returns a list of all the graphs created and their title
"""
for analyzer in self._analyzers:
analyzer.full_analysis()

graphs_and_titles = []
dataframes = []
lists_to_add = []
txt = []
for analyzer in self._analyzers:
tmp_images_list, tmp_dataframes, tmp_lists = analyzer.full_analysis()
graphs_and_titles.extend(tmp_images_list)
dataframes.extend(tmp_dataframes)
lists_to_add.extend(tmp_lists)

has_ibdiagnet_analyzer = any(
isinstance(instance, IBDIAGNETLogAnalyzer) for instance in self._analyzers
)
if not has_ibdiagnet_analyzer:
dataframes.append(("Fabric info", ("No Fabric Info found")))

return graphs_and_titles, dataframes, lists_to_add
graphs_and_titles.extend(analyzer.get_images_created())
dataframes.extend(analyzer.get_dataframes_for_pdf())
txt.extend(analyzer.get_txt_for_pdf())

return graphs_and_titles, dataframes, txt

0 comments on commit 7853db1

Please sign in to comment.