Skip to content

Commit fe08f7f

Browse files
authored
Merge pull request #4360 from sever-sever/T7190
T7190: Add haproxy default timeout options configurable
2 parents 7aa8222 + fe20eae commit fe08f7f

File tree

8 files changed

+147
-39
lines changed

8 files changed

+147
-39
lines changed

data/templates/load-balancing/haproxy.cfg.j2

+9-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ defaults
3838
log global
3939
mode http
4040
option dontlognull
41-
timeout connect 10s
42-
timeout client 50s
43-
timeout server 50s
41+
timeout check {{ timeout.check }}s
42+
timeout connect {{ timeout.connect }}s
43+
timeout client {{ timeout.client }}s
44+
timeout server {{ timeout.server }}s
4445
errorfile 400 /etc/haproxy/errors/400.http
4546
errorfile 403 /etc/haproxy/errors/403.http
4647
errorfile 408 /etc/haproxy/errors/408.http
@@ -134,6 +135,11 @@ frontend {{ front }}
134135
default_backend {{ backend }}
135136
{% endfor %}
136137
{% endif %}
138+
{% if front_config.timeout is vyos_defined %}
139+
{% if front_config.timeout.client is vyos_defined %}
140+
timeout client {{ front_config.timeout.client }}s
141+
{% endif %}
142+
{% endif %}
137143

138144
{% endfor %}
139145
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- include start from haproxy/timeout-check.xml.i -->
2+
<leafNode name="check">
3+
<properties>
4+
<help>Timeout in seconds for established connections</help>
5+
<valueHelp>
6+
<format>u32:1-3600</format>
7+
<description>Check timeout in seconds</description>
8+
</valueHelp>
9+
<constraint>
10+
<validator name="numeric" argument="--range 1-3600"/>
11+
</constraint>
12+
</properties>
13+
</leafNode>
14+
<!-- include end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- include start from haproxy/timeout-client.xml.i -->
2+
<leafNode name="client">
3+
<properties>
4+
<help>Maximum inactivity time on the client side</help>
5+
<valueHelp>
6+
<format>u32:1-3600</format>
7+
<description>Timeout in seconds</description>
8+
</valueHelp>
9+
<constraint>
10+
<validator name="numeric" argument="--range 1-3600"/>
11+
</constraint>
12+
</properties>
13+
</leafNode>
14+
<!-- include end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- include start from haproxy/timeout-connect.xml.i -->
2+
<leafNode name="connect">
3+
<properties>
4+
<help>Set the maximum time to wait for a connection attempt to a server to succeed</help>
5+
<valueHelp>
6+
<format>u32:1-3600</format>
7+
<description>Connect timeout in seconds</description>
8+
</valueHelp>
9+
<constraint>
10+
<validator name="numeric" argument="--range 1-3600"/>
11+
</constraint>
12+
</properties>
13+
</leafNode>
14+
<!-- include end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- include start from haproxy/timeout-server.xml.i -->
2+
<leafNode name="server">
3+
<properties>
4+
<help>Set the maximum inactivity time on the server side</help>
5+
<valueHelp>
6+
<format>u32:1-3600</format>
7+
<description>Server timeout in seconds</description>
8+
</valueHelp>
9+
<constraint>
10+
<validator name="numeric" argument="--range 1-3600"/>
11+
</constraint>
12+
</properties>
13+
</leafNode>
14+
<!-- include end -->

interface-definitions/include/haproxy/timeout.xml.i

+3-36
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,9 @@
44
<help>Timeout options</help>
55
</properties>
66
<children>
7-
<leafNode name="check">
8-
<properties>
9-
<help>Timeout in seconds for established connections</help>
10-
<valueHelp>
11-
<format>u32:1-3600</format>
12-
<description>Check timeout in seconds</description>
13-
</valueHelp>
14-
<constraint>
15-
<validator name="numeric" argument="--range 1-3600"/>
16-
</constraint>
17-
</properties>
18-
</leafNode>
19-
<leafNode name="connect">
20-
<properties>
21-
<help>Set the maximum time to wait for a connection attempt to a server to succeed</help>
22-
<valueHelp>
23-
<format>u32:1-3600</format>
24-
<description>Connect timeout in seconds</description>
25-
</valueHelp>
26-
<constraint>
27-
<validator name="numeric" argument="--range 1-3600"/>
28-
</constraint>
29-
</properties>
30-
</leafNode>
31-
<leafNode name="server">
32-
<properties>
33-
<help>Set the maximum inactivity time on the server side</help>
34-
<valueHelp>
35-
<format>u32:1-3600</format>
36-
<description>Server timeout in seconds</description>
37-
</valueHelp>
38-
<constraint>
39-
<validator name="numeric" argument="--range 1-3600"/>
40-
</constraint>
41-
</properties>
42-
</leafNode>
7+
#include <include/haproxy/timeout-check.xml.i>
8+
#include <include/haproxy/timeout-connect.xml.i>
9+
#include <include/haproxy/timeout-server.xml.i>
4310
</children>
4411
</node>
4512
<!-- include end -->

interface-definitions/load-balancing_haproxy.xml.in

+31
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
<valueless/>
4949
</properties>
5050
</leafNode>
51+
<node name="timeout">
52+
<properties>
53+
<help>Timeout options</help>
54+
</properties>
55+
<children>
56+
#include <include/haproxy/timeout-client.xml.i>
57+
</children>
58+
</node>
5159
<node name="http-compression">
5260
<properties>
5361
<help>Compress HTTP responses</help>
@@ -368,6 +376,29 @@
368376
</leafNode>
369377
</children>
370378
</node>
379+
<node name="timeout">
380+
<properties>
381+
<help>Timeout options</help>
382+
</properties>
383+
<children>
384+
#include <include/haproxy/timeout-check.xml.i>
385+
<leafNode name="check">
386+
<defaultValue>5</defaultValue>
387+
</leafNode>
388+
#include <include/haproxy/timeout-connect.xml.i>
389+
<leafNode name="connect">
390+
<defaultValue>10</defaultValue>
391+
</leafNode>
392+
#include <include/haproxy/timeout-client.xml.i>
393+
<leafNode name="client">
394+
<defaultValue>50</defaultValue>
395+
</leafNode>
396+
#include <include/haproxy/timeout-server.xml.i>
397+
<leafNode name="server">
398+
<defaultValue>50</defaultValue>
399+
</leafNode>
400+
</children>
401+
</node>
371402
#include <include/interface/vrf.xml.i>
372403
</children>
373404
</node>

smoketest/scripts/cli/test_load-balancing_haproxy.py

+48
Original file line numberDiff line numberDiff line change
@@ -521,5 +521,53 @@ def test_10_lb_reverse_proxy_http_compression(self):
521521
with self.assertRaises(ConfigSessionError) as e:
522522
self.cli_commit()
523523

524+
def test_11_lb_haproxy_timeout(self):
525+
t_default_check = '5'
526+
t_default_client = '50'
527+
t_default_connect = '10'
528+
t_default_server ='50'
529+
t_check = '4'
530+
t_client = '300'
531+
t_connect = '12'
532+
t_server ='120'
533+
t_front_client = '600'
534+
535+
self.base_config()
536+
self.cli_commit()
537+
# Check default timeout options
538+
config_entries = (
539+
f'timeout check {t_default_check}s',
540+
f'timeout connect {t_default_connect}s',
541+
f'timeout client {t_default_client}s',
542+
f'timeout server {t_default_server}s',
543+
)
544+
# Check default timeout options
545+
config = read_file(HAPROXY_CONF)
546+
for config_entry in config_entries:
547+
self.assertIn(config_entry, config)
548+
549+
# Set custom timeout options
550+
self.cli_set(base_path + ['timeout', 'check', t_check])
551+
self.cli_set(base_path + ['timeout', 'client', t_client])
552+
self.cli_set(base_path + ['timeout', 'connect', t_connect])
553+
self.cli_set(base_path + ['timeout', 'server', t_server])
554+
self.cli_set(base_path + ['service', 'https_front', 'timeout', 'client', t_front_client])
555+
556+
self.cli_commit()
557+
558+
# Check custom timeout options
559+
config_entries = (
560+
f'timeout check {t_check}s',
561+
f'timeout connect {t_connect}s',
562+
f'timeout client {t_client}s',
563+
f'timeout server {t_server}s',
564+
f'timeout client {t_front_client}s',
565+
)
566+
567+
# Check configured options
568+
config = read_file(HAPROXY_CONF)
569+
for config_entry in config_entries:
570+
self.assertIn(config_entry, config)
571+
524572
if __name__ == '__main__':
525573
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)