Merge ~hloeung/content-cache-charm:nginx-config into content-cache-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: c2df82e13a6e758af41227df96d95e15f135b223
Merged at revision: 6df560833781f16a441a0b42aa0e298671a24a33
Proposed branch: ~hloeung/content-cache-charm:nginx-config
Merge into: content-cache-charm:master
Diff against target: 137 lines (+24/-6)
7 files modified
config.yaml (+7/-0)
lib/nginx.py (+5/-1)
reactive/content_cache.py (+7/-1)
tests/unit/files/nginx_config_rendered_test_output-basic_site.txt (+1/-1)
tests/unit/files/nginx_config_rendered_test_output-token_site.txt (+1/-1)
tests/unit/test_content_cache.py (+2/-0)
tests/unit/test_nginx.py (+1/-2)
Reviewer Review Type Date Requested Status
Barry Price Approve
Canonical IS Reviewers Pending
Review via email: mp+396969@code.launchpad.net

Commit message

Allow overriding Nginx' proxy_cache_lock

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
Barry Price (barryprice) wrote :

Sure

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

Change successfully merged at revision 6df560833781f16a441a0b42aa0e298671a24a33

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/config.yaml b/config.yaml
index e634fe2..a7cd0e9 100644
--- a/config.yaml
+++ b/config.yaml
@@ -33,6 +33,13 @@ options:
33 background subrequest to update objects in cache. This works for33 background subrequest to update objects in cache. This works for
34 large objects, but can cause issues with sites updated recently34 large objects, but can cause issues with sites updated recently
35 to redirect and still have objects in the cache.35 to redirect and still have objects in the cache.
36 enable_cache_lock:
37 default: true
38 type: boolean
39 description: >
40 Default is to restrict to only one request at a time to populate
41 new cache elements from the backends. See Nginx'
42 proxy_cache_lock.
36 enable_prometheus_metrics:43 enable_prometheus_metrics:
37 default: true44 default: true
38 type: boolean45 type: boolean
diff --git a/lib/nginx.py b/lib/nginx.py
index 1b6289e..d880d72 100644
--- a/lib/nginx.py
+++ b/lib/nginx.py
@@ -24,7 +24,7 @@ PROXY_CACHE_DEFAULTS = {
2424
2525
26class NginxConf:26class NginxConf:
27 def __init__(self, conf_path=None, unit='content-cache', enable_cache_bg_update=True):27 def __init__(self, conf_path=None, unit='content-cache', enable_cache_bg_update=True, enable_cache_lock=True):
28 if not conf_path:28 if not conf_path:
29 conf_path = NGINX_BASE_PATH29 conf_path = NGINX_BASE_PATH
30 self.unit = unit30 self.unit = unit
@@ -32,6 +32,7 @@ class NginxConf:
32 self._base_path = conf_path32 self._base_path = conf_path
33 self._conf_path = os.path.join(self.base_path, 'conf.d')33 self._conf_path = os.path.join(self.base_path, 'conf.d')
34 self._enable_cache_bg_update = enable_cache_bg_update34 self._enable_cache_bg_update = enable_cache_bg_update
35 self._enable_cache_lock = enable_cache_lock
35 self._sites_path = os.path.join(self.base_path, 'sites-available')36 self._sites_path = os.path.join(self.base_path, 'sites-available')
3637
37 script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))38 script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
@@ -117,6 +118,9 @@ class NginxConf:
117 lc['cache-background-update'] = 'off'118 lc['cache-background-update'] = 'off'
118 lc['cache-use-stale'] = lc['cache-use-stale'].replace('updating ', '')119 lc['cache-use-stale'] = lc['cache-use-stale'].replace('updating ', '')
119120
121 if not self._enable_cache_lock:
122 lc['cache-lock'] = 'off'
123
120 cache_val = self.proxy_cache_configs['valid']124 cache_val = self.proxy_cache_configs['valid']
121 # Backwards compatibility125 # Backwards compatibility
122 if 'cache-validity' in lc:126 if 'cache-validity' in lc:
diff --git a/reactive/content_cache.py b/reactive/content_cache.py
index 8003f24..ddd0bfb 100644
--- a/reactive/content_cache.py
+++ b/reactive/content_cache.py
@@ -139,9 +139,15 @@ def configure_nginx(conf_path=None):
139 return139 return
140140
141 enable_cache_bg_update = config.get('enable_cache_background_update', True)141 enable_cache_bg_update = config.get('enable_cache_background_update', True)
142 enable_cache_lock = config.get('enable_cache_lock', True)
142 enable_prometheus_metrics = config.get('enable_prometheus_metrics')143 enable_prometheus_metrics = config.get('enable_prometheus_metrics')
143144
144 ngx_conf = nginx.NginxConf(conf_path, hookenv.local_unit(), enable_cache_bg_update=enable_cache_bg_update)145 ngx_conf = nginx.NginxConf(
146 conf_path,
147 hookenv.local_unit(),
148 enable_cache_bg_update=enable_cache_bg_update,
149 enable_cache_lock=enable_cache_lock,
150 )
145151
146 sites_secrets = secrets_from_config(config.get('sites_secrets'))152 sites_secrets = secrets_from_config(config.get('sites_secrets'))
147 blacklist_ports = [int(x.strip()) for x in config.get('blacklist_ports', '').split(',') if x.strip()]153 blacklist_ports = [int(x.strip()) for x in config.get('blacklist_ports', '').split(',') if x.strip()]
diff --git a/tests/unit/files/nginx_config_rendered_test_output-basic_site.txt b/tests/unit/files/nginx_config_rendered_test_output-basic_site.txt
index 98a3042..1e97ac9 100644
--- a/tests/unit/files/nginx_config_rendered_test_output-basic_site.txt
+++ b/tests/unit/files/nginx_config_rendered_test_output-basic_site.txt
@@ -21,7 +21,7 @@ server {
21 proxy_force_ranges on;21 proxy_force_ranges on;
22 proxy_cache e176ab9d1f16-cache;22 proxy_cache e176ab9d1f16-cache;
23 proxy_cache_background_update off;23 proxy_cache_background_update off;
24 proxy_cache_lock on;24 proxy_cache_lock off;
25 proxy_cache_min_uses 1;25 proxy_cache_min_uses 1;
26 proxy_cache_revalidate on;26 proxy_cache_revalidate on;
27 proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;27 proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
diff --git a/tests/unit/files/nginx_config_rendered_test_output-token_site.txt b/tests/unit/files/nginx_config_rendered_test_output-token_site.txt
index 21638c3..c265d8a 100644
--- a/tests/unit/files/nginx_config_rendered_test_output-token_site.txt
+++ b/tests/unit/files/nginx_config_rendered_test_output-token_site.txt
@@ -21,7 +21,7 @@ server {
21 proxy_force_ranges on;21 proxy_force_ranges on;
22 proxy_cache c27ba6753fee-cache;22 proxy_cache c27ba6753fee-cache;
23 proxy_cache_background_update off;23 proxy_cache_background_update off;
24 proxy_cache_lock on;24 proxy_cache_lock off;
25 proxy_cache_min_uses 1;25 proxy_cache_min_uses 1;
26 proxy_cache_revalidate on;26 proxy_cache_revalidate on;
27 proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;27 proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
diff --git a/tests/unit/test_content_cache.py b/tests/unit/test_content_cache.py
index 0d7e39f..6f52f08 100644
--- a/tests/unit/test_content_cache.py
+++ b/tests/unit/test_content_cache.py
@@ -203,6 +203,7 @@ class TestCharm(unittest.TestCase):
203 'cache_max_size': '1g',203 'cache_max_size': '1g',
204 'cache_path': '/var/lib/nginx/proxy',204 'cache_path': '/var/lib/nginx/proxy',
205 'enable_cache_background_update': True,205 'enable_cache_background_update': True,
206 'enable_cache_lock': True,
206 'enable_prometheus_metrics': False,207 'enable_prometheus_metrics': False,
207 'sites': ngx_config,208 'sites': ngx_config,
208 'worker_connections': 768,209 'worker_connections': 768,
@@ -1287,6 +1288,7 @@ site1.local:
1287 'cache_max_size': '1g',1288 'cache_max_size': '1g',
1288 'cache_path': '/var/lib/nginx/proxy',1289 'cache_path': '/var/lib/nginx/proxy',
1289 'enable_cache_background_update': False,1290 'enable_cache_background_update': False,
1291 'enable_cache_lock': False,
1290 'enable_prometheus_metrics': True,1292 'enable_prometheus_metrics': True,
1291 'sites': ngx_config,1293 'sites': ngx_config,
1292 'worker_connections': 768,1294 'worker_connections': 768,
diff --git a/tests/unit/test_nginx.py b/tests/unit/test_nginx.py
index 5ec7fbe..b76c674 100644
--- a/tests/unit/test_nginx.py
+++ b/tests/unit/test_nginx.py
@@ -126,7 +126,7 @@ class TestLibNginx(unittest.TestCase):
126126
127 def test_nginx_config_render_with_metrics(self):127 def test_nginx_config_render_with_metrics(self):
128 """Test rendering with metrics exposed."""128 """Test rendering with metrics exposed."""
129 ngx_conf = nginx.NginxConf(unit='mock-content-cache/0', enable_cache_bg_update=False)129 ngx_conf = nginx.NginxConf(unit='mock-content-cache/0', enable_cache_bg_update=False, enable_cache_lock=False)
130130
131 with open('tests/unit/files/config_test_basic_config.txt', 'r', encoding='utf-8') as f:131 with open('tests/unit/files/config_test_basic_config.txt', 'r', encoding='utf-8') as f:
132 sites = yaml.safe_load(f.read())132 sites = yaml.safe_load(f.read())
@@ -137,7 +137,6 @@ class TestLibNginx(unittest.TestCase):
137 'cache_inactive_time': '2h',137 'cache_inactive_time': '2h',
138 'cache_max_size': '1g',138 'cache_max_size': '1g',
139 'cache_path': '/var/lib/nginx/proxy',139 'cache_path': '/var/lib/nginx/proxy',
140 'enable_cache_background_update': False,
141 'enable_prometheus_metrics': True,140 'enable_prometheus_metrics': True,
142 'listen_address': '127.0.0.1',141 'listen_address': '127.0.0.1',
143 }142 }

Subscribers

People subscribed via source and target branches