Merge ~hloeung/content-cache-charm:tuning into content-cache-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 999a12c49ad90dc077f5a29c9ed94f35dbc6bb8a
Merged at revision: da7fc36d4993b272e6547ff8fa49e00e83c94b8b
Proposed branch: ~hloeung/content-cache-charm:tuning
Merge into: content-cache-charm:master
Diff against target: 201 lines (+27/-16)
11 files modified
config.yaml (+6/-0)
lib/haproxy.py (+3/-1)
reactive/content_cache.py (+3/-1)
templates/haproxy_cfg.tmpl (+2/-2)
tests/unit/files/content_cache_rendered_haproxy_test_output.txt (+1/-1)
tests/unit/files/content_cache_rendered_haproxy_test_output2.txt (+1/-1)
tests/unit/files/content_cache_rendered_haproxy_test_output3.txt (+1/-1)
tests/unit/files/content_cache_rendered_haproxy_test_output_auto_maxconns.txt (+1/-1)
tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads.txt (+1/-1)
tests/unit/files/haproxy_config_rendered_test_output.txt (+2/-2)
tests/unit/test_content_cache.py (+6/-5)
Reviewer Review Type Date Requested Status
Joel Sing (community) +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+388020@code.launchpad.net

Commit message

Allow overriding HAProxy's hard-stop-after config

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Joel Sing (jsing) wrote :

LGTM

review: Approve (+1)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision da7fc36d4993b272e6547ff8fa49e00e83c94b8b

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index 9bf105b..7030778 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -31,6 +31,12 @@ options:
6 description: >
7 Export metrics for the number of requests and the number of cache hits.
8 Prometheus metrics are exposed at /metrics on port 9145.
9+ haproxy_hard_stop_after:
10+ default: "5m"
11+ type: string
12+ description: >
13+ Tune HAProxy's hard-stop-after to prevent lingering HAProxy processes
14+ (LP:1874386).
15 haproxy_processes:
16 default: 0
17 type: int
18diff --git a/lib/haproxy.py b/lib/haproxy.py
19index 544ac08..be0b101 100644
20--- a/lib/haproxy.py
21+++ b/lib/haproxy.py
22@@ -15,9 +15,10 @@ TLS_CIPHER_SUITES = 'ECDHE+AESGCM:ECDHE+AES256:ECDHE+AES128:!SSLv3:!TLSv1'
23
24
25 class HAProxyConf:
26- def __init__(self, conf_path=HAPROXY_BASE_PATH, max_connections=0):
27+ def __init__(self, conf_path=HAPROXY_BASE_PATH, max_connections=0, hard_stop_after='5m'):
28 self._conf_path = conf_path
29 self.max_connections = int(max_connections)
30+ self.hard_stop_after = hard_stop_after
31
32 @property
33 def conf_path(self):
34@@ -291,6 +292,7 @@ backend backend-{name}
35 {
36 'backend': self.render_stanza_backend(config),
37 'global_max_connections': global_max_connections,
38+ 'hard_stop_after': self.hard_stop_after,
39 'listen': listen_stanzas,
40 'max_connections': max_connections,
41 'monitoring_password': monitoring_password or self.monitoring_password,
42diff --git a/reactive/content_cache.py b/reactive/content_cache.py
43index 6e106d6..2857aea 100644
44--- a/reactive/content_cache.py
45+++ b/reactive/content_cache.py
46@@ -204,7 +204,9 @@ def configure_haproxy(): # NOQA: C901 LP#1825084
47 status.blocked('requires list of sites to configure')
48 return
49
50- haproxy = HAProxy.HAProxyConf(max_connections=config.get('max_connections', 0))
51+ max_connections = config.get('max_connections', 0)
52+ hard_stop_after = config.get('haproxy_hard_stop_after')
53+ haproxy = HAProxy.HAProxyConf(max_connections=max_connections, hard_stop_after=hard_stop_after)
54 sites_secrets = secrets_from_config(config.get('sites_secrets'))
55 blacklist_ports = [int(x.strip()) for x in config.get('blacklist_ports', '').split(',') if x.strip()]
56 sites = sites_from_config(config.get('sites'), sites_secrets, blacklist_ports=blacklist_ports)
57diff --git a/templates/haproxy_cfg.tmpl b/templates/haproxy_cfg.tmpl
58index 640cb7e..e3657f3 100644
59--- a/templates/haproxy_cfg.tmpl
60+++ b/templates/haproxy_cfg.tmpl
61@@ -16,8 +16,8 @@ global
62 daemon
63
64 # LP#1874386: Work around lingering HAProxy processes as per LP:1874386
65- # and kill them off after 15mins.
66- hard-stop-after 15m
67+ # and kill them off.
68+ hard-stop-after {{hard_stop_after}}
69
70 # Default SSL material locations
71 ca-base /etc/ssl/certs
72diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output.txt
73index 41e3559..199199b 100644
74--- a/tests/unit/files/content_cache_rendered_haproxy_test_output.txt
75+++ b/tests/unit/files/content_cache_rendered_haproxy_test_output.txt
76@@ -11,7 +11,7 @@ global
77 daemon
78
79 # LP#1874386: Work around lingering HAProxy processes as per LP:1874386
80- # and kill them off after 15mins.
81+ # and kill them off.
82 hard-stop-after 15m
83
84 # Default SSL material locations
85diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output2.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output2.txt
86index ca59e11..fb204d4 100644
87--- a/tests/unit/files/content_cache_rendered_haproxy_test_output2.txt
88+++ b/tests/unit/files/content_cache_rendered_haproxy_test_output2.txt
89@@ -11,7 +11,7 @@ global
90 daemon
91
92 # LP#1874386: Work around lingering HAProxy processes as per LP:1874386
93- # and kill them off after 15mins.
94+ # and kill them off.
95 hard-stop-after 15m
96
97 # Default SSL material locations
98diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output3.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output3.txt
99index 2e1bc57..252e863 100644
100--- a/tests/unit/files/content_cache_rendered_haproxy_test_output3.txt
101+++ b/tests/unit/files/content_cache_rendered_haproxy_test_output3.txt
102@@ -11,7 +11,7 @@ global
103 daemon
104
105 # LP#1874386: Work around lingering HAProxy processes as per LP:1874386
106- # and kill them off after 15mins.
107+ # and kill them off.
108 hard-stop-after 15m
109
110 # Default SSL material locations
111diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output_auto_maxconns.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output_auto_maxconns.txt
112index 7856924..bbde51b 100644
113--- a/tests/unit/files/content_cache_rendered_haproxy_test_output_auto_maxconns.txt
114+++ b/tests/unit/files/content_cache_rendered_haproxy_test_output_auto_maxconns.txt
115@@ -11,7 +11,7 @@ global
116 daemon
117
118 # LP#1874386: Work around lingering HAProxy processes as per LP:1874386
119- # and kill them off after 15mins.
120+ # and kill them off.
121 hard-stop-after 15m
122
123 # Default SSL material locations
124diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads.txt
125index b961ed1..8748683 100644
126--- a/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads.txt
127+++ b/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads.txt
128@@ -12,7 +12,7 @@ global
129 daemon
130
131 # LP#1874386: Work around lingering HAProxy processes as per LP:1874386
132- # and kill them off after 15mins.
133+ # and kill them off.
134 hard-stop-after 15m
135
136 # Default SSL material locations
137diff --git a/tests/unit/files/haproxy_config_rendered_test_output.txt b/tests/unit/files/haproxy_config_rendered_test_output.txt
138index 74f79fc..3b77c93 100644
139--- a/tests/unit/files/haproxy_config_rendered_test_output.txt
140+++ b/tests/unit/files/haproxy_config_rendered_test_output.txt
141@@ -12,8 +12,8 @@ global
142 daemon
143
144 # LP#1874386: Work around lingering HAProxy processes as per LP:1874386
145- # and kill them off after 15mins.
146- hard-stop-after 15m
147+ # and kill them off.
148+ hard-stop-after 5m
149
150 # Default SSL material locations
151 ca-base /etc/ssl/certs
152diff --git a/tests/unit/test_content_cache.py b/tests/unit/test_content_cache.py
153index 9b1d6cf..4807684 100644
154--- a/tests/unit/test_content_cache.py
155+++ b/tests/unit/test_content_cache.py
156@@ -388,7 +388,7 @@ site1.local:
157 def test_configure_haproxy_sites(self, logrotation, set_flag, opened_ports):
158 with open('tests/unit/files/config_test_config.txt', 'r', encoding='utf-8') as f:
159 config = f.read()
160- self.mock_config.return_value = {'max_connections': 8192, 'sites': config}
161+ self.mock_config.return_value = {'haproxy_hard_stop_after': '15m', 'max_connections': 8192, 'sites': config}
162
163 with mock.patch('lib.haproxy.HAProxyConf.conf_file', new_callable=mock.PropertyMock) as mock_conf_file:
164 mock_conf_file.return_value = os.path.join(self.tmpdir, 'haproxy.cfg')
165@@ -416,7 +416,7 @@ site1.local:
166 backends: ['192.168.1.1:8080']
167 tls-cert-bundle-path: /var/lib/haproxy/certs
168 '''
169- self.mock_config.return_value = {'max_connections': 8192, 'sites': config}
170+ self.mock_config.return_value = {'haproxy_hard_stop_after': '15m', 'max_connections': 8192, 'sites': config}
171 with mock.patch('lib.haproxy.HAProxyConf.conf_file', new_callable=mock.PropertyMock) as mock_conf_file:
172 mock_conf_file.return_value = os.path.join(self.tmpdir, 'haproxy.cfg')
173 opened_ports.return_value = ['443/tcp']
174@@ -442,7 +442,7 @@ site1.local:
175 redirect-http-to-https: True
176 tls-cert-bundle-path: /var/lib/haproxy/certs
177 '''
178- self.mock_config.return_value = {'max_connections': 8192, 'sites': config}
179+ self.mock_config.return_value = {'haproxy_hard_stop_after': '15m', 'max_connections': 8192, 'sites': config}
180 with mock.patch('lib.haproxy.HAProxyConf.conf_file', new_callable=mock.PropertyMock) as mock_conf_file:
181 mock_conf_file.return_value = os.path.join(self.tmpdir, 'haproxy.cfg')
182 opened_ports.return_value = ['443/tcp']
183@@ -460,8 +460,8 @@ site1.local:
184 @mock.patch('reactive.content_cache.update_logrotate')
185 def test_configure_haproxy_sites_auto_maxconns(self, logrotation, set_flag, opened_ports):
186 with open('tests/unit/files/config_test_config.txt', 'r', encoding='utf-8') as f:
187- ngx_config = f.read()
188- self.mock_config.return_value = {'max_connections': 0, 'sites': ngx_config}
189+ config = f.read()
190+ self.mock_config.return_value = {'haproxy_hard_stop_after': '15m', 'max_connections': 0, 'sites': config}
191
192 with mock.patch('lib.haproxy.HAProxyConf.conf_file', new_callable=mock.PropertyMock) as mock_conf_file:
193 mock_conf_file.return_value = os.path.join(self.tmpdir, 'haproxy.cfg')
194@@ -486,6 +486,7 @@ site1.local:
195 with open('tests/unit/files/config_test_config.txt', 'r', encoding='utf-8') as f:
196 ngx_config = f.read()
197 self.mock_config.return_value = {
198+ 'haproxy_hard_stop_after': '15m',
199 'haproxy_processes': 3,
200 'haproxy_threads': 10,
201 'max_connections': 0,

Subscribers

People subscribed via source and target branches