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

Proposed by Haw Loeung
Status: Merged
Approved by: Paul Collins
Approved revision: 1401868f6d8adb3f54a540c49d784e9e43e98a30
Merged at revision: 5152c2c47b7cf56ef26e37c8f9f88956a141a741
Proposed branch: ~hloeung/content-cache-charm:cleanup
Merge into: content-cache-charm:master
Diff against target: 114 lines (+13/-12)
5 files modified
config.yaml (+3/-3)
lib/nginx.py (+3/-3)
reactive/content_cache.py (+3/-2)
tests/unit/test_content_cache.py (+2/-2)
tests/unit/test_nginx.py (+2/-2)
Reviewer Review Type Date Requested Status
Paul Collins lgtm Approve
Canonical IS Reviewers Pending
Review via email: mp+388285@code.launchpad.net

Commit message

Renamed config option to make it consistent - LP:1871259

Description of the change

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
Paul Collins (pjdc) :
review: Approve (lgtm)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 5152c2c47b7cf56ef26e37c8f9f88956a141a741

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 0a81a0d..12560a6 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -25,14 +25,14 @@ options:
6 default: "/var/lib/nginx/proxy"
7 description: >
8 Path or directory to store cached objects.
9- disable_cache_background_update:
10- default: false
11+ enable_cache_background_update:
12+ default: true
13 type: boolean
14 description: >
15 Default is to enable serving contents from the cache with a
16 background subrequest to update objects in cache. This works for
17 large objects, but can cause issues with sites updated recently
18- to redirects that still have objects in the cache.
19+ to redirect and still have objects in the cache.
20 enable_prometheus_metrics:
21 default: true
22 type: boolean
23diff --git a/lib/nginx.py b/lib/nginx.py
24index 74f3e58..1b6289e 100644
25--- a/lib/nginx.py
26+++ b/lib/nginx.py
27@@ -24,14 +24,14 @@ PROXY_CACHE_DEFAULTS = {
28
29
30 class NginxConf:
31- def __init__(self, conf_path=None, unit='content-cache', disable_cache_bg_update=False):
32+ def __init__(self, conf_path=None, unit='content-cache', enable_cache_bg_update=True):
33 if not conf_path:
34 conf_path = NGINX_BASE_PATH
35 self.unit = unit
36
37 self._base_path = conf_path
38 self._conf_path = os.path.join(self.base_path, 'conf.d')
39- self._disable_cache_bg_update = disable_cache_bg_update
40+ self._enable_cache_bg_update = enable_cache_bg_update
41 self._sites_path = os.path.join(self.base_path, 'sites-available')
42
43 script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
44@@ -113,7 +113,7 @@ class NginxConf:
45 continue
46 lc.setdefault(cache_key, v)
47
48- if self._disable_cache_bg_update:
49+ if not self._enable_cache_bg_update:
50 lc['cache-background-update'] = 'off'
51 lc['cache-use-stale'] = lc['cache-use-stale'].replace('updating ', '')
52
53diff --git a/reactive/content_cache.py b/reactive/content_cache.py
54index 6c6eeef..e5967a8 100644
55--- a/reactive/content_cache.py
56+++ b/reactive/content_cache.py
57@@ -138,10 +138,11 @@ def configure_nginx(conf_path=None):
58 status.blocked('requires list of sites to configure')
59 return
60
61+ enable_cache_bg_update = config.get('enable_cache_background_update', True)
62 enable_prometheus_metrics = config.get('enable_prometheus_metrics')
63
64- disable_cache_bg_update = config.get('disable_cache_background_update', False)
65- ngx_conf = nginx.NginxConf(conf_path, hookenv.local_unit(), disable_cache_bg_update=disable_cache_bg_update)
66+ ngx_conf = nginx.NginxConf(conf_path, hookenv.local_unit(), enable_cache_bg_update=enable_cache_bg_update)
67+
68 sites_secrets = secrets_from_config(config.get('sites_secrets'))
69 blacklist_ports = [int(x.strip()) for x in config.get('blacklist_ports', '').split(',') if x.strip()]
70 sites = sites_from_config(config.get('sites'), sites_secrets, blacklist_ports=blacklist_ports)
71diff --git a/tests/unit/test_content_cache.py b/tests/unit/test_content_cache.py
72index ad9964f..5b4e386 100644
73--- a/tests/unit/test_content_cache.py
74+++ b/tests/unit/test_content_cache.py
75@@ -192,7 +192,7 @@ class TestCharm(unittest.TestCase):
76 'cache_inactive_time': '2h',
77 'cache_max_size': '1g',
78 'cache_path': '/var/lib/nginx/proxy',
79- 'disable_cache_background_update': False,
80+ 'enable_cache_background_update': True,
81 'enable_prometheus_metrics': False,
82 'sites': ngx_config,
83 'worker_connections': 768,
84@@ -1155,7 +1155,7 @@ site1.local:
85 'cache_inactive_time': '2h',
86 'cache_max_size': '1g',
87 'cache_path': '/var/lib/nginx/proxy',
88- 'disable_cache_background_update': True,
89+ 'enable_cache_background_update': False,
90 'enable_prometheus_metrics': True,
91 'sites': ngx_config,
92 'worker_connections': 768,
93diff --git a/tests/unit/test_nginx.py b/tests/unit/test_nginx.py
94index 7f95ba8..c7bcfe3 100644
95--- a/tests/unit/test_nginx.py
96+++ b/tests/unit/test_nginx.py
97@@ -124,7 +124,7 @@ class TestLibNginx(unittest.TestCase):
98
99 def test_nginx_config_render_with_metrics(self):
100 """Test rendering with metrics exposed."""
101- ngx_conf = nginx.NginxConf(unit='mock-content-cache/0', disable_cache_bg_update=True)
102+ ngx_conf = nginx.NginxConf(unit='mock-content-cache/0', enable_cache_bg_update=False)
103
104 with open('tests/unit/files/config_test_basic_config.txt', 'r', encoding='utf-8') as f:
105 sites = yaml.safe_load(f.read())
106@@ -133,7 +133,7 @@ class TestLibNginx(unittest.TestCase):
107 'cache_inactive_time': '2h',
108 'cache_max_size': '1g',
109 'cache_path': '/var/lib/nginx/proxy',
110- 'disable_cache_background_update': True,
111+ 'enable_cache_background_update': False,
112 'enable_prometheus_metrics': True,
113 'listen_address': '127.0.0.1',
114 }

Subscribers

People subscribed via source and target branches