Merge "Add optional healthcheck middleware"

This commit is contained in:
Zuul 2023-12-14 00:35:55 +00:00 committed by Gerrit Code Review
commit 973e6ac996
5 changed files with 54 additions and 5 deletions

View File

@ -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.

View File

@ -718,6 +718,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'
@ -736,6 +747,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"
@ -773,6 +785,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 = [
@ -820,6 +833,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)

View File

@ -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()

View 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.

View File

@ -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