Skip to content

Commit 8160140

Browse files
authored
Merge pull request #1116 from eloycoto/ServiceHost
Logging: Added target host on logging policy.
2 parents d818e1a + 605eadd commit 8160140

File tree

5 files changed

+55
-13
lines changed

5 files changed

+55
-13
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
### Added
1010

1111
- Introduce possibility of specifying policy order restrictions in their schemas. APIcast now shows a warning when those restrictions are not respected [#1088](https://github.com/3scale/APIcast/pull/1088), [THREESCALE-2896](https://issues.jboss.org/browse/THREESCALE-2896)
12-
- Added new parameters to logging policy to allow custom access log [PR #1089](https://github.com/3scale/APIcast/pull/1089), [THREESCALE-1234](https://issues.jboss.org/browse/THREESCALE-1234)[THREESCALE-2876](https://issues.jboss.org/browse/THREESCALE-2876)
12+
- Added new parameters to logging policy to allow custom access log [PR #1089](https://github.com/3scale/APIcast/pull/1089), [THREESCALE-1234](https://issues.jboss.org/browse/THREESCALE-1234)[THREESCALE-2876](https://issues.jboss.org/browse/THREESCALE-2876), [PR #1116] (https://github.com/3scale/APIcast/pull/1116)
1313
- Added http_proxy policy to use an HTTP proxy in api_backed calls. [THREESCALE-2696](https://issues.jboss.org/browse/THREESCALE-2696), [PR #1080](https://github.com/3scale/APIcast/pull/1080)
1414
- Option to load service configurations one by one lazily [PR #1099](https://github.com/3scale/APIcast/pull/1099), [THREESCALE-3168](https://issues.jboss.org/browse/THREESCALE-3168)
1515
- New maintenance mode policy, useful for maintenance periods. [PR #1105](https://github.com/3scale/APIcast/pull/1105), [THREESCALE-3189](https://issues.jboss.org/browse/THREESCALE-3189)

gateway/src/apicast/executor.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ local function shared_build_context(executor)
7373
ctx.context = context
7474
end
7575

76-
if not ctx.original_request then
77-
store_original_request(ctx)
76+
if not context.original_request then
77+
store_original_request(context)
7878
end
7979

8080
return context

gateway/src/apicast/policy/logging/logging.lua

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ local function get_request_context(context)
7777
}
7878

7979
ctx.service = context.service or {}
80+
ctx.original_request = context.original_request
8081
return LinkedList.readonly(ctx, ngx.var)
8182
end
8283

gateway/src/apicast/policy/routing/routing_operation.lua

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,45 @@ local function new(evaluate_left_side_func, op, value, value_type)
2525
end
2626

2727
function _M.new_op_with_path(op, value, value_type)
28-
local eval_left_func = function(request) return request:get_uri() end
28+
local eval_left_func = function(context) return context.request:get_uri() end
2929
return new(eval_left_func, op, value, value_type)
3030
end
3131

3232
function _M.new_op_with_header(header_name, op, value, value_type)
33-
local eval_left_func = function(request)
34-
return request:get_header(header_name)
33+
local eval_left_func = function(context)
34+
return context.request:get_header(header_name)
3535
end
3636

3737
return new(eval_left_func, op, value, value_type)
3838
end
3939

4040
function _M.new_op_with_query_arg(query_arg_name, op, value, value_type)
41-
local eval_left_func = function(request)
42-
return request:get_uri_arg(query_arg_name)
41+
local eval_left_func = function(context)
42+
return context.request:get_uri_arg(query_arg_name)
4343
end
4444

4545
return new(eval_left_func, op, value, value_type)
4646
end
4747

4848
function _M.new_op_with_jwt_claim(jwt_claim_name, op, value, value_type)
49-
local eval_left_func = function(request)
50-
local jwt = request:get_validated_jwt()
49+
local eval_left_func = function(context)
50+
local jwt = context.request:get_validated_jwt()
5151
return (jwt and jwt[jwt_claim_name]) or nil
5252
end
5353

5454
return new(eval_left_func, op, value, value_type)
5555
end
5656

5757
function _M.new_op_with_liquid_templating(liquid_expression, op, value, value_type)
58-
local eval_left_func = function()
59-
return TemplateString.new(liquid_expression or "" , "liquid"):render(ngx.ctx)
58+
local eval_left_func = function(context)
59+
return TemplateString.new(liquid_expression or "" , "liquid"):render(context)
6060
end
6161

6262
return new(eval_left_func, op, value, value_type)
6363
end
6464

6565
function _M:evaluate(context)
66-
local left_operand_val = self.evaluate_left_side_func(context.request)
66+
local left_operand_val = self.evaluate_left_side_func(context)
6767

6868
local op = Operation.new(
6969
left_operand_val, 'plain', self.op, self.value, self.value_type

t/apicast-policy-logging.t

+41
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,44 @@ GET /
420420
[qr/^\{\"host\"\:\"echo\"\}/]
421421
--- no_error_log eval
422422
[qr/\[error/, qr/GET \/ HTTP\/1.1\" 200/]
423+
424+
=== TEST 11: Original request information can be retrieved correctly
425+
--- configuration
426+
{
427+
"services": [
428+
{
429+
"id": 42,
430+
"proxy": {
431+
"policy_chain": [
432+
{
433+
"name": "apicast.policy.logging",
434+
"configuration": {
435+
"custom_logging": "Status::{{ status }} {{service.id}} {{host}} {{original_request.host}}",
436+
"enable_json_logs": false
437+
}
438+
},
439+
{
440+
"name": "apicast.policy.upstream",
441+
"configuration":
442+
{
443+
"rules": [ { "regex": "/", "url": "http://echo" } ]
444+
}
445+
}
446+
]
447+
}
448+
}
449+
]
450+
}
451+
--- upstream
452+
location / {
453+
content_by_lua_block {
454+
ngx.say('yay, api backend');
455+
}
456+
}
457+
--- request
458+
GET /
459+
--- error_code: 200
460+
--- error_log eval
461+
[qr/^Status\:\:200 42 echo localhost/]
462+
--- no_error_log eval
463+
[qr/\[error/, qr/GET \/ HTTP\/1.1\" 200/]

0 commit comments

Comments
 (0)