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 25, 2022
1 parent f2adaeb commit 091c721
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 36 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
56 changes: 21 additions & 35 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,10 +116,9 @@ plugins:
core.log.warn("this is a warning message for test2.")
}
}
--- request
GET /tg
--- response_body
--- error_log
this is a warning message for test2
clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
clickhouse headers: x-clickhouse-key:a
clickhouse headers: x-clickhouse-user:default
Expand All @@ -140,32 +135,31 @@ 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
}]]
)
ngx.sleep(2)
core.log.warn("this is an error message for test3.")
core.log.warn("this is a warning message for test3.")
}
}
--- request
GET /tg
--- response_body
--- error_log
this is a warning message for test3
clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
clickhouse headers: x-clickhouse-key:a
clickhouse headers: x-clickhouse-user:default
Expand All @@ -182,16 +176,15 @@ 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
this is a warning message for test4
clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
clickhouse headers: x-clickhouse-key:a
clickhouse headers: x-clickhouse-user:default
Expand All @@ -208,16 +201,15 @@ 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
this is a warning message for test5
clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
clickhouse headers: x-clickhouse-key:a
clickhouse headers: x-clickhouse-user:default
Expand All @@ -234,14 +226,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 +247,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 +261,5 @@ plugins:
ngx.say(body)
}
}
--- request
GET /tg
--- response_body
passed
--- no_error_log
[error]

0 comments on commit 091c721

Please sign in to comment.