Skip to content

Commit

Permalink
Chore lint (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
Superskyyy authored Jun 16, 2023
1 parent e0e9428 commit 43076b7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions drain3/template_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def __init__(self,

self.persistence_handler = persistence_handler

param_str = self.config.mask_prefix + "*" + self.config.mask_suffix
param_str = f"{self.config.mask_prefix}*{self.config.mask_suffix}"

# Follow the configuration in the configuration file to instantiate Drain
# target_obj will be "Drain" if the engine argument is not specified.
target_obj = self.config.engine
if target_obj not in ["Drain","JaccardDrain"]:
if target_obj not in ["Drain", "JaccardDrain"]:
raise ValueError(f"Invalid matched_pattern: {target_obj}, must be either 'Drain' or 'JaccardDrain'")

self.drain = globals()[target_obj](
Expand Down Expand Up @@ -104,8 +104,8 @@ def load_state(self):
self.drain.clusters_counter = loaded_drain.clusters_counter
self.drain.root_node = loaded_drain.root_node

logger.info("Restored {0} clusters built from {1} messages".format(
len(loaded_drain.clusters), loaded_drain.get_total_cluster_size()))
logger.info(f"Restored {len(loaded_drain.clusters)} clusters "
f"built from {loaded_drain.get_total_cluster_size()} messages")

def save_state(self, snapshot_reason):
state = jsonpickle.dumps(self.drain, keys=True).encode('utf-8')
Expand All @@ -119,7 +119,7 @@ def save_state(self, snapshot_reason):

def get_snapshot_reason(self, change_type, cluster_id):
if change_type != "none":
return "{} ({})".format(change_type, cluster_id)
return f"{change_type} ({cluster_id})"

diff_time_sec = time.time() - self.last_save_time
if diff_time_sec >= self.config.snapshot_interval_minutes * 60:
Expand Down Expand Up @@ -246,11 +246,11 @@ def extract_parameters(self,

@cachedmethod(lambda self: self.parameter_extraction_cache)
def _get_template_parameter_extraction_regex(self, log_template: str, exact_matching: bool):
param_group_name_to_mask_name = dict()
param_group_name_to_mask_name = {}
param_name_counter = [0]

def get_next_param_name():
param_group_name = "p_" + str(param_name_counter[0])
param_group_name = f"p_{str(param_name_counter[0])}"
param_name_counter[0] += 1
return param_group_name

Expand Down Expand Up @@ -293,7 +293,7 @@ def replace_captured_param_name(param_pattern):
param_group_name = get_next_param_name()
param_group_name_to_mask_name[param_group_name] = _mask_name
joined_patterns = "|".join(allowed_patterns)
capture_regex = "(?P<{}>{})".format(param_group_name, joined_patterns)
capture_regex = f"(?P<{param_group_name}>{joined_patterns})"
return capture_regex

# For every mask in the template, replace it with a named group of all
Expand Down Expand Up @@ -321,5 +321,5 @@ def replace_captured_param_name(param_pattern):

# match also messages with multiple spaces or other whitespace chars between tokens
template_regex = re.sub(r"\\ ", r"\\s+", template_regex)
template_regex = "^" + template_regex + "$"
template_regex = f"^{template_regex}$"
return template_regex, param_group_name_to_mask_name
6 changes: 3 additions & 3 deletions examples/drain_bigfile_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


config = TemplateMinerConfig()
config.load(dirname(__file__) + "/drain3.ini")
config.load(f"{dirname(__file__)}/drain3.ini")
config.profiling_enabled = True
template_miner = TemplateMiner(config=config)

Expand All @@ -52,8 +52,8 @@
batch_start_time = time.time()
if result["change_type"] != "none":
result_json = json.dumps(result)
logger.info(f"Input ({line_count}): " + line)
logger.info("Result: " + result_json)
logger.info(f"Input ({line_count}): {line}")
logger.info(f"Result: {result_json}")

time_took = time.time() - start_time
rate = line_count / time_took
Expand Down
4 changes: 2 additions & 2 deletions examples/drain_stdin_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
persistence = None

config = TemplateMinerConfig()
config.load(dirname(__file__) + "/drain3.ini")
config.load(f"{dirname(__file__)}/drain3.ini")
config.profiling_enabled = False

template_miner = TemplateMiner(persistence, config)
Expand All @@ -55,7 +55,7 @@
print(result_json)
template = result["template_mined"]
params = template_miner.extract_parameters(template, log_line)
print("Parameters: " + str(params))
print(f"Parameters: {str(params)}")

print("Training done. Mined clusters:")
for cluster in template_miner.drain.clusters:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_template_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TemplateMinerTest(unittest.TestCase):

def test_load_config(self):
config = TemplateMinerConfig()
config.load(dirname(__file__) + "/drain3_test.ini")
config.load(f"{dirname(__file__)}/drain3_test.ini")
self.assertEqual(1024, config.drain_max_clusters)
self.assertListEqual(["_"], config.drain_extra_delimiters)
self.assertEqual(7, len(config.masking_instructions))
Expand Down

0 comments on commit 43076b7

Please sign in to comment.