Merge "Improve agent_client logging"
This commit is contained in:
commit
6222d57a74
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
"""Utilities and helper functions."""
|
"""Utilities and helper functions."""
|
||||||
|
|
||||||
|
from collections import abc
|
||||||
import contextlib
|
import contextlib
|
||||||
import datetime
|
import datetime
|
||||||
import errno
|
import errno
|
||||||
|
@ -638,3 +639,18 @@ def is_memory_insufficent(raise_if_fail=False):
|
||||||
# Sleep so interpreter can switch threads.
|
# Sleep so interpreter can switch threads.
|
||||||
time.sleep(CONF.minimum_memory_wait_time)
|
time.sleep(CONF.minimum_memory_wait_time)
|
||||||
loop_count = loop_count + 1
|
loop_count = loop_count + 1
|
||||||
|
|
||||||
|
|
||||||
|
_LARGE_KEYS = frozenset(['system_logs'])
|
||||||
|
|
||||||
|
|
||||||
|
def remove_large_keys(var):
|
||||||
|
"""Remove specific keys from the var, recursing into dicts and lists."""
|
||||||
|
if isinstance(var, abc.Mapping):
|
||||||
|
return {key: (remove_large_keys(value)
|
||||||
|
if key not in _LARGE_KEYS else '<...>')
|
||||||
|
for key, value in var.items()}
|
||||||
|
elif isinstance(var, abc.Sequence) and not isinstance(var, str):
|
||||||
|
return var.__class__(map(remove_large_keys, var))
|
||||||
|
else:
|
||||||
|
return var
|
||||||
|
|
|
@ -24,6 +24,7 @@ import tenacity
|
||||||
|
|
||||||
from ironic.common import exception
|
from ironic.common import exception
|
||||||
from ironic.common.i18n import _
|
from ironic.common.i18n import _
|
||||||
|
from ironic.common import utils
|
||||||
from ironic.conf import CONF
|
from ironic.conf import CONF
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
@ -53,6 +54,15 @@ def get_command_error(command):
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
|
||||||
|
def _sanitize_for_logging(var):
|
||||||
|
if not var:
|
||||||
|
return var
|
||||||
|
elif isinstance(var, str):
|
||||||
|
return strutils.mask_password(var)
|
||||||
|
else:
|
||||||
|
return utils.remove_large_keys(strutils.mask_dict_password(var))
|
||||||
|
|
||||||
|
|
||||||
class AgentClient(object):
|
class AgentClient(object):
|
||||||
"""Client for interacting with nodes via a REST API."""
|
"""Client for interacting with nodes via a REST API."""
|
||||||
@METRICS.timer('AgentClient.__init__')
|
@METRICS.timer('AgentClient.__init__')
|
||||||
|
@ -170,8 +180,10 @@ class AgentClient(object):
|
||||||
agent_token = node.driver_internal_info.get('agent_secret_token')
|
agent_token = node.driver_internal_info.get('agent_secret_token')
|
||||||
if agent_token:
|
if agent_token:
|
||||||
request_params['agent_token'] = agent_token
|
request_params['agent_token'] = agent_token
|
||||||
LOG.debug('Executing agent command %(method)s for node %(node)s',
|
LOG.debug('Executing agent command %(method)s for node %(node)s '
|
||||||
{'node': node.uuid, 'method': method})
|
'with params %(params)s',
|
||||||
|
{'node': node.uuid, 'method': method,
|
||||||
|
'params': _sanitize_for_logging(request_params)})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = self.session.post(
|
response = self.session.post(
|
||||||
|
@ -208,7 +220,7 @@ class AgentClient(object):
|
||||||
LOG.debug('Agent command %(method)s for node %(node)s returned '
|
LOG.debug('Agent command %(method)s for node %(node)s returned '
|
||||||
'result %(res)s, error %(error)s, HTTP status code %(code)s',
|
'result %(res)s, error %(error)s, HTTP status code %(code)s',
|
||||||
{'node': node.uuid, 'method': method,
|
{'node': node.uuid, 'method': method,
|
||||||
'res': result.get('command_result'),
|
'res': _sanitize_for_logging(result.get('command_result')),
|
||||||
'error': error,
|
'error': error,
|
||||||
'code': response.status_code if response is not None
|
'code': response.status_code if response is not None
|
||||||
else 'unknown'})
|
else 'unknown'})
|
||||||
|
@ -313,7 +325,8 @@ class AgentClient(object):
|
||||||
result = _get().json()['commands']
|
result = _get().json()['commands']
|
||||||
status = '; '.join('%(cmd)s: result "%(res)s", error "%(err)s"' %
|
status = '; '.join('%(cmd)s: result "%(res)s", error "%(err)s"' %
|
||||||
{'cmd': r.get('command_name'),
|
{'cmd': r.get('command_name'),
|
||||||
'res': r.get('command_result'),
|
'res': _sanitize_for_logging(
|
||||||
|
r.get('command_result')),
|
||||||
'err': r.get('command_error')}
|
'err': r.get('command_error')}
|
||||||
for r in result)
|
for r in result)
|
||||||
LOG.debug('Status of agent commands for node %(node)s: %(status)s',
|
LOG.debug('Status of agent commands for node %(node)s: %(status)s',
|
||||||
|
|
Loading…
Reference in New Issue