From 614c2e0829122b6a63a5a6f264175e1c73e9ea04 Mon Sep 17 00:00:00 2001 From: Guy Davis Date: Mon, 26 Sep 2022 20:29:11 -0600 Subject: [PATCH] Fixes for Chiadog over-notifications --- .../condition_checkers/non_decreasing_plots.py | 3 ++- src/chia_log/log_consumer.py | 11 +++++++---- src/chia_log/parsers/block_parser.py | 2 +- src/chia_log/parsers/finished_signage_point_parser.py | 2 +- src/chia_log/parsers/harvester_activity_parser.py | 2 +- src/chia_log/parsers/partial_parser.py | 2 +- src/chia_log/parsers/wallet_added_coin_parser.py | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/chia_log/handlers/condition_checkers/non_decreasing_plots.py b/src/chia_log/handlers/condition_checkers/non_decreasing_plots.py index f5081cc..41476ef 100644 --- a/src/chia_log/handlers/condition_checkers/non_decreasing_plots.py +++ b/src/chia_log/handlers/condition_checkers/non_decreasing_plots.py @@ -24,7 +24,8 @@ def __init__(self): def check(self, obj: HarvesterActivityMessage) -> Optional[Event]: event = None - if obj.total_plots_count > self._max_farmed_plots: + # Only alert if going from 1 or more plots to more. Don't spam a message from zero on every startup... + if self._max_farmed_plots > 0 and obj.total_plots_count > self._max_farmed_plots: logging.info(f"Detected new plots. Farming with {obj.total_plots_count} plots.") message = ( f"Connected HDD? The total plot count increased from " diff --git a/src/chia_log/log_consumer.py b/src/chia_log/log_consumer.py index 9af0347..0bec59c 100644 --- a/src/chia_log/log_consumer.py +++ b/src/chia_log/log_consumer.py @@ -69,6 +69,10 @@ def __init__(self, log_path: Path, coin_name: str, coin_symbol: str, prefix: str logging.info(f"Enabled local file log consumer: {self._expanded_log_path}") self._offset_path = mkdtemp() / Config.get_log_offset_path() logging.info(f"Using temporary directory {self._offset_path}") + # Cleanup stale temporary file + if self._offset_path.exists(): + logging.info(f"Deleting stale log offset file: {self._offset_path}") + self._offset_path.unlink() self._is_running = True self._thread = Thread(target=self._consume_loop) self._thread.start() @@ -78,11 +82,10 @@ def __init__(self, log_path: Path, coin_name: str, coin_symbol: str, prefix: str def stop(self): logging.info("Stopping") - # Why were original authors throwing away the offset file on every stop? # Cleanup the temporary file - #if self._offset_path.exists(): - # logging.info(f"Deleting {self._offset_path}") - # self._offset_path.unlink() + if self._offset_path.exists(): + logging.info(f"Deleting {self._offset_path}") + self._offset_path.unlink() self._is_running = False diff --git a/src/chia_log/parsers/block_parser.py b/src/chia_log/parsers/block_parser.py index f4ddfb2..d6e87e5 100644 --- a/src/chia_log/parsers/block_parser.py +++ b/src/chia_log/parsers/block_parser.py @@ -27,7 +27,7 @@ class BlockParser: def __init__(self, config: Optional[dict] = None): logging.info("Enabled parser for block found stats.") self._regex = re.compile( - r"([0-9:.]*) full_node (?:src|" + config['prefix'] + ").full_node.full_node\s*: INFO\s* ((?:🍀 |.)\s*Farmed unfinished_block)" + r"([0-9:.T-]*) full_node (?:src|" + config['prefix'] + ").full_node.full_node\s*: INFO\s* ((?:🍀 |.)\s*Farmed unfinished_block)" ) def parse(self, logs: str) -> List[BlockMessage]: diff --git a/src/chia_log/parsers/finished_signage_point_parser.py b/src/chia_log/parsers/finished_signage_point_parser.py index b5e1379..349d0a0 100644 --- a/src/chia_log/parsers/finished_signage_point_parser.py +++ b/src/chia_log/parsers/finished_signage_point_parser.py @@ -29,7 +29,7 @@ def __init__(self, config: Optional[dict] = None): # Doing some "smart" tricks with this expression to also match the 64th signage point # with the same regex expression. See test examples to see how they differ. self._regex = re.compile( - r"([0-9:.]*) full_node (?:src|" + config['prefix'] + ").full_node.full_node(?:\s?): INFO\s*(?:⏲️|.)[a-z A-Z,]* ([0-9]*)\/64" + r"([0-9:.T-]*) full_node (?:src|" + config['prefix'] + ").full_node.full_node(?:\s?): INFO\s*(?:⏲️|.)[a-z A-Z,]* ([0-9]*)\/64" ) def parse(self, logs: str) -> List[FinishedSignagePointMessage]: diff --git a/src/chia_log/parsers/harvester_activity_parser.py b/src/chia_log/parsers/harvester_activity_parser.py index e33c403..d1aef18 100644 --- a/src/chia_log/parsers/harvester_activity_parser.py +++ b/src/chia_log/parsers/harvester_activity_parser.py @@ -31,7 +31,7 @@ class HarvesterActivityParser: def __init__(self, config: Optional[dict] = None): logging.info("Enabled parser for harvester activity - eligible plot events.") self._regex = re.compile( - r"([0-9:.]*) harvester (?:src|" + config['prefix'] + ").harvester.harvester(?:\s?): INFO\s*([0-9]+) plots were " + r"([0-9:.T-]*) harvester (?:src|" + config['prefix'] + ").harvester.harvester(?:\s?): INFO\s*([0-9]+) plots were " r"eligible for farming ([0-9a-z.]*) Found ([0-9]) proofs. Time: ([0-9.]*) s. " r"Total ([0-9]*) plots" ) diff --git a/src/chia_log/parsers/partial_parser.py b/src/chia_log/parsers/partial_parser.py index 3afe38c..9511e2d 100644 --- a/src/chia_log/parsers/partial_parser.py +++ b/src/chia_log/parsers/partial_parser.py @@ -26,7 +26,7 @@ class PartialParser: def __init__(self, config: Optional[dict] = None): logging.info("Enabled parser for partial submitting stats.") - self._regex = re.compile(r"([0-9:.]*) farmer (?:src|" + config['prefix'] + ").farmer.farmer\s*: INFO\s* (Submitting partial)") + self._regex = re.compile(r"([0-9:.T-]*) farmer (?:src|" + config['prefix'] + ").farmer.farmer\s*: INFO\s* (Submitting partial)") def parse(self, logs: str) -> List[PartialMessage]: """Parses all farmer activity messages from a bunch of logs diff --git a/src/chia_log/parsers/wallet_added_coin_parser.py b/src/chia_log/parsers/wallet_added_coin_parser.py index 925654f..2e02aec 100644 --- a/src/chia_log/parsers/wallet_added_coin_parser.py +++ b/src/chia_log/parsers/wallet_added_coin_parser.py @@ -26,7 +26,7 @@ def __init__(self, config: Optional[dict] = None): logging.info("Enabled parser for wallet activity - added coins.") self._prefix = config['prefix'] self._regex = re.compile( - r"([0-9:.]*) wallet (?:src|" + self._prefix + ").wallet.wallet_state_manager(?:\s?): " + r"([0-9:.T-]*) wallet (?:src|" + self._prefix + ").wallet.wallet_state_manager(?:\s?): " r"INFO\s*Adding.*coin:.*'?amount'?: ([0-9]*)" )