summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-09-28 17:33:39 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2015-09-29 12:59:00 -0700
commitb1b4f8480c78663a5807d12e6917a94421d5b0b6 (patch)
treed6fe26a10808ccfa23f659a8fb1906faacbb4ccd
parent77a6d8aef4429e413aac3723e36337f42d8a53bc (diff)
downloadoslo-middleware-b1b4f8480c78663a5807d12e6917a94421d5b0b6.tar.gz
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
-rw-r--r--oslo_middleware/healthcheck/__init__.py22
-rw-r--r--oslo_middleware/healthcheck/disable_by_file.py16
-rw-r--r--oslo_middleware/healthcheck/pluginbase.py11
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):
<H2>Result of {{results|length}} checks:</H2>
<TABLE bgcolor="#ffffff" border="1">
<TBODY>
+<TR>
+{% if detailed -%}
+<TH>
+Kind
+</TH>
+<TH>
+Reason
+</TH>
+<TH>
+Details
+</TH>
+{% else %}
+<TH>
+Reason
+</TH>
+{%- endif %}
+</TR>
{% for result in results -%}
{% if result.reason -%}
<TR>
@@ -169,6 +186,9 @@ class Healthcheck(base.ConfigurableMiddleware):
<TD>{{result.class|e}}</TD>
{%- endif %}
<TD>{{result.reason|e}}</TD>
+{% if detailed -%}
+ <TD>{{result.details|e}}</TD>
+{%- endif %}
</TR>
{%- 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)