Skip to content

Commit

Permalink
fix doc and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
qizhendong committed Feb 11, 2022
1 parent d89631d commit 22c3fb0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion apisix/plugins/clickhouse-logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ local function send_http_data(conf, log_message)
end

if url_decoded.scheme == "https" and conf.ssl_verify then
ok, err = httpc:ssl_handshake(true, host, true)
ok, err = httpc:ssl_handshake(true, host, conf.ssl_verify)
if not ok then
return false, "failed to perform SSL with host[" .. host .. "] "
.. "port[" .. tostring(port) .. "] " .. err
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/plugins/clickhouse-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ hello, world

| Name | Type | Requirement | Default | Valid | Description |
| ---------------- | ------- | ----------- | ------------- | ------- | ---------------------------------------------------------------------------------------- |
| log_format | object | optional | {"host": "$host", "@timestamp": "$time_iso8601", "client_ip": "$remote_addr"} | | Log format declared as key value pair in JSON format. Only string is supported in the `value` part. If the value starts with `$`, it means to get `APISIX` variables or [Nginx variable](http://nginx.org/en/docs/varindex.html). |
| log_format | object | optional | {"host": "$host", "@timestamp": "$time_iso8601", "client_ip": "$remote_addr"} | | Log format declared as key value pair in JSON format. Only string is supported in the `value` part. If the value starts with `$`, it means to get [APISIX variable](../apisix-variable.md) or [Nginx variable](http://nginx.org/en/docs/varindex.html). |

Note that **the metadata configuration is applied in global scope**, which means it will take effect on all Route or Service which use clickhouse-logger plugin.

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/latest/plugins/clickhouse-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ hello, world

| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
| ---------------- | ------- | ------ | ------------- | ------- | ------------------------------------------------ |
| log_format | object | 可选 | {"host": "$host", "@timestamp": "$time_iso8601", "client_ip": "$remote_addr"} | | 以 JSON 格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 __APISIX__ 变量或 [Nginx 内置变量](http://nginx.org/en/docs/varindex.html)。特别的,**该设置是全局生效的**,意味着指定 log_format 后,将对所有绑定 http-logger 的 Route 或 Service 生效。 |
| log_format | object | 可选 | {"host": "$host", "@timestamp": "$time_iso8601", "client_ip": "$remote_addr"} | | 以 JSON 格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 [APISIX 变量](../../../en/latest/apisix-variable.md) [Nginx 内置变量](http://nginx.org/en/docs/varindex.html)。特别的,**该设置是全局生效的**,意味着指定 log_format 后,将对所有绑定 http-logger 的 Route 或 Service 生效。 |

### 设置日志格式示例

Expand Down
25 changes: 9 additions & 16 deletions t/plugin/clickhouse-logger.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ add_block_preprocessor(sub {
my $http_config = $block->http_config // <<_EOC_;
server {
listen 10420;
location /loggly/bulk/tok/tag/bulk {
location /clickhouse-logger/test {
content_by_lua_block {
ngx.req.read_body()
local data = ngx.req.get_body_data()
local headers = ngx.req.get_headers()
ngx.log(ngx.ERR, "loggly body: ", data)
ngx.log(ngx.ERR, "loggly tags: " .. require("toolkit.json").encode(headers["X-LOGGLY-TAG"]))
ngx.log(ngx.ERR, "clickhouse body: ", data)
ngx.say("ok")
}
}
Expand All @@ -58,8 +57,6 @@ __DATA__
=== TEST 1: Full configuration verification
--- yaml_config
plugins:
- clickhouse-logger
--- config
location /t {
content_by_lua_block {
Expand All @@ -71,7 +68,7 @@ plugins:
password = "a",
database = "default",
logtable = "t",
endpoint_addr = "http://127.0.0.1:8123",
endpoint_addr = "http://127.0.0.1:10420/clickhouse-logger/test",
max_retry_count = 1,
name = "clickhouse logger",
ssl_verify = false
Expand All @@ -91,8 +88,6 @@ passed
=== TEST 2: Basic configuration verification
--- yaml_config
plugins:
- clickhouse-logger
--- config
location /t {
content_by_lua_block {
Expand All @@ -101,7 +96,7 @@ plugins:
password = "a",
database = "default",
logtable = "t",
endpoint_addr = "http://127.0.0.1:8123"
endpoint_addr = "http://127.0.0.1:10420/clickhouse-logger/test"
})
if not ok then
Expand All @@ -118,8 +113,6 @@ passed
=== TEST 3: auth configure undefined
--- yaml_config
plugins:
- clickhouse-logger
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -147,8 +140,6 @@ property "endpoint_addr" is required
apisix:
node_listen: 1984
admin_key: null
plugins:
- clickhouse-logger
--- config
location /t {
content_by_lua_block {
Expand All @@ -162,7 +153,7 @@ plugins:
"password": "a",
"database": "default",
"logtable": "t",
"endpoint_addr": "http://127.0.0.1:8123"
"endpoint_addr": "http://127.0.0.1:10420/clickhouse-logger/test"
}
},
"upstream": {
Expand Down Expand Up @@ -190,7 +181,7 @@ plugins:
"max_retry_count":0,
"retry_delay":1,
"ssl_verify":true,
"endpoint_addr":"http://127.0.0.1:8123",
"endpoint_addr":"http://127.0.0.1:10420/clickhouse-logger/test",
"password":"a",
"buffer_duration":60,
"timeout":3,
Expand Down Expand Up @@ -224,4 +215,6 @@ passed
GET /opentracing
--- response_body
opentracing
--- wait: 2
--- grep_error_log_out
clickhouse body:
--- wait: 5

0 comments on commit 22c3fb0

Please sign in to comment.