From 22c3fb0d5bcbca5f19ed18df9896d21b703ca2ae Mon Sep 17 00:00:00 2001 From: qizhendong Date: Thu, 10 Feb 2022 14:09:15 +0800 Subject: [PATCH] fix doc and test cases --- apisix/plugins/clickhouse-logger.lua | 2 +- docs/en/latest/plugins/clickhouse-logger.md | 2 +- docs/zh/latest/plugins/clickhouse-logger.md | 2 +- t/plugin/clickhouse-logger.t | 25 ++++++++------------- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/apisix/plugins/clickhouse-logger.lua b/apisix/plugins/clickhouse-logger.lua index 416983721669..ef5234b7c8d7 100644 --- a/apisix/plugins/clickhouse-logger.lua +++ b/apisix/plugins/clickhouse-logger.lua @@ -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 diff --git a/docs/en/latest/plugins/clickhouse-logger.md b/docs/en/latest/plugins/clickhouse-logger.md index 11ca4490bb3d..4bec548b9766 100644 --- a/docs/en/latest/plugins/clickhouse-logger.md +++ b/docs/en/latest/plugins/clickhouse-logger.md @@ -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. diff --git a/docs/zh/latest/plugins/clickhouse-logger.md b/docs/zh/latest/plugins/clickhouse-logger.md index 3f816a638d14..8aa6d9b779aa 100644 --- a/docs/zh/latest/plugins/clickhouse-logger.md +++ b/docs/zh/latest/plugins/clickhouse-logger.md @@ -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 生效。 | ### 设置日志格式示例 diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index 99de12a6ac8c..25d860d62f61 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -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") } } @@ -58,8 +57,6 @@ __DATA__ === TEST 1: Full configuration verification --- yaml_config -plugins: - - clickhouse-logger --- config location /t { content_by_lua_block { @@ -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 @@ -91,8 +88,6 @@ passed === TEST 2: Basic configuration verification --- yaml_config -plugins: - - clickhouse-logger --- config location /t { content_by_lua_block { @@ -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 @@ -118,8 +113,6 @@ passed === TEST 3: auth configure undefined --- yaml_config -plugins: - - clickhouse-logger --- config location /t { content_by_lua_block { @@ -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 { @@ -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": { @@ -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, @@ -224,4 +215,6 @@ passed GET /opentracing --- response_body opentracing ---- wait: 2 +--- grep_error_log_out +clickhouse body: +--- wait: 5