From b1b4f8480c78663a5807d12e6917a94421d5b0b6 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 28 Sep 2015 17:33:39 -0700 Subject: Allow health check results to provide there own details When in detailed mode, show the provided details in a nicely formatted table (or json) so that the user of the healthcheck middleware can gain more insight into the result that was produced. Change-Id: I2fc1f7588ee628990d78b15ad337bd0eebbe8fb3 --- oslo_middleware/healthcheck/__init__.py | 22 ++++++++++++++++++++++ oslo_middleware/healthcheck/disable_by_file.py | 16 ++++++++++------ oslo_middleware/healthcheck/pluginbase.py | 11 ++++++++--- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/oslo_middleware/healthcheck/__init__.py b/oslo_middleware/healthcheck/__init__.py index 9e46bd8..cacc9b6 100644 --- a/oslo_middleware/healthcheck/__init__.py +++ b/oslo_middleware/healthcheck/__init__.py @@ -162,6 +162,23 @@ class Healthcheck(base.ConfigurableMiddleware):

Result of {{results|length}} checks:

+ +{% if detailed -%} + + + +{% else %} + +{%- endif %} + {% for result in results -%} {% if result.reason -%} @@ -169,6 +186,9 @@ class Healthcheck(base.ConfigurableMiddleware): {%- endif %} +{% if detailed -%} + +{%- endif %} {%- endif %} {%- endfor %} @@ -293,6 +313,7 @@ class Healthcheck(base.ConfigurableMiddleware): for result in results: reasons.append({ 'reason': result.reason, + 'details': result.details or '', 'class': reflection.get_class_name(result, fully_qualified=False), }) @@ -317,6 +338,7 @@ class Healthcheck(base.ConfigurableMiddleware): translated_results = [] for result in results: translated_results.append({ + 'details': result.details or '', 'reason': result.reason, 'class': reflection.get_class_name(result, fully_qualified=False), diff --git a/oslo_middleware/healthcheck/disable_by_file.py b/oslo_middleware/healthcheck/disable_by_file.py index cd438cf..a80a46e 100644 --- a/oslo_middleware/healthcheck/disable_by_file.py +++ b/oslo_middleware/healthcheck/disable_by_file.py @@ -44,11 +44,15 @@ class DisableByFileHealthcheck(pluginbase.HealthcheckBaseExtension): if path is None: LOG.warning(_LW('DisableByFile healthcheck middleware enabled ' 'without disable_by_file_path set')) - return pluginbase.HealthcheckResult(available=True, - reason="OK") + return pluginbase.HealthcheckResult( + available=True, reason="OK", + details="No 'disable_by_file_path' configuration value" + " specified") elif not os.path.exists(path): - return pluginbase.HealthcheckResult(available=True, - reason="OK") + return pluginbase.HealthcheckResult( + available=True, reason="OK", + details="Path '%s' was not found" % path) else: - return pluginbase.HealthcheckResult(available=False, - reason="DISABLED BY FILE") + return pluginbase.HealthcheckResult( + available=False, reason="DISABLED BY FILE", + details="Path '%s' was found" % path) diff --git a/oslo_middleware/healthcheck/pluginbase.py b/oslo_middleware/healthcheck/pluginbase.py index ffd3e08..92b2c09 100644 --- a/oslo_middleware/healthcheck/pluginbase.py +++ b/oslo_middleware/healthcheck/pluginbase.py @@ -14,12 +14,17 @@ # under the License. import abc -import collections import six -HealthcheckResult = collections.namedtuple( - 'HealthcheckResult', ['available', 'reason']) + +class HealthcheckResult(object): + """Result of a ``healthcheck`` method call should be this object.""" + + def __init__(self, available, reason, details=None): + self.available = available + self.reason = reason + self.details = details @six.add_metaclass(abc.ABCMeta) -- cgit v1.2.1
+Kind + +Reason + +Details + +Reason +
{{result.class|e}}{{result.reason|e}}{{result.details|e}}