From 8fd739bf7dd234e8a777a5da23c65ba9e4149fc9 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Thu, 13 Jun 2024 20:33:22 +0200 Subject: [PATCH] Log repeated "no action" messages at a DEBUG level Many people have to tune Patroni log level to WARNING, since messages like "no action: I am (patroni1), the leader with the lock" are emitted every HA loop run at an INFO level. Those are noisy and not terribly useful, as Patroni emits a different message anyway when the status quo changes. This commit changes the default behavior by showing the "no action" message as an INFO for the first time, demoting subsequent repeated "no action" messages to DEBUG. --- patroni/__main__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/patroni/__main__.py b/patroni/__main__.py index e3d8a3c49..2fe69b04c 100644 --- a/patroni/__main__.py +++ b/patroni/__main__.py @@ -78,6 +78,8 @@ def __init__(self, config: 'Config') -> None: self.next_run = time.time() self.scheduled_restart: Dict[str, Any] = {} + self._last_cycle_info = "" + def ensure_dcs_access(self, sleep_time: int = 5) -> 'Cluster': """Continuously attempt to retrieve cluster from DCS with delay. @@ -209,7 +211,15 @@ def _run_cycle(self) -> None: the change and cache the new dynamic configuration values in ``patroni.dynamic.json`` file under Postgres data directory. """ - logger.info(self.ha.run_cycle()) + + info: str = self.ha.run_cycle() + # if we report no action, show this message as INFO only when emitted for the first time + # demote it to DEBUG afterwards as long as it repeats + log_ha_action = logger.info + if info.startswith('no action.') or info.startswith('PAUSE: no action.') and self._last_cycle_info == info: + log_ha_action = logger.debug + + log_ha_action(info) if self.dcs.cluster and self.dcs.cluster.config and self.dcs.cluster.config.data \ and self.config.set_dynamic_configuration(self.dcs.cluster.config):