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

Logs: Fix host on access logs #1284

Merged
merged 1 commit into from
Jun 22, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- 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)
- Fixed warning messages [PR #1282](https://github.com/3scale/APIcast/pull/1282) [THREESCALE-5816](https://issues.redhat.com/browse/THREESCALE-5816)
- Fixed lua socket error on ssl_certificate [PR #1283](https://github.com/3scale/APIcast/pull/1283) [THREESCALE-7230](https://issues.redhat.com/browse/THREESCALE-7230)
- Fixed Acess log header [PR #1284](https://github.com/3scale/APIcast/pull/1284) [THREESCALE-6193](https://issues.redhat.com/browse/THREESCALE-6193)

### Added

Expand Down
5 changes: 3 additions & 2 deletions gateway/conf.d/apicast.conf
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ location / {
set $ctx_ref -1;

set $post_action_impact '';
set $original_request_id '';
set $original_request_id $request_id;
set $original_request_uri '$scheme://$host$request_uri';

# Variables needed by Websocket policy
Expand All @@ -168,7 +168,8 @@ location / {
set $cache_request 'true';
set $cache_zone 'off';

set $original_request_id $request_id;
set $target_host $host;

set $upstream_keepalive_key "";

# {% if http_keepalive_timeout != empty %}
Expand Down
2 changes: 1 addition & 1 deletion gateway/http.d/apicast.conf.liquid
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
log_format time '[$time_local] $host:$server_port $remote_addr:$remote_port "$request" $status $body_bytes_sent ($request_time) $post_action_impact';
log_format time '[$time_local] $target_host:$server_port $remote_addr:$remote_port "$request" $status $body_bytes_sent ($request_time) $post_action_impact';

map $status $extended_access_log {
default '';
Expand Down
42 changes: 42 additions & 0 deletions t/apicast-log.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use lib 't';
use Test::APIcast::Blackbox 'no_plan';

# Test::Nginx does not allow to grep access logs, so we redirect them to
# stderr to be able to use "grep_error_log" by setting APICAST_ACCESS_LOG_FILE
$ENV{APICAST_ACCESS_LOG_FILE} = "$Test::Nginx::Util::ErrLogFile";

repeat_each(2);

run_tests();
Expand Down Expand Up @@ -89,3 +93,41 @@ yay, api backend: test:$TEST_NGINX_SERVER_PORT
requestID=
--- no_error_log
[error]

=== TEST 3: Access log has the correct host.
--- configuration
{
"services": [
{
"id": 42,
"backend_version": 1,
"backend_authentication_type": "service_token",
"backend_authentication_value": "token-value",
"proxy": {
"api_backend": "http://test:$TEST_NGINX_SERVER_PORT/",
"proxy_rules": [
{ "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 }
]
}
}
]
}
--- backend
location /transactions/authrep.xml {
content_by_lua_block {
ngx.exit(200)
}
}
--- upstream
location / {
echo 'yay, api backend: $http_host';
}
--- request
GET /?user_key=value
--- response_body env
yay, api backend: test:$TEST_NGINX_SERVER_PORT
--- error_code: 200
--- error_log eval
qr/\+0000\] localhost\:\d+ 127\.0\.0\.1\:\d+/
--- no_error_log
[error]