Skip to content
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
4 changes: 4 additions & 0 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ local function merge_service_route(service_conf, route_conf)
new_conf.value.script = route_conf.value.script
end

if route_conf.value.name then
new_conf.value.name = route_conf.value.name
end

-- core.log.info("merged conf : ", core.json.delay_encode(new_conf))
return new_conf
end
Expand Down
93 changes: 93 additions & 0 deletions t/core/ctx.t
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,96 @@ GET /hello
hello world
--- error_log eval
qr/request log: \{"route_id":"1"\}/



=== TEST 34: add metadata, service and route, and the service is bound to the route
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/plugin_metadata/http-logger',
ngx.HTTP_PUT,
[[{
"log_format": {
"route_name": "$route_name",
"service_name": "$service_name"
}
}]],
[[{
"node": {
"value": {
"log_format": {
"route_name": "$route_name",
"service_name": "$service_name"
}
}
},
"action": "set"
}]]
)

if code >= 300 then
ngx.status = code
ngx.say(body)
end

local code, body = t('/apisix/admin/services/1',
Copy link
Member

Choose a reason for hiding this comment

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

We can put TEST 35 into TEST 34.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

ngx.HTTP_PUT,
[[{
"name": "my_service",
"plugins": {
"http-logger": {
"uri": "http://127.0.0.1:1980/log",
"batch_max_size": 1,
"max_retry_count": 1,
"retry_delay": 2,
"buffer_duration": 2,
"concat_method": "json"
}
}
}]]
)

if code >= 300 then
ngx.status = code
ngx.say(body)
end

code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"name": "my_route",
"uri": "/hello",
"service_id": 1,
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 35: hit route and route_name and service_name are different
--- request
GET /hello
--- response_body
hello world
--- error_log eval
qr/request log: \{"route_id":"1","route_name":"my_route","service_id":"1","service_name":"my_service"\}/