Merge "Avoid translating debug log"
This commit is contained in:
commit
0ea64947b5
@ -212,11 +212,10 @@ class AlarmService(object):
|
||||
def _evaluate_alarm(self, alarm):
|
||||
"""Evaluate the alarms assigned to this evaluator."""
|
||||
if alarm.type not in self.evaluators:
|
||||
LOG.debug(_('skipping alarm %s: type unsupported') %
|
||||
alarm.alarm_id)
|
||||
LOG.debug('skipping alarm %s: type unsupported', alarm.alarm_id)
|
||||
return
|
||||
|
||||
LOG.debug(_('evaluating alarm %s') % alarm.alarm_id)
|
||||
LOG.debug('evaluating alarm %s', alarm.alarm_id)
|
||||
try:
|
||||
self.evaluators[alarm.type].obj.evaluate(alarm)
|
||||
except Exception:
|
||||
|
@ -101,8 +101,8 @@ class CombinationEvaluator(evaluator.Evaluator):
|
||||
|
||||
def evaluate(self, alarm):
|
||||
if not self.within_time_constraint(alarm):
|
||||
LOG.debug(_('Attempted to evaluate alarm %s, but it is not '
|
||||
'within its time constraint.') % alarm.alarm_id)
|
||||
LOG.debug('Attempted to evaluate alarm %s, but it is not '
|
||||
'within its time constraint.', alarm.alarm_id)
|
||||
return
|
||||
|
||||
states = zip(alarm.rule['alarm_ids'],
|
||||
|
@ -78,7 +78,7 @@ class GnocchiThresholdEvaluator(threshold.ThresholdEvaluator):
|
||||
alarm.rule['resource_type'],
|
||||
alarm.rule['resource_id'], alarm.rule['metric'])
|
||||
|
||||
LOG.debug(_('stats query %s') % req['url'])
|
||||
LOG.debug('stats query %s', req['url'])
|
||||
try:
|
||||
r = getattr(requests, method)(**req)
|
||||
except Exception:
|
||||
|
@ -76,14 +76,14 @@ class ThresholdEvaluator(evaluator.Evaluator):
|
||||
window = ((alarm.rule.get('period', None) or alarm.rule['granularity'])
|
||||
* (alarm.rule['evaluation_periods'] + look_back))
|
||||
start = now - datetime.timedelta(seconds=window)
|
||||
LOG.debug(_('query stats from %(start)s to '
|
||||
'%(now)s') % {'start': start, 'now': now})
|
||||
LOG.debug('query stats from %(start)s to '
|
||||
'%(now)s', {'start': start, 'now': now})
|
||||
return start.isoformat(), now.isoformat()
|
||||
|
||||
@staticmethod
|
||||
def _sanitize(alarm, statistics):
|
||||
"""Sanitize statistics."""
|
||||
LOG.debug(_('sanitize stats %s') % statistics)
|
||||
LOG.debug('sanitize stats %s', statistics)
|
||||
if alarm.rule.get('exclude_outliers'):
|
||||
key = operator.attrgetter('count')
|
||||
mean = utils.mean(statistics, key)
|
||||
@ -92,7 +92,7 @@ class ThresholdEvaluator(evaluator.Evaluator):
|
||||
upper = mean + 2 * stddev
|
||||
inliers, outliers = utils.anomalies(statistics, key, lower, upper)
|
||||
if outliers:
|
||||
LOG.debug(_('excluded weak datapoints with sample counts %s'),
|
||||
LOG.debug('excluded weak datapoints with sample counts %s',
|
||||
[s.count for s in outliers])
|
||||
statistics = inliers
|
||||
else:
|
||||
@ -103,7 +103,7 @@ class ThresholdEvaluator(evaluator.Evaluator):
|
||||
statistics = statistics[-alarm.rule['evaluation_periods']:]
|
||||
result_statistics = [getattr(stat, alarm.rule['statistic'])
|
||||
for stat in statistics]
|
||||
LOG.debug(_('pruned statistics to %d') % len(statistics))
|
||||
LOG.debug('pruned statistics to %d', len(statistics))
|
||||
return result_statistics
|
||||
|
||||
def _statistics(self, alarm, start, end):
|
||||
@ -112,7 +112,7 @@ class ThresholdEvaluator(evaluator.Evaluator):
|
||||
before = dict(field='timestamp', op='le', value=end)
|
||||
query = copy.copy(alarm.rule['query'])
|
||||
query.extend([before, after])
|
||||
LOG.debug(_('stats query %s') % query)
|
||||
LOG.debug('stats query %s', query)
|
||||
try:
|
||||
return self._client.statistics.list(
|
||||
meter_name=alarm.rule['meter_name'], q=query,
|
||||
@ -200,8 +200,8 @@ class ThresholdEvaluator(evaluator.Evaluator):
|
||||
|
||||
def evaluate(self, alarm):
|
||||
if not self.within_time_constraint(alarm):
|
||||
LOG.debug(_('Attempted to evaluate alarm %s, but it is not '
|
||||
'within its time constraint.') % alarm.alarm_id)
|
||||
LOG.debug('Attempted to evaluate alarm %s, but it is not '
|
||||
'within its time constraint.', alarm.alarm_id)
|
||||
return
|
||||
|
||||
start, end = self._bound_duration(alarm)
|
||||
@ -212,9 +212,8 @@ class ThresholdEvaluator(evaluator.Evaluator):
|
||||
def _compare(value):
|
||||
op = COMPARATORS[alarm.rule['comparison_operator']]
|
||||
limit = alarm.rule['threshold']
|
||||
LOG.debug(_('comparing value %(value)s against threshold'
|
||||
' %(limit)s') %
|
||||
{'value': value, 'limit': limit})
|
||||
LOG.debug('comparing value %(value)s against threshold'
|
||||
' %(limit)s', {'value': value, 'limit': limit})
|
||||
return op(value, limit)
|
||||
|
||||
self._transition(alarm,
|
||||
|
@ -47,5 +47,23 @@ def check_oslo_namespace_imports(logical_line, physical_line, filename):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
def no_translate_debug_logs(logical_line, filename):
|
||||
"""Check for 'LOG.debug(_('
|
||||
|
||||
As per our translation policy,
|
||||
https://wiki.openstack.org/wiki/LoggingStandards#Log_Translation
|
||||
we shouldn't translate debug level logs.
|
||||
|
||||
* This check assumes that 'LOG' is a logger.
|
||||
* Use filename so we can start enforcing this in specific folders instead
|
||||
of needing to do so all at once.
|
||||
|
||||
N319
|
||||
"""
|
||||
if logical_line.startswith("LOG.debug(_("):
|
||||
yield(0, "N319 Don't translate debug level logs")
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(check_oslo_namespace_imports)
|
||||
register(no_translate_debug_logs)
|
||||
|
@ -96,8 +96,8 @@ class AlarmNotifierService(os_service.Service):
|
||||
return
|
||||
|
||||
try:
|
||||
LOG.debug(_("Notifying alarm %(id)s with action %(act)s") % (
|
||||
{'id': alarm_id, 'act': action}))
|
||||
LOG.debug("Notifying alarm %(id)s with action %(act)s",
|
||||
{'id': alarm_id, 'act': action})
|
||||
notifier.notify(action, alarm_id, alarm_name, severity,
|
||||
previous, current, reason, reason_data)
|
||||
except Exception:
|
||||
|
@ -20,7 +20,6 @@ from oslo_context import context
|
||||
from oslo_log import log
|
||||
import six
|
||||
|
||||
from aodh.i18n import _
|
||||
from aodh import messaging
|
||||
from aodh.storage import models
|
||||
|
||||
@ -45,9 +44,9 @@ class RPCAlarmNotifier(object):
|
||||
def notify(self, alarm, previous, reason, reason_data):
|
||||
actions = getattr(alarm, models.Alarm.ALARM_ACTIONS_MAP[alarm.state])
|
||||
if not actions:
|
||||
LOG.debug(_('alarm %(alarm_id)s has no action configured '
|
||||
LOG.debug('alarm %(alarm_id)s has no action configured '
|
||||
'for state transition from %(previous)s to '
|
||||
'state %(state)s, skipping the notification.') %
|
||||
'state %(state)s, skipping the notification.',
|
||||
{'alarm_id': alarm.alarm_id,
|
||||
'previous': previous,
|
||||
'state': alarm.state})
|
||||
|
@ -18,7 +18,6 @@ from oslo_log import log
|
||||
from oslo_utils import netutils
|
||||
from six.moves.urllib import parse as urlparse
|
||||
|
||||
from aodh.i18n import _
|
||||
from aodh.storage.hbase import inmemory as hbase_inmemory
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
@ -42,8 +41,8 @@ class Connection(object):
|
||||
else:
|
||||
# This is a in-memory usage for unit tests
|
||||
if Connection._memory_instance is None:
|
||||
LOG.debug(_('Creating a new in-memory HBase '
|
||||
'Connection object'))
|
||||
LOG.debug('Creating a new in-memory HBase Connection '
|
||||
'object')
|
||||
Connection._memory_instance = (hbase_inmemory.
|
||||
MConnectionPool())
|
||||
self.conn_pool = Connection._memory_instance
|
||||
@ -59,8 +58,8 @@ class Connection(object):
|
||||
The tests use a subclass to override this and return an
|
||||
in-memory connection pool.
|
||||
"""
|
||||
LOG.debug(_('connecting to HBase on %(host)s:%(port)s') % (
|
||||
{'host': conf['host'], 'port': conf['port']}))
|
||||
LOG.debug('connecting to HBase on %(host)s:%(port)s',
|
||||
{'host': conf['host'], 'port': conf['port']})
|
||||
return happybase.ConnectionPool(size=100, host=conf['host'],
|
||||
port=conf['port'],
|
||||
table_prefix=conf['table_prefix'])
|
||||
|
@ -21,7 +21,6 @@ from oslo_log import log
|
||||
import six
|
||||
|
||||
import aodh
|
||||
from aodh.i18n import _
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -265,7 +264,7 @@ class MConnection(object):
|
||||
|
||||
@staticmethod
|
||||
def open():
|
||||
LOG.debug(_("Opening in-memory HBase connection"))
|
||||
LOG.debug("Opening in-memory HBase connection")
|
||||
|
||||
def create_table(self, n, families=None):
|
||||
families = families or {}
|
||||
|
@ -17,7 +17,6 @@ import operator
|
||||
from oslo_log import log
|
||||
|
||||
import aodh
|
||||
from aodh.i18n import _
|
||||
from aodh.storage import base
|
||||
from aodh.storage.hbase import base as hbase_base
|
||||
from aodh.storage.hbase import migration as hbase_migration
|
||||
@ -81,18 +80,18 @@ class Connection(hbase_base.Connection, base.Connection):
|
||||
hbase_migration.migrate_tables(conn, tables)
|
||||
|
||||
def clear(self):
|
||||
LOG.debug(_('Dropping HBase schema...'))
|
||||
LOG.debug('Dropping HBase schema...')
|
||||
with self.conn_pool.connection() as conn:
|
||||
for table in [self.ALARM_TABLE,
|
||||
self.ALARM_HISTORY_TABLE]:
|
||||
try:
|
||||
conn.disable_table(table)
|
||||
except Exception:
|
||||
LOG.debug(_('Cannot disable table but ignoring error'))
|
||||
LOG.debug('Cannot disable table but ignoring error')
|
||||
try:
|
||||
conn.delete_table(table)
|
||||
except Exception:
|
||||
LOG.debug(_('Cannot delete table but ignoring error'))
|
||||
LOG.debug('Cannot delete table but ignoring error')
|
||||
|
||||
def update_alarm(self, alarm):
|
||||
"""Create an alarm.
|
||||
|
Loading…
Reference in New Issue
Block a user