Skip to content

Commit

Permalink
removed support for sending request logs
Browse files Browse the repository at this point in the history
closes #291
  • Loading branch information
mikz committed Mar 14, 2017
1 parent c6ea2e3 commit f9d31c9
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 175 deletions.
3 changes: 0 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ REDIS_HOST=redis
# Limit to subset of services. Comma separated list of service ids.
# APICAST_SERVICES=265,31,42

# Turn on request logging to 3scale
# APICAST_REQUEST_LOGS=1

# Turn on logging response codes to 3scale
# APICAST_RESPONSE_CODES=1

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Removed

- Removed support for sending Request logs [PR #296](https://github.com/3scale/apicast/pull/296)

## [3.0.0-beta2] - 2017-03-08

### Fixed
Expand Down
1 change: 0 additions & 1 deletion apicast/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ env REDIS_HOST;
env REDIS_PORT;
env RESOLVER;
env APICAST_MODULE;
env APICAST_REQUEST_LOGS;
env APICAST_RESPONSE_CODES;
env APICAST_MANAGEMENT_API;
env BACKEND_ENDPOINT_OVERRIDE;
Expand Down
23 changes: 2 additions & 21 deletions apicast/src/apicast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ local _M = {
_NAME = 'APIcast'
}

local request_logs = env.enabled('APICAST_REQUEST_LOGS')

local mt = {
__index = _M
}
Expand Down Expand Up @@ -82,25 +80,8 @@ function _M.access()
return fun()
end

if request_logs then
ngx.log(ngx.WARN, 'ENABLED REQUEST LOGS')

function _M.body_filter()
ngx.ctx.buffered = (ngx.ctx.buffered or "") .. string.sub(ngx.arg[1], 1, 1000)

if ngx.arg[2] then
ngx.var.resp_body = ngx.ctx.buffered
end
end

function _M.header_filter()

ngx.var.resp_headers = require('cjson').encode(ngx.resp.get_headers())
end
else
_M.body_filter = noop
_M.header_filter = noop
end
_M.body_filter = noop
_M.header_filter = noop

_M.balancer = balancer.call

Expand Down
23 changes: 6 additions & 17 deletions apicast/src/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ local resty_resolver = require 'resty.resolver'
local empty = {}

local response_codes = env.enabled('APICAST_RESPONSE_CODES')
local request_logs = env.enabled('APICAST_REQUEST_LOGS')

local _M = { }

Expand Down Expand Up @@ -355,28 +354,18 @@ function _M:access(service)
end


local function request_logs_encoded_data()
local request_log = {}
local function response_codes_encoded_data()
local params = {}

if not request_logs and not response_codes then
if not response_codes then
return ''
end

if request_logs then
local method, path, headers = ngx.req.get_method(), ngx.var.request_uri, ngx.req.get_headers()

local req = cjson.encode{ method=method, path=path, headers=headers }
local resp = cjson.encode{ body = ngx.var.resp_body, headers = cjson.decode(ngx.var.resp_headers) }

request_log["log[request]"] = req
request_log["log[response]"] = resp
end

if response_codes then
request_log["log[code]"] = ngx.var.status
params["log[code]"] = ngx.var.status
end

return ngx.escape_uri(ngx.encode_args(request_log))
return ngx.escape_uri(ngx.encode_args(params))
end

function _M:post_action()
Expand All @@ -391,7 +380,7 @@ function _M:post_action()
self:set_backend_upstream(service)

local auth_uri = service.backend_version == 'oauth' and 'threescale_oauth_authrep' or 'threescale_authrep'
local res = http.get("/".. auth_uri .."?log=" .. request_logs_encoded_data())
local res = http.get("/".. auth_uri .."?log=" .. response_codes_encoded_data())

if res.status ~= 200 then
local api_keys = ngx.shared.api_keys
Expand Down
11 changes: 0 additions & 11 deletions doc/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ Specifies the name of the main Lua module that implements the API gateway logic.

When this parameter is set to _true_, the gateway will use path-based routing instead of the default host-based routing.

### `APICAST_REQUEST_LOGS`

**Values:**
- `true` or `1` for _true_
- `false`, `0` or empty for _false_

**Default:** \<empty\> (_false_)

When set to _true_, APIcast will log the details about the API request (method, path and headers) and response (body and headers) in 3scale. In some plans this information can later be consulted from the 3scale admin portal.
Find more information about the Request Logs feature on the [3scale support site](https://support.3scale.net/docs/analytics/response-codes-tracking).

### `APICAST_RESPONSE_CODES`

**Values:**
Expand Down
6 changes: 0 additions & 6 deletions openshift/apicast-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ objects:
value: "${PATH_ROUTING}"
- name: APICAST_RESPONSE_CODES
value: "${RESPONSE_CODES}"
- name: APICAST_REQUEST_LOGS
value: "${REQUEST_LOGS}"
- name: APICAST_CONFIGURATION_CACHE
value: "${CONFIGURATION_CACHE}"
- name: REDIS_HOST
Expand Down Expand Up @@ -141,10 +139,6 @@ parameters:
name: PATH_ROUTING
required: false
value: "false"
- description: "Enable traffic logging to 3scale. Includes whole request and response."
value: "false"
name: REQUEST_LOGS
required: false
- description: "Enable logging response codes to 3scale."
value: "false"
name: RESPONSE_CODES
Expand Down
116 changes: 0 additions & 116 deletions t/008-apicast-request-logs.t
Original file line number Diff line number Diff line change
Expand Up @@ -69,62 +69,6 @@ api response
--- grep_error_log eval: qr/log\[\w+\]:.+/
--- grep_error_log_out
=== TEST 2: request logs are sent when opt-in
--- main_config
env APICAST_REQUEST_LOGS=1;
--- http_config
include $TEST_NGINX_UPSTREAM_CONFIG;
lua_package_path "$TEST_NGINX_LUA_PATH";
init_by_lua_block {
require('configuration_loader').mock({
services = {
{
id = 42,
backend_version = 1,
proxy = {
api_backend = 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/',
proxy_rules = {
{ pattern = '/', http_method = 'GET', metric_system_name = 'bar' }
}
}
},
}
})
ngx.shared.api_keys:set('42:somekey:usage%5Bbar%5D=0', 200)
}
lua_shared_dict api_keys 1m;
--- config
include $TEST_NGINX_APICAST_CONFIG;
set $backend_endpoint 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT';
location /api/ {
echo "api response";
}
location /transactions/authrep.xml {
content_by_lua_block {
local args = ngx.req.get_uri_args()
for key, val in pairs(args) do
ngx.log(ngx.DEBUG, key, ": ", val)
end
ngx.exit(200)
}
}
--- request
GET /foo?user_key=somekey
--- response_body
api response
--- error_code: 200
--- grep_error_log eval: qr/log\[\w+\]:.+/
--- grep_error_log_out eval
<<"END";
log[request]: {"path":"\\/foo?user_key=somekey","method":"GET","headers":{"host":"127.0.0.1","connection":"close"}}
log[response]: {"headers":{"x-3scale-matched-rules":"\\/","content-type":"text\\/plain","connection":"close","x-3scale-usage":"usage%5Bbar%5D=0","x-3scale-hostname":"$::host","x-3scale-credentials":"user_key=somekey"},"body":"api response\\n"}
END
=== TEST 3: response codes are sent when opt-in
--- main_config
Expand Down Expand Up @@ -181,63 +125,3 @@ api response
<<"END";
log[code]: 201
END
=== TEST 4: request logs and response codes are sent when opt-in
--- main_config
env APICAST_REQUEST_LOGS=1;
env APICAST_RESPONSE_CODES=1;
--- http_config
include $TEST_NGINX_UPSTREAM_CONFIG;
lua_package_path "$TEST_NGINX_LUA_PATH";
init_by_lua_block {
require('configuration_loader').mock({
services = {
{
id = 42,
backend_version = 1,
proxy = {
api_backend = 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/',
proxy_rules = {
{ pattern = '/', http_method = 'GET', metric_system_name = 'bar' }
}
}
},
}
})
ngx.shared.api_keys:set('42:somekey:usage%5Bbar%5D=0', 200)
}
lua_shared_dict api_keys 1m;
--- config
include $TEST_NGINX_APICAST_CONFIG;
set $backend_endpoint 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT';
location /api/ {
echo "api response";
echo_status 202;
}
location /transactions/authrep.xml {
content_by_lua_block {
local args = ngx.req.get_uri_args()
for key, val in pairs(args) do
ngx.log(ngx.DEBUG, key, ": ", val)
end
ngx.exit(200)
}
}
--- request
GET /foo?user_key=somekey
--- response_body
api response
--- error_code: 202
--- grep_error_log eval: qr/log\[\w+\]:.+/
--- grep_error_log_out eval
<<"END";
log[response]: {"headers":{"x-3scale-matched-rules":"\\/","content-type":"text\\/plain","connection":"close","x-3scale-usage":"usage%5Bbar%5D=0","x-3scale-hostname":"$::host","x-3scale-credentials":"user_key=somekey"},"body":"api response\\n"}
log[request]: {"path":"\\/foo?user_key=somekey","method":"GET","headers":{"host":"127.0.0.1","connection":"close"}}
log[code]: 202
END

0 comments on commit f9d31c9

Please sign in to comment.