From 502094ee79bed4b2eead29c88239c6a1cb992b1d Mon Sep 17 00:00:00 2001 From: Don Seiler Date: Fri, 3 Aug 2018 10:00:57 -0500 Subject: [PATCH] Log config change or not (#731) This adds INFO log messages that clearly state if configuration values were seen as changed by Patroni after SIGHUP/reload and warrant reloading (or if nothing was changed an no reloading is necessary). This ended up being a lot simpler than I had imagined once I found postgresql.py:reload_config(). I add a log line in config.py:reload_local_configuration() since that function will short-circuit the process early if the local config wasn't changed. But the final determination of whether or not values have changed and need reloading is in postgresql.py:reload_config(). --- patroni/config.py | 2 ++ patroni/postgresql.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/patroni/config.py b/patroni/config.py index 89f1511c..ee809f5b 100644 --- a/patroni/config.py +++ b/patroni/config.py @@ -158,6 +158,8 @@ class Config(object): self._local_configuration = configuration self.__effective_configuration = new_configuration return True + else: + logger.info('No configuration items changed, nothing to reload.') except Exception: logger.exception('Exception when reloading local configuration from %s', self.config_file) if dry_run: diff --git a/patroni/postgresql.py b/patroni/postgresql.py index 4462c524..a963330f 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -337,10 +337,12 @@ class Postgresql(object): if new_value is None or not compare_values(r[3], unit, r[1], new_value): if r[4] == 'postmaster': pending_restart = True + logger.info('Changed %s from %s to %s (restart required)', r[0], r[1], new_value) if config.get('use_unix_socket') and r[0] == 'unix_socket_directories'\ or r[0] in ('listen_addresses', 'port'): local_connection_address_changed = True else: + logger.info('Changed %s from %s to %s', r[0], r[1], new_value) conf_changed = True for param in changes: if param in server_parameters: @@ -351,11 +353,13 @@ class Postgresql(object): if not conf_changed: for p, v in server_parameters.items(): if '.' in p and (p not in self._server_parameters or str(v) != str(self._server_parameters[p])): + logger.info('Changed %s from %s to %s', p, self._server_parameters.get(p), v) conf_changed = True break if not conf_changed: for p, v in self._server_parameters.items(): if '.' in p and (p not in server_parameters or str(v) != str(server_parameters[p])): + logger.info('Changed %s from %s to %s', p, v, server_parameters.get(p)) conf_changed = True break @@ -377,7 +381,10 @@ class Postgresql(object): self._replace_pg_hba() if conf_changed or hba_changed: + logger.info('PostgreSQL configuration items changed, reloading configuration.') self.reload() + elif not pending_restart: + logger.info('No PostgreSQL configuration items changed, nothing to reload.') self._is_leader_retry.deadline = self.retry.deadline = config['retry_timeout']/2.0