Merge ~hloeung/content-cache-charm:nginx-site-cache-inactive-time into content-cache-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 524b59fc729a77223198dfb753c45f4f8a3d6d22
Merged at revision: d4f83ee95befd6d0d1cb53fc36da465eee1fbe3a
Proposed branch: ~hloeung/content-cache-charm:nginx-site-cache-inactive-time
Merge into: content-cache-charm:master
Prerequisite: ~hloeung/content-cache-charm:nginx-extra-server-configs
Diff against target: 91 lines (+11/-7)
4 files modified
reactive/content_cache.py (+3/-2)
tests/unit/files/config_test_config.txt (+1/-0)
tests/unit/files/nginx_config_rendered_test_output-site11.local.txt (+1/-1)
tests/unit/test_nginx.py (+6/-4)
Reviewer Review Type Date Requested Status
James Simpson Approve
Canonical IS Reviewers Pending
Review via email: mp+414775@code.launchpad.net

Commit message

Allow overriding cache_inactive_time on per site basis - LP:1922927

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
James Simpson (jsimpso) wrote :

LGTM

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

Change successfully merged at revision d4f83ee95befd6d0d1cb53fc36da465eee1fbe3a

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/content_cache.py b/reactive/content_cache.py
2index e757e27..964057c 100644
3--- a/reactive/content_cache.py
4+++ b/reactive/content_cache.py
5@@ -171,7 +171,6 @@ def configure_nginx(conf_path=None):
6 # to deploy to edge networks and not worry about having to firewall off
7 # access.
8 conf = {}
9- conf['cache_inactive_time'] = config['cache_inactive_time']
10 conf['cache_max_size'] = config['cache_max_size'] or utils.cache_max_size(config['cache_path'])
11 conf['cache_path'] = config['cache_path']
12 conf['listen_address'] = '127.0.0.1'
13@@ -181,9 +180,11 @@ def configure_nginx(conf_path=None):
14 conf['site'] = site
15 conf['site_name'] = site_conf.get('site-name') or site
16 conf['listen_port'] = site_conf['cache_port']
17- conf['locations'] = site_conf.get('locations', {})
18+
19+ conf['cache_inactive_time'] = site_conf.get('cache-inactive-time', config['cache_inactive_time'])
20 conf['enable_prometheus_metrics'] = enable_prometheus_metrics
21 conf['extra_config'] = site_conf.get('extra-config', [])
22+ conf['locations'] = site_conf.get('locations', {})
23
24 if ngx_conf.write_site(site, ngx_conf.render(conf)):
25 hookenv.log('Wrote out new configs for site: {}:{}'.format(site, conf['listen_port']))
26diff --git a/tests/unit/files/config_test_config.txt b/tests/unit/files/config_test_config.txt
27index e93e817..b82c653 100644
28--- a/tests/unit/files/config_test_config.txt
29+++ b/tests/unit/files/config_test_config.txt
30@@ -144,6 +144,7 @@ site10.local:
31
32 # Test 11: Extra server configs, rather than location
33 site11.local:
34+ cache-inactive-time: 12h
35 extra-config:
36 - proxy_request_buffering off
37 - proxy_buffering off
38diff --git a/tests/unit/files/nginx_config_rendered_test_output-site11.local.txt b/tests/unit/files/nginx_config_rendered_test_output-site11.local.txt
39index 9eea04f..c65c003 100644
40--- a/tests/unit/files/nginx_config_rendered_test_output-site11.local.txt
41+++ b/tests/unit/files/nginx_config_rendered_test_output-site11.local.txt
42@@ -1,4 +1,4 @@
43-proxy_cache_path /var/lib/nginx/proxy/site11.local use_temp_path=off levels=1:2 keys_zone=22e76843effa-cache:10m inactive=2h max_size=1g;
44+proxy_cache_path /var/lib/nginx/proxy/site11.local use_temp_path=off levels=1:2 keys_zone=22e76843effa-cache:10m inactive=12h max_size=1g;
45
46 server {
47 server_name site11.local;
48diff --git a/tests/unit/test_nginx.py b/tests/unit/test_nginx.py
49index 9769f87..0a52113 100644
50--- a/tests/unit/test_nginx.py
51+++ b/tests/unit/test_nginx.py
52@@ -48,7 +48,6 @@ class TestLibNginx(unittest.TestCase):
53 sites.pop('configs', '')
54
55 conf = {}
56- conf['cache_inactive_time'] = '2h'
57 conf['cache_max_size'] = '1g'
58 conf['cache_path'] = '/var/lib/nginx/proxy'
59 conf['enable_prometheus_metrics'] = False
60@@ -63,8 +62,10 @@ class TestLibNginx(unittest.TestCase):
61 conf['site'] = site
62 conf['site_name'] = site_conf.get('site-name') or site
63 conf['listen_port'] = port
64- conf['locations'] = site_conf.get('locations', {})
65+
66+ conf['cache_inactive_time'] = site_conf.get('cache-inactive-time', '2h')
67 conf['extra_config'] = site_conf.get('extra-config', [])
68+ conf['locations'] = site_conf.get('locations', {})
69
70 for location, loc_conf in conf['locations'].items():
71 if loc_conf.get('backends'):
72@@ -136,7 +137,6 @@ class TestLibNginx(unittest.TestCase):
73 sites.pop('configs', '')
74
75 conf = {
76- 'cache_inactive_time': '2h',
77 'cache_max_size': '1g',
78 'cache_path': '/var/lib/nginx/proxy',
79 'enable_prometheus_metrics': True,
80@@ -147,8 +147,10 @@ class TestLibNginx(unittest.TestCase):
81 conf['site'] = site
82 conf['site_name'] = site_conf.get('site-name') or site
83 conf['listen_port'] = BASE_LISTEN_PORT
84- conf['locations'] = site_conf.get('locations', {})
85+
86+ conf['cache_inactive_time'] = site_conf.get('cache-inactive-time', '2h')
87 conf['extra_config'] = site_conf.get('extra-config', [])
88+ conf['locations'] = site_conf.get('locations', {})
89
90 for location, loc_conf in conf['locations'].items():
91 if loc_conf.get('backends'):

Subscribers

People subscribed via source and target branches