Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Policy: Content Caching disable totally #1278

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed issues on OIDC jwk discovery [PR #1268](https://github.com/3scale/APIcast/pull/1268) [THREESCALE-6913](https://issues.redhat.com/browse/THREESCALE-6913)
- Fixed Payload limit content-length response header [PR #1266](https://github.com/3scale/APIcast/pull/1266) [THREESCALE-6736](https://issues.redhat.com/browse/THREESCALE-6736)
- Fixed IPcheck policy issues with invalid IP [PR #1273](https://github.com/3scale/APIcast/pull/1273) [THREESCALE-7075](https://issues.redhat.com/browse/THREESCALE-7075)

- Disabled content-caching globally if no policy at all [PR #1278](https://github.com/3scale/APIcast/pull/1278) [THREESCALE-7016](https://issues.redhat.com/browse/THREESCALE-7016)


### Added
Expand All @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).




## [3.10.0] 2021-01-04

Beta1 is stable and moved to final release.
Expand Down
3 changes: 2 additions & 1 deletion gateway/conf.d/apicast.conf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ location @upstream {
}

#{% capture proxy_cache_valid %}
#{#} proxy_cache apicast_cache;
#{#} proxy_cache $cache_zone;
#{#} proxy_cache_key $scheme$request_method$proxy_host$request_uri$service_id;
#{#} proxy_no_cache $cache_request;
#{#} proxy_cache_valid {{ env.APICAST_CACHE_STATUS_CODES | default: '200 302'}} {{ env.APICAST_CACHE_MAX_TIME | default: '1m' }};
Expand Down Expand Up @@ -166,6 +166,7 @@ location / {

# Variable to enable/disable content cache
set $cache_request 'true';
set $cache_zone 'off';

set $original_request_id $request_id;
set $upstream_keepalive_key "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ local metrics_updater = require('apicast.metrics.updater')

local content_cache_metric = prometheus('counter', "content_caching", "Content caching status", {"status"})

local cache_zone = "apicast_cache"

local new = _M.new

function _M.new(config)
Expand All @@ -30,7 +32,9 @@ function _M.new(config)
end

function _M:access(context)
ngx.var.cache_zone = cache_zone
ngx.var.cache_request = "true"

for _, rule in ipairs(self.rules or {}) do
local cond_is_true = rule.condition:evaluate(context)
if cond_is_true and rule.cache then
Expand Down
104 changes: 104 additions & 0 deletions t/apicast-policy-content-caching.t
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,107 @@ __DATA__
["X-Cache-Status: MISS", "X-Cache-Status: MISS"]
--- no_error_log
[error]



=== TEST 8: HEAD request is enabled if no content-caching
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add a brief explanation here or in TEST 9 that clarifies that this is tested because of https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_convert_head

This is related to https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_convert_head
and THREESCALE-7016
--- configuration
{
"services": [
{
"id": 42,
"proxy": {
"hosts": ["one"],
"policy_chain": [
{
"name": "apicast.policy.upstream",
"configuration":
{
"rules": [ { "regex": "/", "url": "http://test:$TEST_NGINX_SERVER_PORT/" } ]
}
}
]
}
}
]
}
--- upstream
location / {
content_by_lua_block {
local assert = require('luassert')
assert.same(ngx.var.request_method, "HEAD")
}
}
--- request
HEAD /foo
--- more_headers
Host: one
--- expected_response_body_like_multiple eval
yay, api backend
--- error_code: 200
--- no_error_log
[error]

=== TEST 9: HEAD request is disabled when using content-caching
This is related to https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_convert_head
and THREESCALE-7016
--- configuration
{
"services": [
{
"id": 42,
"proxy": {
"hosts": ["one"],
"policy_chain": [
{
"name": "apicast.policy.content_caching",
"version": "builtin",
"configuration": {
"rules": [
{
"cache": true,
"header": "X-Cache-Status",
"condition": {
"combine_op": "and",
"operations": [
{
"left": "oo",
"op": "==",
"right": "oo"
}
]
}
}
]
}
},
{
"name": "apicast.policy.upstream",
"configuration":
{
"rules": [ { "regex": "/", "url": "http://test:$TEST_NGINX_SERVER_PORT/" } ]
}
}
]
}
}
]
}
--- upstream
location / {
content_by_lua_block {
local assert = require('luassert')
assert.same(ngx.var.request_method, "GET")
}
}
--- request
HEAD /foo
--- more_headers
Host: one
--- expected_response_body_like_multiple eval
yay, api backend
--- error_code: 200
--- no_error_log
[error]