Add optional healthcheck middleware
This change introduces a new option, [healthcheck] enabled, which enables the healthcheck middleware in mistral-api pipeline. This middleware allows status check at /healthcheck path, which is useful for load balancers or any monitoring services to validate health of its backend services. This change is created based on the same change proposed to ironic[1]. [1] 6f439414bdcef9fc02f844f475ec798d48d42558 Co-Authored-By: Jim Rollenhagen <jim@jimrollenhagen.com> Change-Id: I9bf3de8a5ae6a8c9346285147732b773a3667f7e
This commit is contained in:
parent
7c35734300
commit
f17dd7a04b
@ -15,7 +15,8 @@
|
||||
|
||||
from oslo_config import cfg
|
||||
import oslo_middleware.cors as cors_middleware
|
||||
import oslo_middleware.http_proxy_to_wsgi as http_proxy_to_wsgi_middleware
|
||||
from oslo_middleware import healthcheck
|
||||
from oslo_middleware import http_proxy_to_wsgi
|
||||
import osprofiler.web
|
||||
import pecan
|
||||
|
||||
@ -85,7 +86,11 @@ def setup_app(config=None):
|
||||
)
|
||||
|
||||
# Create HTTPProxyToWSGI wrapper
|
||||
app = http_proxy_to_wsgi_middleware.HTTPProxyToWSGI(app, cfg.CONF)
|
||||
app = http_proxy_to_wsgi.HTTPProxyToWSGI(app, cfg.CONF)
|
||||
|
||||
# Create a healthcheck wrapper
|
||||
if cfg.CONF.healthcheck.enabled:
|
||||
app = healthcheck.Healthcheck(app, cfg.CONF)
|
||||
|
||||
# Create a CORS wrapper, and attach mistral-specific defaults that must be
|
||||
# included in all CORS responses.
|
||||
|
@ -705,6 +705,17 @@ yaql_opts = [
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
healthcheck_opts = [
|
||||
cfg.BoolOpt('enabled',
|
||||
default=False,
|
||||
help=_('Enable the health check endpoint at /healthcheck. '
|
||||
'Note that this is unauthenticated. More information '
|
||||
'is available at '
|
||||
'https://docs.openstack.org/oslo.middleware/latest/'
|
||||
'reference/healthcheck_plugins.html.')),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
LEGACY_ACTION_PROVIDER_GROUP = 'legacy_action_provider'
|
||||
@ -723,6 +734,7 @@ ACTION_LOGGING_GROUP = 'action_logging'
|
||||
PROFILER_GROUP = profiler.list_opts()[0][0]
|
||||
KEYCLOAK_OIDC_GROUP = "keycloak_oidc"
|
||||
YAQL_GROUP = "yaql"
|
||||
HEALTHCHECK_GROUP = 'healthcheck'
|
||||
KEYSTONE_GROUP = "keystone"
|
||||
|
||||
|
||||
@ -760,6 +772,7 @@ CONF.register_opts(coordination_opts, group=COORDINATION_GROUP)
|
||||
CONF.register_opts(profiler_opts, group=PROFILER_GROUP)
|
||||
CONF.register_opts(keycloak_oidc_opts, group=KEYCLOAK_OIDC_GROUP)
|
||||
CONF.register_opts(yaql_opts, group=YAQL_GROUP)
|
||||
CONF.register_opts(healthcheck_opts, group=HEALTHCHECK_GROUP)
|
||||
loading.register_session_conf_options(CONF, KEYSTONE_GROUP)
|
||||
|
||||
CLI_OPTS = [
|
||||
@ -807,6 +820,7 @@ def list_opts():
|
||||
(PROFILER_GROUP, profiler_opts),
|
||||
(KEYCLOAK_OIDC_GROUP, keycloak_oidc_opts),
|
||||
(YAQL_GROUP, yaql_opts),
|
||||
(HEALTHCHECK_GROUP, healthcheck_opts),
|
||||
(ACTION_HEARTBEAT_GROUP, action_heartbeat_opts),
|
||||
(ACTION_LOGGING_GROUP, action_logging_opts),
|
||||
(None, default_group_opts)
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
from mistral.tests.unit.api import base
|
||||
from oslo_config import cfg
|
||||
from oslo_middleware import http_proxy_to_wsgi as http_proxy_to_wsgi_middleware
|
||||
from oslo_middleware import healthcheck
|
||||
from oslo_middleware import http_proxy_to_wsgi
|
||||
|
||||
|
||||
class TestHTTPProxyToWSGIMiddleware(base.APITest):
|
||||
@ -28,15 +29,38 @@ class TestHTTPProxyToWSGIMiddleware(base.APITest):
|
||||
|
||||
def setUp(self):
|
||||
# Make sure the HTTPProxyToWSGI options are registered
|
||||
cfg.CONF.register_opts(http_proxy_to_wsgi_middleware.OPTS,
|
||||
cfg.CONF.register_opts(http_proxy_to_wsgi.OPTS,
|
||||
'oslo_middleware')
|
||||
|
||||
# Enable proxy headers parsing in HTTPProxyToWSGI middleware.
|
||||
self.override_config(
|
||||
"enable_proxy_headers_parsing",
|
||||
"True",
|
||||
True,
|
||||
group='oslo_middleware'
|
||||
)
|
||||
|
||||
# Create the application.
|
||||
super(TestHTTPProxyToWSGIMiddleware, self).setUp()
|
||||
|
||||
|
||||
class TestHealthcheckMiddleware(base.APITest):
|
||||
"""Test oslo_middleware Healthcheck.
|
||||
|
||||
It checks that oslo_middleware middleware Healthcheck is executed
|
||||
when enabled.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
# Make sure the Healthcheck options are registered
|
||||
cfg.CONF.register_opts(healthcheck.OPTS,
|
||||
'oslo_middleware')
|
||||
|
||||
# Enable healthcheck middleware.
|
||||
self.override_config(
|
||||
"enabled",
|
||||
True,
|
||||
group='healthcheck'
|
||||
)
|
||||
|
||||
# Create the application.
|
||||
super(TestHealthcheckMiddleware, self).setUp()
|
||||
|
5
releasenotes/notes/healthcheck-b2757de5e49a868b.yaml
Normal file
5
releasenotes/notes/healthcheck-b2757de5e49a868b.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The new ``[healthcheck] enabled`` option has been added. This option can
|
||||
be used to enable the ``helthcheck`` middleware in mistral-api service.
|
@ -3,6 +3,7 @@ namespace = mistral.config
|
||||
namespace = oslo.db
|
||||
namespace = oslo.messaging
|
||||
namespace = oslo.middleware.cors
|
||||
namespace = oslo.middleware.healthcheck
|
||||
namespace = oslo.middleware.http_proxy_to_wsgi
|
||||
namespace = keystonemiddleware.auth_token
|
||||
namespace = oslo.log
|
||||
|
Loading…
x
Reference in New Issue
Block a user