Skip to content

Commit

Permalink
update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
qizhendong committed Feb 23, 2022
1 parent f2adaeb commit b99e156
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs/zh/latest/plugins/error-log-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/error-log-logger -H 'X-A

## 如何设置接收日志的 clickhouse 数据库

插件将error log作为一个字符串发送到clickhouse表的 `data` 字段。
插件将 error log 作为一个字符串发送到 clickhouse 表的 `data` 字段。
步骤:更新插件属性

```shell
Expand Down
50 changes: 16 additions & 34 deletions t/plugin/error-log-logger-clickhouse.t
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ __DATA__
local ok, err = plugin.check_schema(
{
clickhouse = {
user = "default",
password = "a",
database = "default",
logtable = "t",
endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
user = "default",
password = "a",
database = "default",
logtable = "t",
endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
}
},
core.schema.TYPE_METADATA
Expand All @@ -82,12 +82,8 @@ __DATA__
ngx.say("done")
}
}
--- request
GET /t
--- response_body
done
--- no_error_log
[error]
Expand All @@ -99,7 +95,7 @@ apisix:
plugins:
- error-log-logger
--- config
location /tg {
location /t {
content_by_lua_block {
local core = require("apisix.core")
local t = require("lib.test_admin").test
Expand All @@ -120,8 +116,6 @@ plugins:
core.log.warn("this is a warning message for test2.")
}
}
--- request
GET /tg
--- response_body
--- error_log
clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
Expand All @@ -140,19 +134,19 @@ apisix:
plugins:
- error-log-logger
--- config
location /tg {
location /t {
content_by_lua_block {
local core = require("apisix.core")
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
ngx.HTTP_PUT,
[[{
"clickhouse": {
"user": "default",
"password": "a",
"database": "default",
"logtable": "t",
"endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
"user": "default",
"password": "a",
"database": "default",
"logtable": "t",
"endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
},
"batch_max_size": 15,
"inactive_timeout": 1
Expand All @@ -162,8 +156,6 @@ plugins:
core.log.warn("this is an error message for test3.")
}
}
--- request
GET /tg
--- response_body
--- error_log
clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
Expand All @@ -182,14 +174,12 @@ apisix:
plugins:
- error-log-logger
--- config
location /tg {
location /t {
content_by_lua_block {
local core = require("apisix.core")
core.log.warn("this is a warning message for test4.")
}
}
--- request
GET /tg
--- response_body
--- error_log
clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
Expand All @@ -208,14 +198,12 @@ apisix:
plugins:
- error-log-logger
--- config
location /tg {
location /t {
content_by_lua_block {
local core = require("apisix.core")
core.log.warn("this is a warning message for test5.")
}
}
--- request
GET /tg
--- response_body
--- error_log
clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
Expand All @@ -234,14 +222,12 @@ apisix:
plugins:
- error-log-logger
--- config
location /tg {
location /t {
content_by_lua_block {
local core = require("apisix.core")
core.log.info("this is an info message for test6.")
}
}
--- request
GET /tg
--- response_body
--- error_log
this is an info message for test6
Expand All @@ -257,7 +243,7 @@ apisix:
plugins:
- error-log-logger
--- config
location /tg {
location /t {
content_by_lua_block {
local core = require("apisix.core")
local t = require("lib.test_admin").test
Expand All @@ -271,9 +257,5 @@ plugins:
ngx.say(body)
}
}
--- request
GET /tg
--- response_body
passed
--- no_error_log
[error]

0 comments on commit b99e156

Please # to comment.