From 42976df86fa5938225c50b92d2b6ba8dbb11a572 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Mon, 16 Oct 2023 08:55:07 +0200 Subject: [PATCH] Make it easier to debug callbacks (#2902) 1. Introduce DEBUG logs for callbacks 2. Configure log format in behave tests to include filename, line, and method name that triggered the callback and enable DEBUG logs for `patroni.postgresql.callback_executor` module. P.S. unfortunately it works only starting from python 3.8, but it should be good enough for debug purpose because 3.7 is already EOL. --- features/environment.py | 4 ++++ patroni/postgresql/callback_executor.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/features/environment.py b/features/environment.py index 79db5d16..1f36eb0c 100644 --- a/features/environment.py +++ b/features/environment.py @@ -245,6 +245,10 @@ class PatroniController(AbstractController): self.recursive_update(config, custom_config) self.recursive_update(config, { + 'log': { + 'format': '%(asctime)s %(levelname)s [%(pathname)s:%(lineno)d - %(funcName)s]: %(message)s', + 'loggers': {'patroni.postgresql.callback_executor': 'DEBUG'} + }, 'bootstrap': { 'dcs': { 'loop_wait': 2, diff --git a/patroni/postgresql/callback_executor.py b/patroni/postgresql/callback_executor.py index fa645b86..06b9f353 100644 --- a/patroni/postgresql/callback_executor.py +++ b/patroni/postgresql/callback_executor.py @@ -1,8 +1,9 @@ import logging +import sys from enum import Enum from threading import Condition, Thread -from typing import List +from typing import Any, Dict, List from .cancellable import CancellableExecutor, CancellableSubprocess @@ -53,6 +54,8 @@ class CallbackExecutor(CancellableExecutor, Thread): If it couldn't be killed we wait until it finishes. :param cmd: command to be executed""" + kwargs: Dict[str, Any] = {'stacklevel': 3} if sys.version_info >= (3, 8) else {} + logger.debug('CallbackExecutor.call(%s)', cmd, **kwargs) if cmd[-3] == CallbackAction.ON_RELOAD: return self._on_reload_executor.call_nowait(cmd)