-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(http-logger): support for specified the log formats via admin API #2294
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9285a13
test: add test.
membphis 44b6843
feat: support user-defined `log_format`, default is json encoding for…
membphis a5766a4
revert code.
membphis 4e202b1
test: added test api.
membphis 09d5b0c
Chinese doc
membphis b939f6a
test: delete the plugin metadata at the end of test file.
membphis 8e3ecfa
Merge branch 'master' into http-logger-log-format
membphis 00ba1dc
bug: use empty table if there was no plugin metadata.
membphis 8750b97
chore: code style.
membphis 6f1ddf8
typo
membphis 90e3073
test: update match context
membphis c8fe4c7
test: use `apple.com` to replace `baidu.com`, it is more stable in CI…
membphis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
use t::APISIX 'no_plan'; | ||
|
||
log_level('info'); | ||
repeat_each(1); | ||
no_long_string(); | ||
no_root_location(); | ||
|
||
run_tests; | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: add plugin metadata | ||
--- 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": { | ||
"host": "$host", | ||
"@timestamp": "$time_iso8601", | ||
"client_ip": "$remote_addr" | ||
} | ||
}]], | ||
[[{ | ||
"node": { | ||
"value": { | ||
"log_format": { | ||
"host": "$host", | ||
"@timestamp": "$time_iso8601", | ||
"client_ip": "$remote_addr" | ||
} | ||
} | ||
}, | ||
"action": "set" | ||
}]] | ||
) | ||
|
||
ngx.status = code | ||
ngx.say(body) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
passed | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 2: sanity, batch_max_size=1 | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/routes/1', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"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, | ||
"inactive_timeout": 2, | ||
"concat_method": "new_line" | ||
} | ||
}, | ||
"upstream": { | ||
"nodes": { | ||
"127.0.0.1:1982": 1 | ||
}, | ||
"type": "roundrobin" | ||
}, | ||
"uri": "/hello" | ||
}]] | ||
) | ||
|
||
if code >= 300 then | ||
ngx.status = code | ||
end | ||
ngx.say(body) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
passed | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 3: hit route and report http logger | ||
--- request | ||
GET /hello | ||
--- response_body | ||
hello world | ||
--- wait: 0.5 | ||
--- no_error_log | ||
[error] | ||
--- error_log | ||
request log: { | ||
|
||
|
||
|
||
=== TEST 4: remove plugin metadata | ||
--- 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_DELETE | ||
) | ||
|
||
if code >= 300 then | ||
ngx.status = code | ||
end | ||
|
||
ngx.say(body) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
passed | ||
--- no_error_log | ||
[error] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between metadata and the properties of plugin itself? I didn't see why we need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get plugin schema:
/apisix/admin/plugins/{plugin-name}, eg: /apisix/admin/plugins/limit-req
get plugin metadata:
/apisix/admin/plugin_metadata/{plugin-name}, eg: /apisix/admin/plugin_metadata/example-plugin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2294 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend using
/plugins/{name}/metadata
in a RESTful way if this PR is needed..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also curious about what scenarios need metadata instead of plugin's option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this PR has been merged. we can talk in here: #2307 (comment)