Deploy healthcheck middleware as app instead of filter

Using the healthcheck middleware as a filter is deprecated and
the middleware should be used as an application[1].
 [1] 6feaa13610c450c8486f969703768db5319b4846

This change updates definition and usage of the healthcheck middleware
accordingly to avoid the following deprecation warning.

DeprecationWarning: Using function/method 'Healthcheck.factory()' is
deprecated: The healthcheck middleware must now be configured as
an application, not as a filter.

Change-Id: Ie81140d3b03c315f0a057d2f59754ee14dac539c
This commit is contained in:
Takashi Kajinami 2021-08-18 23:42:41 +09:00
parent 68e6c0e48d
commit ce217a287c
7 changed files with 63 additions and 25 deletions

View File

@ -35,20 +35,22 @@ Healthcheck Middleware
This piece of middleware creates an endpoint that allows a load balancer
to probe if the API endpoint should be available at the node or not.
The healthcheck middleware should be placed early in the pipeline. Which
is located in your ``api-paste.ini`` under a section called
``[filter:healthcheck]``. It should look like this::
The healthcheck middleware should be deployed as a paste application
application. Which is located in your ``api-paste.ini`` under a section called
``[app:healthcheck]``. It should look like this::
[filter:healthcheck]
paste.filter_factory = oslo_middleware:Healthcheck.factory
[app:healthcheck]
paste.app_factory = oslo_middleware:Healthcheck.app_factory
backends = disable_by_file
disable_by_file_path = /etc/magnum/healthcheck_disable
The main pipeline using this filter should look something like this also
The main pipeline using this application should look something like this also
defined in the ``api-paste.ini``::
[pipeline:main]
pipeline = cors healthcheck request_id authtoken api_v1
[composite:main]
paste.composite_factory = magnum.api:root_app_factory
/: api
/healthcheck: healthcheck
If you wish to disable a middleware without taking it out of the
pipeline, you can create a file under the file path defined by

View File

@ -1,5 +1,10 @@
[pipeline:main]
pipeline = cors healthcheck http_proxy_to_wsgi request_id osprofiler authtoken api_v1
[composite:main]
paste.composite_factory = magnum.api:root_app_factory
/: api
/healthcheck: healthcheck
[pipeline:api]
pipeline = cors http_proxy_to_wsgi request_id osprofiler authtoken api_v1
[app:api_v1]
paste.app_factory = magnum.api.app:app_factory
@ -18,8 +23,8 @@ paste.filter_factory = oslo_middleware:RequestId.factory
paste.filter_factory = oslo_middleware.cors:filter_factory
oslo_config_project = magnum
[filter:healthcheck]
paste.filter_factory = oslo_middleware:Healthcheck.factory
[app:healthcheck]
paste.app_factory = oslo_middleware:Healthcheck.app_factory
backends = disable_by_file
disable_by_file_path = /etc/magnum/healthcheck_disable

View File

@ -0,0 +1,16 @@
# 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.
import paste.urlmap
def root_app_factory(loader, global_conf, **local_conf):
return paste.urlmap.urlmap_factory(loader, global_conf, **local_conf)

View File

@ -1,5 +1,10 @@
[pipeline:main]
pipeline = cors healthcheck request_id authtoken api_v1
[composite:main]
paste.composite_factory = magnum.api:root_app_factory
/: api
/healthcheck: healthcheck
[pipeline:api]
pipeline = cors request_id authtoken api_v1
[app:api_v1]
paste.app_factory = magnum.api.app:app_factory
@ -14,7 +19,7 @@ paste.filter_factory = oslo_middleware:RequestId.factory
paste.filter_factory = oslo_middleware.cors:filter_factory
oslo_config_project = magnum
[filter:healthcheck]
paste.filter_factory = oslo_middleware:Healthcheck.factory
[app:healthcheck]
paste.app_factory = oslo_middleware:Healthcheck.app_factory
backends = disable_by_file
disable_by_file_path = /tmp/magnum_healthcheck_disable

View File

@ -1,5 +1,10 @@
[pipeline:main]
pipeline = cors healthcheck request_id authtoken api_v1
[composite:main]
paste.composite_factory = magnum.api:root_app_factory
/: api
/healthcheck: healthcheck
[pipeline:api]
pipeline = cors request_id authtoken api_v1
[app:api_v1]
paste.app_factory = magnum.api.app:app_factory
@ -15,7 +20,7 @@ paste.filter_factory = oslo_middleware:RequestId.factory
paste.filter_factory = oslo_middleware.cors:filter_factory
oslo_config_project = magnum
[filter:healthcheck]
paste.filter_factory = oslo_middleware:Healthcheck.factory
[app:healthcheck]
paste.app_factory = oslo_middleware:Healthcheck.app_factory
backends = disable_by_file
disable_by_file_path = /tmp/magnum_healthcheck_disable

View File

@ -1,5 +1,10 @@
[pipeline:main]
pipeline = cors healthcheck request_id authtoken api_v1
[composite:main]
paste.composite_factory = magnum.api:root_app_factory
/: api
/healthcheck: healthcheck
[pipeline:api]
pipeline = cors request_id authtoken api_v1
[app:api_v1]
paste.app_factory = magnum.api.app:app_factory
@ -15,7 +20,7 @@ paste.filter_factory = oslo_middleware:RequestId.factory
paste.filter_factory = oslo_middleware.cors:filter_factory
oslo_config_project = magnum
[filter:healthcheck]
paste.filter_factory = oslo_middleware:Healthcheck.factory
[app:healthcheck]
paste.app_factory = oslo_middleware:Healthcheck.app_factory
backends = disable_by_file
disable_by_file_path = /tmp/magnum_healthcheck_disable

View File

@ -195,7 +195,7 @@ class TestHeathcheck(api_base.FunctionalTest):
# Read current file and create new one
config = ConfigParser.RawConfigParser()
config.read(self.get_path(paste_ini))
config.set('filter:healthcheck',
config.set('app:healthcheck',
'disable_by_file_path',
self.tempdir + "/disable")
with open(self.tempdir + "/paste.ini", 'wt') as configfile: