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
1diff --git a/config.yaml b/config.yaml
2index e634fe2..a7cd0e9 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -33,6 +33,13 @@ options:
6 background subrequest to update objects in cache. This works for
7 large objects, but can cause issues with sites updated recently
8 to redirect and still have objects in the cache.
9+ enable_cache_lock:
10+ default: true
11+ type: boolean
12+ description: >
13+ Default is to restrict to only one request at a time to populate
14+ new cache elements from the backends. See Nginx'
15+ proxy_cache_lock.
16 enable_prometheus_metrics:
17 default: true
18 type: boolean
19diff --git a/lib/nginx.py b/lib/nginx.py
20index 1b6289e..d880d72 100644
21--- a/lib/nginx.py
22+++ b/lib/nginx.py
23@@ -24,7 +24,7 @@ PROXY_CACHE_DEFAULTS = {
24
25
26 class NginxConf:
27- def __init__(self, conf_path=None, unit='content-cache', enable_cache_bg_update=True):
28+ def __init__(self, conf_path=None, unit='content-cache', enable_cache_bg_update=True, enable_cache_lock=True):
29 if not conf_path:
30 conf_path = NGINX_BASE_PATH
31 self.unit = unit
32@@ -32,6 +32,7 @@ class NginxConf:
33 self._base_path = conf_path
34 self._conf_path = os.path.join(self.base_path, 'conf.d')
35 self._enable_cache_bg_update = enable_cache_bg_update
36+ self._enable_cache_lock = enable_cache_lock
37 self._sites_path = os.path.join(self.base_path, 'sites-available')
38
39 script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
40@@ -117,6 +118,9 @@ class NginxConf:
41 lc['cache-background-update'] = 'off'
42 lc['cache-use-stale'] = lc['cache-use-stale'].replace('updating ', '')
43
44+ if not self._enable_cache_lock:
45+ lc['cache-lock'] = 'off'
46+
47 cache_val = self.proxy_cache_configs['valid']
48 # Backwards compatibility
49 if 'cache-validity' in lc:
50diff --git a/reactive/content_cache.py b/reactive/content_cache.py
51index 8003f24..ddd0bfb 100644
52--- a/reactive/content_cache.py
53+++ b/reactive/content_cache.py
54@@ -139,9 +139,15 @@ def configure_nginx(conf_path=None):
55 return
56
57 enable_cache_bg_update = config.get('enable_cache_background_update', True)
58+ enable_cache_lock = config.get('enable_cache_lock', True)
59 enable_prometheus_metrics = config.get('enable_prometheus_metrics')
60
61- ngx_conf = nginx.NginxConf(conf_path, hookenv.local_unit(), enable_cache_bg_update=enable_cache_bg_update)
62+ ngx_conf = nginx.NginxConf(
63+ conf_path,
64+ hookenv.local_unit(),
65+ enable_cache_bg_update=enable_cache_bg_update,
66+ enable_cache_lock=enable_cache_lock,
67+ )
68
69 sites_secrets = secrets_from_config(config.get('sites_secrets'))
70 blacklist_ports = [int(x.strip()) for x in config.get('blacklist_ports', '').split(',') if x.strip()]
71diff --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
72index 98a3042..1e97ac9 100644
73--- a/tests/unit/files/nginx_config_rendered_test_output-basic_site.txt
74+++ b/tests/unit/files/nginx_config_rendered_test_output-basic_site.txt
75@@ -21,7 +21,7 @@ server {
76 proxy_force_ranges on;
77 proxy_cache e176ab9d1f16-cache;
78 proxy_cache_background_update off;
79- proxy_cache_lock on;
80+ proxy_cache_lock off;
81 proxy_cache_min_uses 1;
82 proxy_cache_revalidate on;
83 proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
84diff --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
85index 21638c3..c265d8a 100644
86--- a/tests/unit/files/nginx_config_rendered_test_output-token_site.txt
87+++ b/tests/unit/files/nginx_config_rendered_test_output-token_site.txt
88@@ -21,7 +21,7 @@ server {
89 proxy_force_ranges on;
90 proxy_cache c27ba6753fee-cache;
91 proxy_cache_background_update off;
92- proxy_cache_lock on;
93+ proxy_cache_lock off;
94 proxy_cache_min_uses 1;
95 proxy_cache_revalidate on;
96 proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
97diff --git a/tests/unit/test_content_cache.py b/tests/unit/test_content_cache.py
98index 0d7e39f..6f52f08 100644
99--- a/tests/unit/test_content_cache.py
100+++ b/tests/unit/test_content_cache.py
101@@ -203,6 +203,7 @@ class TestCharm(unittest.TestCase):
102 'cache_max_size': '1g',
103 'cache_path': '/var/lib/nginx/proxy',
104 'enable_cache_background_update': True,
105+ 'enable_cache_lock': True,
106 'enable_prometheus_metrics': False,
107 'sites': ngx_config,
108 'worker_connections': 768,
109@@ -1287,6 +1288,7 @@ site1.local:
110 'cache_max_size': '1g',
111 'cache_path': '/var/lib/nginx/proxy',
112 'enable_cache_background_update': False,
113+ 'enable_cache_lock': False,
114 'enable_prometheus_metrics': True,
115 'sites': ngx_config,
116 'worker_connections': 768,
117diff --git a/tests/unit/test_nginx.py b/tests/unit/test_nginx.py
118index 5ec7fbe..b76c674 100644
119--- a/tests/unit/test_nginx.py
120+++ b/tests/unit/test_nginx.py
121@@ -126,7 +126,7 @@ class TestLibNginx(unittest.TestCase):
122
123 def test_nginx_config_render_with_metrics(self):
124 """Test rendering with metrics exposed."""
125- ngx_conf = nginx.NginxConf(unit='mock-content-cache/0', enable_cache_bg_update=False)
126+ ngx_conf = nginx.NginxConf(unit='mock-content-cache/0', enable_cache_bg_update=False, enable_cache_lock=False)
127
128 with open('tests/unit/files/config_test_basic_config.txt', 'r', encoding='utf-8') as f:
129 sites = yaml.safe_load(f.read())
130@@ -137,7 +137,6 @@ class TestLibNginx(unittest.TestCase):
131 'cache_inactive_time': '2h',
132 'cache_max_size': '1g',
133 'cache_path': '/var/lib/nginx/proxy',
134- 'enable_cache_background_update': False,
135 'enable_prometheus_metrics': True,
136 'listen_address': '127.0.0.1',
137 }

Subscribers

People subscribed via source and target branches