logpai / Drain3

A robust streaming log template miner based on the Drain algorithm
Other
470 stars 134 forks source link

Error parsing logs: "ZeroDivisionError: float division by zero" #65

Closed zequeira closed 2 years ago

zequeira commented 2 years ago

Hi, I'm using Drain3 to parse some logs and sometimes I get the following error:

Traceback (most recent call last): File "C:+\envs+\lib\site-packages\IPython\core\interactiveshell.py", line 3369, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 13, in <cell line: 11> result = template_miner.add_log_message(msg) File "C:+\envs+\lib\site-packages\drain3\template_miner.py", line 146, in add_log_message self.profiler.report(self.config.profiling_report_sec) File "C:+\envs+\lib\site-packages\drain3\simple_profiler.py", line 112, in report text = os.linesep.join(lines) File "C:+\envs+\lib\site-packages\drain3\simple_profiler.py", line 111, in lines = map(lambda it: it.to_string(enclosing_time_sec, include_batch_rates), sorted_sections) File "C:+\envs+\lib\site-packages\drain3\simple_profiler.py", line 135, in to_string samples_per_sec = f"{self.sample_count / self.total_time_sec: 15,.2f}" ZeroDivisionError: float division by zero

any help would be appreciated.

Superskyyy commented 2 years ago

I guess the code didn't start and enclose the last section, which I think is probably this

template_miner.profiler.start_section('print_tree')
template_miner.drain.print_tree()
template_miner.profiler.end_section('print_tree')

template_miner.profiler.report(period_sec=0)

So the profiler took the wrong section total which is already done profiling.

Can you confirm please? @davidohana

davidohana commented 2 years ago

@zequeira This seems like a bug in the profiler, when trying to measure the time of a very short operation, the total time is 0. Fixed in latest version 0.9.11 (hopefully), please check. BTW you can always disable profiling in the configuration of Drain3, I think that the default should be disabled.

davidohana commented 2 years ago

@Superskyyy I don't see any profiling of print_tree in the codebase, can you specify the exact lines?

Superskyyy commented 2 years ago

This is fixed and closing.