Add optional healthcheck middleware
This change allows uses to enable the healthcheck middleware from oslo.middleware in API pipeline, by setting the [healthcheck]/enabled option. This middleware provides an API endpoint at /healthcheck path which allows load balancers or monitoring applications to determine a service is up using HTTP requests. This change basically follows the same change merged in ironic[1] repo. [1] 6f439414bdcef9fc02f844f475ec798d48d42558 Change-Id: Ic2ee2bca74ea2a5a0723ef54b10c531f77ea7b8d
This commit is contained in:
parent
62f79a1129
commit
d7400b5dc4
@ -19,6 +19,7 @@ from ironic_inspector.conf import default
|
||||
from ironic_inspector.conf import discovery
|
||||
from ironic_inspector.conf import dnsmasq_pxe_filter
|
||||
from ironic_inspector.conf import extra_hardware
|
||||
from ironic_inspector.conf import healthcheck
|
||||
from ironic_inspector.conf import iptables
|
||||
from ironic_inspector.conf import ironic
|
||||
from ironic_inspector.conf import pci_devices
|
||||
@ -39,6 +40,7 @@ discovery.register_opts(CONF)
|
||||
default.register_opts(CONF)
|
||||
dnsmasq_pxe_filter.register_opts(CONF)
|
||||
extra_hardware.register_opts(CONF)
|
||||
healthcheck.register_opts(CONF)
|
||||
iptables.register_opts(CONF)
|
||||
ironic.register_opts(CONF)
|
||||
pci_devices.register_opts(CONF)
|
||||
|
33
ironic_inspector/conf/healthcheck.py
Normal file
33
ironic_inspector/conf/healthcheck.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from ironic_inspector.common.i18n import _
|
||||
|
||||
_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.')),
|
||||
]
|
||||
|
||||
|
||||
def register_opts(conf):
|
||||
conf.register_opts(_OPTS, group='healthcheck')
|
||||
|
||||
|
||||
def list_opts():
|
||||
return _OPTS
|
@ -69,6 +69,7 @@ def list_opts():
|
||||
('dnsmasq_pxe_filter',
|
||||
ironic_inspector.conf.dnsmasq_pxe_filter.list_opts()),
|
||||
('extra_hardware', ironic_inspector.conf.extra_hardware.list_opts()),
|
||||
('healthcheck', ironic_inspector.conf.healthcheck.list_opts()),
|
||||
('ironic', ironic_inspector.conf.ironic.list_opts()),
|
||||
('iptables', ironic_inspector.conf.iptables.list_opts()),
|
||||
('port_physnet', ironic_inspector.conf.port_physnet.list_opts()),
|
||||
|
@ -70,6 +70,8 @@ def _init_middleware():
|
||||
else:
|
||||
LOG.warning('Starting unauthenticated, please check'
|
||||
' configuration')
|
||||
if CONF.healthcheck.enabled:
|
||||
utils.add_healthcheck_middleware(_app)
|
||||
utils.add_cors_middleware(_app)
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@ from openstack.baremetal.v1 import node
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_middleware import cors as cors_middleware
|
||||
from oslo_middleware import healthcheck as healthcheck_middleware
|
||||
import pytz
|
||||
import webob
|
||||
|
||||
@ -246,6 +247,14 @@ def add_cors_middleware(app):
|
||||
app.wsgi_app = cors_middleware.CORS(app.wsgi_app, CONF)
|
||||
|
||||
|
||||
def add_healthcheck_middleware(app):
|
||||
"""Add healthcheck middleware
|
||||
|
||||
:param app: application
|
||||
"""
|
||||
app.wsgi_app = healthcheck_middleware.Healthcheck(app.wsgi_app, CONF)
|
||||
|
||||
|
||||
def check_auth(request, rule=None, target=None):
|
||||
"""Check authentication on request.
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The new ``[healthcheck] enabled`` option has been added. When this option
|
||||
is set to ``True``, the healthcheck middleware is enabled in API pipeline
|
||||
and the additional API endpoint to monitor service availability becomes
|
||||
available at ``/healthcheck`` path.
|
@ -7,6 +7,7 @@ namespace = oslo.db
|
||||
namespace = oslo.log
|
||||
namespace = oslo.messaging
|
||||
namespace = oslo.middleware.cors
|
||||
namespace = oslo.middleware.healthcheck
|
||||
namespace = oslo.policy
|
||||
namespace = oslo.service.service
|
||||
namespace = oslo.service.sslutils
|
||||
|
Loading…
Reference in New Issue
Block a user