From 11fb500825550bdfe977151ceb74788a1af6f721 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 31 Aug 2025 00:12:22 +0900 Subject: [PATCH] Remove remaining log translation Log translation support was removed during Pike cycle[1]. [1] https://review.opendev.org/c/openstack/oslo.i18n/+/446762 Also string interpolations should be delayed in logging to avoid unnecessary interpolation operations. Change-Id: Ifce960b10bae691f8117c4728821f9da13045fed Signed-off-by: Takashi Kajinami --- aodh/api/controllers/v2/alarms.py | 2 +- aodh/evaluator/composite.py | 2 +- aodh/evaluator/gnocchi.py | 18 +++++++++--------- aodh/notifier/heat.py | 2 +- aodh/notifier/log.py | 18 +++++++++--------- aodh/notifier/rest.py | 10 +++++----- aodh/notifier/zaqar.py | 14 +++++++------- tox.ini | 3 ++- 8 files changed, 35 insertions(+), 34 deletions(-) diff --git a/aodh/api/controllers/v2/alarms.py b/aodh/api/controllers/v2/alarms.py index 687ccdc37..30a3bb1ad 100644 --- a/aodh/api/controllers/v2/alarms.py +++ b/aodh/api/controllers/v2/alarms.py @@ -192,7 +192,7 @@ class AlarmTimeConstraint(base.Base): ALARMS_RULES = extension.ExtensionManager("aodh.alarm.rule") -LOG.debug("alarm rules plugin loaded: %s" % ",".join(ALARMS_RULES.names())) +LOG.debug("alarm rules plugin loaded: %s", ",".join(ALARMS_RULES.names())) ACTIONS_SCHEMA = extension.ExtensionManager( notifier.AlarmNotifierService.NOTIFIER_EXTENSIONS_NAMESPACE).names() diff --git a/aodh/evaluator/composite.py b/aodh/evaluator/composite.py index 93f270d0e..3d0b1cf6f 100644 --- a/aodh/evaluator/composite.py +++ b/aodh/evaluator/composite.py @@ -158,7 +158,7 @@ class CompositeEvaluator(evaluator.Evaluator): self.rule_targets.append(rule) return AlarmEvaluation(rule), OkEvaluation(rule) else: - LOG.error("Invalid rule type: %s" % alarm_rule['type']) + LOG.error("Invalid rule type: %s", alarm_rule['type']) return False, False def _reason(self, alarm, new_state, rule_target_alarm): diff --git a/aodh/evaluator/gnocchi.py b/aodh/evaluator/gnocchi.py index 867e2674d..bbd97b252 100644 --- a/aodh/evaluator/gnocchi.py +++ b/aodh/evaluator/gnocchi.py @@ -91,9 +91,9 @@ class GnocchiResourceThresholdEvaluator(GnocchiBase): rule['resource_id']), []) except Exception as e: - msg = 'alarm statistics retrieval failed: %s' % e - LOG.warning(msg) - raise threshold.InsufficientDataError(msg, []) + msg = 'alarm statistics retrieval failed: %s' + LOG.warning(msg, e) + raise threshold.InsufficientDataError(msg % e, []) class GnocchiAggregationMetricsThresholdEvaluator(GnocchiBase): @@ -136,9 +136,9 @@ class GnocchiAggregationMetricsThresholdEvaluator(GnocchiBase): 'metrics in %s' % (rule['aggregation_method'], rule['metrics']), []) except Exception as e: - msg = 'alarm statistics retrieval failed: %s' % e - LOG.warning(msg) - raise threshold.InsufficientDataError(msg, []) + msg = 'alarm statistics retrieval failed: %s' + LOG.warning(msg, e) + raise threshold.InsufficientDataError(msg % e, []) class GnocchiAggregationResourcesThresholdEvaluator(GnocchiBase): @@ -177,6 +177,6 @@ class GnocchiAggregationResourcesThresholdEvaluator(GnocchiBase): 'aggregation %s does not exist for at least one ' 'metric of the query' % rule['aggregation_method'], []) except Exception as e: - msg = 'alarm statistics retrieval failed: %s' % e - LOG.warning(msg) - raise threshold.InsufficientDataError(msg, []) + msg = 'alarm statistics retrieval failed: %s' + LOG.warning(msg, e) + raise threshold.InsufficientDataError(msg % e, []) diff --git a/aodh/notifier/heat.py b/aodh/notifier/heat.py index c875e80ad..730aca4b4 100644 --- a/aodh/notifier/heat.py +++ b/aodh/notifier/heat.py @@ -51,7 +51,7 @@ class TrustHeatAlarmNotifier(notifier.AlarmNotifier): LOG.info( "Notifying alarm %(alarm_name)s %(alarm_id)s of %(severity)s " "priority from %(previous)s to %(current)s with action %(action)s" - " because %(reason)s." % + " because %(reason)s.", {'alarm_name': alarm_name, 'alarm_id': alarm_id, 'severity': severity, diff --git a/aodh/notifier/log.py b/aodh/notifier/log.py index bfc215ddf..118429b41 100644 --- a/aodh/notifier/log.py +++ b/aodh/notifier/log.py @@ -16,7 +16,6 @@ from oslo_log import log -from aodh.i18n import _ from aodh import notifier LOG = log.getLogger(__name__) @@ -28,13 +27,14 @@ class LogAlarmNotifier(notifier.AlarmNotifier): @staticmethod def notify(action, alarm_id, alarm_name, severity, previous, current, reason, reason_data): - LOG.info(_( + LOG.info( "Notifying alarm %(alarm_name)s %(alarm_id)s of %(severity)s " "priority from %(previous)s to %(current)s with action %(action)s" - " because %(reason)s.") % ({'alarm_name': alarm_name, - 'alarm_id': alarm_id, - 'severity': severity, - 'previous': previous, - 'current': current, - 'action': action.geturl(), - 'reason': reason})) + " because %(reason)s.", + {'alarm_name': alarm_name, + 'alarm_id': alarm_id, + 'severity': severity, + 'previous': previous, + 'current': current, + 'action': action.geturl(), + 'reason': reason}) diff --git a/aodh/notifier/rest.py b/aodh/notifier/rest.py index bea1e6005..985376152 100644 --- a/aodh/notifier/rest.py +++ b/aodh/notifier/rest.py @@ -67,11 +67,11 @@ class RestAlarmNotifier(notifier.AlarmNotifier): LOG.info( "Notifying alarm %(alarm_name)s %(alarm_id)s with severity" " %(severity)s from %(previous)s to %(current)s with action " - "%(action)s because %(reason)s. request-id: %(request_id)s " % - ({'alarm_name': alarm_name, 'alarm_id': alarm_id, - 'severity': severity, 'previous': previous, - 'current': current, 'action': action, 'reason': reason, - 'request_id': headers['x-openstack-request-id']})) + "%(action)s because %(reason)s. request-id: %(request_id)s", + {'alarm_name': alarm_name, 'alarm_id': alarm_id, + 'severity': severity, 'previous': previous, + 'current': current, 'action': action, 'reason': reason, + 'request_id': headers['x-openstack-request-id']}) body = {'alarm_name': alarm_name, 'alarm_id': alarm_id, 'severity': severity, 'previous': previous, 'current': current, 'reason': reason, diff --git a/aodh/notifier/zaqar.py b/aodh/notifier/zaqar.py index 948e88721..023aa8fed 100644 --- a/aodh/notifier/zaqar.py +++ b/aodh/notifier/zaqar.py @@ -134,13 +134,13 @@ class ZaqarAlarmNotifier(notifier.AlarmNotifier): LOG.info( "Notifying alarm %(alarm_name)s %(alarm_id)s of %(severity)s " "priority from %(previous)s to %(current)s with action %(action)s" - " because %(reason)s." % ({'alarm_name': alarm_name, - 'alarm_id': alarm_id, - 'severity': severity, - 'previous': previous, - 'current': current, - 'action': action, - 'reason': reason})) + " because %(reason)s.", {'alarm_name': alarm_name, + 'alarm_id': alarm_id, + 'severity': severity, + 'previous': previous, + 'current': current, + 'action': action, + 'reason': reason}) body = {'alarm_name': alarm_name, 'alarm_id': alarm_id, 'severity': severity, 'previous': previous, 'current': current, 'reason': reason, diff --git a/tox.ini b/tox.ini index 515282c82..e9de3af8b 100644 --- a/tox.ini +++ b/tox.ini @@ -89,7 +89,8 @@ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build # [H203] Use assertIs(Not)None to check for None. # [H204] Use assert(Not)Equal to check for equality. # [H205] Use assert(Greater|Less)(Equal) for comparison. -enable-extensions=H106,H203,H204,H205 +# [H904] Delay string interpolations at logging calls. +enable-extensions=H106,H203,H204,H205,H904 show-source = True [hacking]