Merge ~bloodearnest/content-cache-charm:no-cache-or-measure-check into content-cache-charm:master

Proposed by Simon Davy
Status: Work in progress
Proposed branch: ~bloodearnest/content-cache-charm:no-cache-or-measure-check
Merge into: content-cache-charm:master
Diff against target: 53 lines (+17/-2)
2 files modified
templates/nginx_cfg.tmpl (+11/-2)
tests/unit/files/nginx_config_rendered_test_output-site2.local.txt (+6/-0)
Reviewer Review Type Date Requested Status
Content Cache Charmers Pending
Review via email: mp+374565@code.launchpad.net

Commit message

Do not cache or measure check urls in nginx

Seems like Cache-control: no-cache is not enough to prevent nginx from
caching the health check urls. So have added explicit config to not
cache these in nginx template.

Additionally, noticed that the exemption for measuring for check urls
was hardcoded, so updated that to use the explicit healthcheck.

To post a comment you must log in.

Unmerged commits

7da8bbb... by Simon Davy

Do not cache or measure check urls in nginx

Seems like Cache-control: no-cache is not enough to prevent nginx from
caching the health check urls. So have added explicit config to not
cache these in nginx template.

Additionally, noticed that the exemption for measuring for check urls
was hardcoded, so updated that to use the explicit healthcheck.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/templates/nginx_cfg.tmpl b/templates/nginx_cfg.tmpl
2index 6589023..cc1b578 100644
3--- a/templates/nginx_cfg.tmpl
4+++ b/templates/nginx_cfg.tmpl
5@@ -20,6 +20,15 @@ server {
6 proxy_{{key|replace("-", "_")}} {{value}};
7 {%- endif %}
8 {%- endfor -%}
9+
10+ {%- if conf['backend-check-path'] %}
11+ set $nocache 0;
12+ if ($url ~ "^{{conf['backend-check-path']}}") {
13+ set $nocache 1;
14+ }
15+ proxy_cache_bypass $nocache;
16+ proxy_no_cache $nocache;
17+ {%- endif %}
18 {%- endif %}
19
20 {%- if conf['origin-headers'] %}
21@@ -103,7 +112,7 @@ server {
22 {%- if enable_prometheus_metrics %}
23
24 -- Exclude healthchecks from nginx_cache_request_total metric.
25- from, to = ngx.re.find(ngx.var.uri, "^/check/?")
26+ from, to = ngx.re.find(ngx.var.uri, "^{{conf['backend-check-path']|default('/check/?')}}")
27 if not from then
28 cache_request_total:inc(1, {ngx.var.server_name})
29 end
30@@ -113,7 +122,7 @@ server {
31
32 access_by_lua_block {
33 -- Exclude healthchecks from nginx_cache_request_total metric.
34- from, to = ngx.re.find(ngx.var.uri, "^/check/?")
35+ from, to = ngx.re.find(ngx.var.uri, "^{{conf['backend-check-path']|default('/check/?')}}")
36 if not from then
37 cache_request_total:inc(1, {ngx.var.server_name})
38 end
39diff --git a/tests/unit/files/nginx_config_rendered_test_output-site2.local.txt b/tests/unit/files/nginx_config_rendered_test_output-site2.local.txt
40index 687ae85..bf9a845 100644
41--- a/tests/unit/files/nginx_config_rendered_test_output-site2.local.txt
42+++ b/tests/unit/files/nginx_config_rendered_test_output-site2.local.txt
43@@ -18,6 +18,12 @@ server {
44 proxy_cache_revalidate on;
45 proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
46 proxy_cache_valid 200 1d;
47+ set $nocache 0;
48+ if ($url ~ "^/check/") {
49+ set $nocache 1;
50+ }
51+ proxy_cache_bypass $nocache;
52+ proxy_no_cache $nocache;
53 }
54
55

Subscribers

People subscribed via source and target branches