Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 875abeb

Browse files
committed
add maxconn to all the frontend section
1 parent 5dde93f commit 875abeb

3 files changed

Lines changed: 43 additions & 26 deletions

File tree

haproxy/helper/frontend_helper.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,27 @@ def config_common_part(port, ssl_bind_string, vhosts):
9494
frontend_section = []
9595
bind_string, ssl = get_bind_string(port, ssl_bind_string, vhosts)
9696
frontend_section.append("bind :%s" % bind_string)
97+
98+
# add x-forwarded-porto header
9799
if ssl:
98100
frontend_section.append("reqadd X-Forwarded-Proto:\ https")
99101
else:
100102
frontend_section.append("reqadd X-Forwarded-Proto:\ http")
101-
if EXTRA_FRONTEND_SETTINGS and port in EXTRA_FRONTEND_SETTINGS:
102-
frontend_section.extend(EXTRA_FRONTEND_SETTINGS[port])
103103

104-
# add websocket acl rule
105-
frontend_section.append("acl is_websocket hdr(Upgrade) -i WebSocket")
104+
# add maxconn
105+
frontend_section.append("maxconn %s" % MAXCONN)
106106

107107
# add monitor uri
108108
if port == MONITOR_PORT and MONITOR_URI:
109109
frontend_section.append("monitor-uri %s" % MONITOR_URI)
110110
monitor_uri_configured = True
111+
112+
# add extra frontend setting
113+
if EXTRA_FRONTEND_SETTINGS and port in EXTRA_FRONTEND_SETTINGS:
114+
frontend_section.extend(EXTRA_FRONTEND_SETTINGS[port])
115+
116+
# add websocket acl rule
117+
frontend_section.append("acl is_websocket hdr(Upgrade) -i WebSocket")
111118
return frontend_section, monitor_uri_configured
112119

113120

@@ -129,27 +136,29 @@ def config_default_frontend(ssl_bind_string):
129136
cfg = OrderedDict()
130137
monitor_uri_configured = False
131138
frontend = [("bind :80 %s" % EXTRA_BIND_SETTINGS.get('80', "")).strip(),
132-
"reqadd X-Forwarded-Proto:\ http"]
133-
if "80" in EXTRA_FRONTEND_SETTINGS:
134-
frontend.extend(EXTRA_FRONTEND_SETTINGS["80"])
139+
"reqadd X-Forwarded-Proto:\ http", "maxconn %s" % MAXCONN]
140+
135141
if MONITOR_URI and MONITOR_PORT == '80':
136142
frontend.append("monitor-uri %s" % MONITOR_URI)
137143
monitor_uri_configured = True
138144

139-
frontend.append("maxconn %s" % MAXCONN)
145+
if "80" in EXTRA_FRONTEND_SETTINGS:
146+
frontend.extend(EXTRA_FRONTEND_SETTINGS["80"])
147+
140148
frontend.append("default_backend default_service")
141149
cfg["frontend default_port_80"] = frontend
142150

143151
if ssl_bind_string:
144152
ssl_frontend = [("bind :443 %s %s" % (ssl_bind_string, EXTRA_BIND_SETTINGS.get('443', ""))).strip(),
145-
"reqadd X-Forwarded-Proto:\ https"]
146-
if "443" in EXTRA_FRONTEND_SETTINGS:
147-
ssl_frontend.extend(EXTRA_FRONTEND_SETTINGS["443"])
153+
"reqadd X-Forwarded-Proto:\ https", "maxconn %s" % MAXCONN]
154+
148155
if MONITOR_URI and (MONITOR_PORT == '443'):
149156
ssl_frontend.append("monitor-uri %s" % MONITOR_URI)
150157
monitor_uri_configured = True
151158

152-
ssl_frontend.append("maxconn %s" % MAXCONN)
159+
if "443" in EXTRA_FRONTEND_SETTINGS:
160+
ssl_frontend.extend(EXTRA_FRONTEND_SETTINGS["443"])
161+
153162
ssl_frontend.append("default_backend default_service")
154163
cfg["frontend default_port_443"] = ssl_frontend
155164

tests/unit/helper/test_frontend_helper.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_config_frontend_with_virtual_host_without_monitoring_uri_added(self):
3030
cfg, monitor_uri_configured = config_frontend_with_virtual_host(vhosts, "ssl crt /certs/")
3131
result = OrderedDict([('frontend port_80', ['bind :80',
3232
'reqadd X-Forwarded-Proto:\\ http',
33+
'maxconn 55555',
3334
'acl is_websocket hdr(Upgrade) -i WebSocket',
3435
'acl host_rule_1 hdr(host) -i a.com',
3536
'acl host_rule_1_port hdr(host) -i a.com:80',
@@ -42,6 +43,7 @@ def test_config_frontend_with_virtual_host_with_path_rules(self):
4243
cfg, monitor_uri_configured = config_frontend_with_virtual_host(vhosts, "ssl crt /certs/")
4344
result = OrderedDict([('frontend port_80', ['bind :80',
4445
'reqadd X-Forwarded-Proto:\\ http',
46+
'maxconn 55555',
4547
'acl is_websocket hdr(Upgrade) -i WebSocket',
4648
'acl host_rule_1 hdr_reg(host) -i ^.*$',
4749
'acl host_rule_1_port hdr_reg(host) -i ^.*:80$',
@@ -57,8 +59,9 @@ def test_config_frontend_with_virtual_host_with_monitoring_uri_added(self):
5759
result = OrderedDict([('frontend port_9999',
5860
['bind :9999',
5961
'reqadd X-Forwarded-Proto:\\ http',
60-
'acl is_websocket hdr(Upgrade) -i WebSocket',
62+
'maxconn 55555',
6163
'monitor-uri /ping',
64+
'acl is_websocket hdr(Upgrade) -i WebSocket',
6265
'acl host_rule_1 hdr(host) -i a.com',
6366
'acl host_rule_1_port hdr(host) -i a.com:9999',
6467
'use_backend SERVICE_web-a if host_rule_1 or host_rule_1_port'])])
@@ -130,15 +133,18 @@ def test_config_common_part_with_ssl(self, mock_get_bind_string):
130133
mock_get_bind_string.return_value = ("443 ssl crt /certs/", True)
131134
frontend_section, monitor_uri_configured = config_common_part("443", "ssl crt /certs/", [])
132135
self.assertEqual(
133-
["bind :443 ssl crt /certs/", "reqadd X-Forwarded-Proto:\ https", "acl is_websocket hdr(Upgrade) -i WebSocket"],
136+
["bind :443 ssl crt /certs/", "reqadd X-Forwarded-Proto:\ https",
137+
"acl is_websocket hdr(Upgrade) -i WebSocket"],
134138
frontend_section)
135139
self.assertFalse(monitor_uri_configured)
136140

137141
@mock.patch("haproxy.helper.frontend_helper.get_bind_string")
138142
def test_config_common_part_without_ssl(self, mock_get_bind_string):
139143
mock_get_bind_string.return_value = ("80", False)
140144
frontend_section, monitor_uri_configured = config_common_part("80", "ssl crt /certs/", [])
141-
self.assertEqual(["bind :80", 'reqadd X-Forwarded-Proto:\\ http',
145+
self.assertEqual(["bind :80",
146+
'reqadd X-Forwarded-Proto:\\ http',
147+
"maxconn 55555",
142148
"acl is_websocket hdr(Upgrade) -i WebSocket"],
143149
frontend_section)
144150
self.assertFalse(monitor_uri_configured)
@@ -147,8 +153,11 @@ def test_config_common_part_without_ssl(self, mock_get_bind_string):
147153
def test_config_common_part_with_ssl(self, mock_get_bind_string):
148154
mock_get_bind_string.return_value = ("9999 ssl crt /certs/", True)
149155
frontend_section, monitor_uri_configured = config_common_part("9999", "ssl crt /certs/", [])
150-
self.assertEqual(["bind :9999 ssl crt /certs/", "reqadd X-Forwarded-Proto:\ https",
151-
"acl is_websocket hdr(Upgrade) -i WebSocket", "monitor-uri %s" % frontend_helper.MONITOR_URI],
156+
self.assertEqual(["bind :9999 ssl crt /certs/",
157+
"reqadd X-Forwarded-Proto:\ https",
158+
'maxconn 55555',
159+
"monitor-uri %s" % frontend_helper.MONITOR_URI,
160+
"acl is_websocket hdr(Upgrade) -i WebSocket"],
152161
frontend_section)
153162
self.assertTrue(monitor_uri_configured)
154163

@@ -168,6 +177,7 @@ def test_config_common_part_with_extra_frontend_sttings(self, mock_get_bind_stri
168177
frontend_helper.EXTRA_FRONTEND_SETTINGS = {'80': ["reqadd header1 value1", "reqadd header2 value2"]}
169178
frontend_section, monitor_uri_configured = config_common_part("80", "ssl crt /certs/", [])
170179
self.assertEqual(["bind :80", 'reqadd X-Forwarded-Proto:\\ http',
180+
'maxconn 55555',
171181
'reqadd header1 value1',
172182
'reqadd header2 value2',
173183
"acl is_websocket hdr(Upgrade) -i WebSocket"],
@@ -229,8 +239,9 @@ def test_config_default_front(self):
229239
self.assertEqual(OrderedDict([('frontend default_port_80',
230240
['bind :80',
231241
'reqadd X-Forwarded-Proto:\\ http',
242+
'maxconn 55555',
232243
'monitor-uri /ping',
233-
'maxconn 55555', 'default_backend default_service'])]), cfg)
244+
'default_backend default_service'])]), cfg)
234245
self.assertTrue(monitor_uri_configured)
235246

236247
frontend_helper.MONITOR_PORT = "443"
@@ -244,8 +255,8 @@ def test_config_default_front(self):
244255
('frontend default_port_443',
245256
['bind :443 ssl crt /certs/ accept-proxy',
246257
'reqadd X-Forwarded-Proto:\\ https',
247-
'monitor-uri /ping',
248258
'maxconn 55555',
259+
'monitor-uri /ping',
249260
'default_backend default_service'])]), cfg)
250261
self.assertTrue(monitor_uri_configured)
251262

@@ -254,19 +265,18 @@ def test_config_default_front(self):
254265
self.assertEqual(OrderedDict([('frontend default_port_80',
255266
['bind :80',
256267
'reqadd X-Forwarded-Proto:\\ http',
257-
'reqadd header1 value1',
258268
'maxconn 55555',
269+
'reqadd header1 value1',
259270
'default_backend default_service']),
260271
('frontend default_port_443',
261272
['bind :443 ssl crt /certs/ accept-proxy',
262273
'reqadd X-Forwarded-Proto:\\ https',
263-
'reqadd header2 value2',
264-
'monitor-uri /ping',
265274
'maxconn 55555',
275+
'monitor-uri /ping',
276+
'reqadd header2 value2',
266277
'default_backend default_service'])]), cfg)
267278
self.assertTrue(monitor_uri_configured)
268279

269-
270280
def test_config_common_part_with_monitor_uri(self):
271281
self.assertEqual(OrderedDict(), config_monitor_frontend(True))
272282
self.assertEqual(OrderedDict([('frontend monitor', ['bind :9999', 'monitor-uri /ping'])]),
@@ -278,6 +288,3 @@ def test_config_common_part_with_monitor_uri(self):
278288
frontend_helper.MONITOR_PORT = "3333"
279289
self.assertEqual(OrderedDict([('frontend monitor', ['bind :3333', 'monitor-uri /ping'])]),
280290
config_monitor_frontend(False))
281-
282-
frontend_helper.MONITOR_PORT = "3333"
283-
frontend_helper.MONITOR_URI = ""

tests/unit/test_haproxycfg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ def test_config_frontend_sections(self, mock_init, mock_details, mock_services,
285285
self.assertEqual(OrderedDict([('frontend port_80',
286286
['bind :80',
287287
'reqadd X-Forwarded-Proto:\\ http',
288+
'maxconn 4096',
288289
'acl is_websocket hdr(Upgrade) -i WebSocket',
289290
'acl host_rule_1 hdr(host) -i a.com',
290291
'acl host_rule_1_port hdr(host) -i a.com:80',

0 commit comments

Comments
 (0)