Enable HAProxy HTTP Health Checks

Ceph radosgw supports [0] the swift health check endpoint
"/swift/healthcheck". This change adds the haproxy
configuration [1] necessary to take the response of "GET
/swift/healthcheck" into account when determining the health
of a radosgw service.

For testing, I verified that:
- HAProxy starts and responds to requests normally with this
  configuration.
- Servers with status != 2xx or 3xx are removed from the
  backend.
- Servers that take too long to respond are also removed
  from the backend. The default timeout value is 2s.

[0] https://tracker.ceph.com/issues/11682
[1] https://www.haproxy.com/documentation/hapee/2-0r1/onepage/#4.2-option%20httpchk

Closes-Bug: 1946280
Change-Id: I82634255ca3423fec3fc15c1e714dcb31db5da7a
(cherry picked from commit 31a4584169)
This commit is contained in:
Cornellius Metto 2021-11-11 16:03:13 +00:00 committed by Jorge Merlino
parent 020384fecc
commit 6c725f1335
2 changed files with 17 additions and 2 deletions

View File

@ -22,6 +22,7 @@ from charmhelpers.contrib.openstack import context
from charmhelpers.contrib.hahelpers.cluster import (
determine_api_port,
determine_apache_port,
https,
)
from charmhelpers.core.host import (
cmp_pkgrevno,
@ -68,12 +69,13 @@ class HAProxyContext(context.HAProxyContext):
def __call__(self):
ctxt = super(HAProxyContext, self).__call__()
port = utils.listen_port()
service = 'cephradosgw-server'
# Apache ports
a_cephradosgw_api = determine_apache_port(port, singlenode_mode=True)
port_mapping = {
'cephradosgw-server': [port, a_cephradosgw_api]
service: [port, a_cephradosgw_api]
}
ctxt['cephradosgw_bind_port'] = determine_api_port(
@ -82,7 +84,16 @@ class HAProxyContext(context.HAProxyContext):
)
# for haproxy.conf
backend_options = {
service: [{
'option': 'httpchk GET /swift/healthcheck',
}]
}
ctxt['service_ports'] = port_mapping
ctxt['backend_options'] = backend_options
ctxt['https'] = https()
return ctxt

View File

@ -63,7 +63,11 @@ class HAProxyContextTests(CharmTestCase):
self.determine_api_port.return_value = 70
expect = {
'cephradosgw_bind_port': 70,
'service_ports': {'cephradosgw-server': [80, 70]}
'service_ports': {'cephradosgw-server': [80, 70]},
'backend_options': {'cephradosgw-server': [{
'option': 'httpchk GET /swift/healthcheck',
}]},
'https': False
}
self.assertEqual(expect, haproxy_context())