From a2d395bb2ea9614bb2a7d56131757032aa7a61a1 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Thu, 27 Jan 2022 11:03:41 +0800 Subject: [PATCH 01/19] feat: clickhouse logger --- apisix/plugins/clickhouse-logger.lua | 231 +++++++++++++++++++++++++ conf/config-default.yaml | 1 + docs/en/latest/plugins/click-logger.md | 156 +++++++++++++++++ docs/zh/latest/plugins/click-logger.md | 158 +++++++++++++++++ t/plugin/clickhouse-logger.t | 194 +++++++++++++++++++++ 5 files changed, 740 insertions(+) create mode 100644 apisix/plugins/clickhouse-logger.lua create mode 100644 docs/en/latest/plugins/click-logger.md create mode 100644 docs/zh/latest/plugins/click-logger.md create mode 100644 t/plugin/clickhouse-logger.t diff --git a/apisix/plugins/clickhouse-logger.lua b/apisix/plugins/clickhouse-logger.lua new file mode 100644 index 000000000000..58b0ab5faa41 --- /dev/null +++ b/apisix/plugins/clickhouse-logger.lua @@ -0,0 +1,231 @@ +-- +-- 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. +-- + +local batch_processor = require("apisix.utils.batch-processor") +local log_util = require("apisix.utils.log-util") +local core = require("apisix.core") +local http = require("resty.http") +local url = require("net.url") +local plugin = require("apisix.plugin") + +local ngx = ngx +local tostring = tostring +local ipairs = ipairs +local timer_at = ngx.timer.at + +local plugin_name = "clickhouse-logger" +local stale_timer_running = false +local buffers = {} + +local schema = { + type = "object", + properties = { + endpoint_addr = core.schema.uri_def, + user = {type = "string", default = ""}, + password = {type = "string", default = ""}, + database = {type = "string", default = ""}, + logtable = {type = "string", default = ""}, + timeout = {type = "integer", minimum = 1, default = 3}, + name = {type = "string", default = "clickhouse logger"}, + max_retry_count = {type = "integer", minimum = 0, default = 0}, + retry_delay = {type = "integer", minimum = 0, default = 1}, + batch_max_size = {type = "integer", minimum = 1, default = 100} + }, + required = {"endpoint_addr", "user", "password", "database", "logtable"} +} + + +local metadata_schema = { + type = "object", + properties = { + log_format = log_util.metadata_schema_log_format, + }, +} + + +local _M = { + version = 0.1, + priority = 399, + name = plugin_name, + schema = schema, + metadata_schema = metadata_schema, +} + + +function _M.check_schema(conf, schema_type) + if schema_type == core.schema.TYPE_METADATA then + return core.schema.check(metadata_schema, conf) + end + return core.schema.check(schema, conf) +end + + +local function send_http_data(conf, log_message) + local err_msg + local res = true + local url_decoded = url.parse(conf.endpoint_addr) + local host = url_decoded.host + local port = url_decoded.port + + core.log.info("sending a batch logs to ", conf.endpoint_addr) + + if ((not port) and url_decoded.scheme == "https") then + port = 443 + elseif not port then + port = 80 + end + + local httpc = http.new() + httpc:set_timeout(conf.timeout * 1000) + local ok, err = httpc:connect(host, port) + + if not ok then + return false, "failed to connect to host[" .. host .. "] port[" + .. tostring(port) .. "] " .. err + end + + if url_decoded.scheme == "https" then + ok, err = httpc:ssl_handshake(true, host, false) + if not ok then + return false, "failed to perform SSL with host[" .. host .. "] " + .. "port[" .. tostring(port) .. "] " .. err + end + end + url_decoded.query['database'] = conf.database + + local httpc_res, httpc_err = httpc:request({ + method = "POST", + path = url_decoded.path, + query = url_decoded.query, + body = "INSERT INTO " .. conf.logtable .." FORMAT JSONEachRow " .. log_message, + headers = { + ["Host"] = url_decoded.host, + ["Content-Type"] = "application/json", + ["X-ClickHouse-User"] = conf.user, + ["X-ClickHouse-Key"] = conf.password, + } + }) + + if not httpc_res then + return false, "error while sending data to [" .. host .. "] port[" + .. tostring(port) .. "] " .. httpc_err + end + + -- some error occurred in the server + if httpc_res.status >= 400 then + res = false + err_msg = "server returned status code[" .. httpc_res.status .. "] host[" + .. host .. "] port[" .. tostring(port) .. "] " + .. "body[" .. httpc_res:read_body() .. "]" + end + + return res, err_msg +end + + +-- remove stale objects from the memory after timer expires +local function remove_stale_objects(premature) + if premature then + return + end + + for key, batch in ipairs(buffers) do + if #batch.entry_buffer.entries == 0 and #batch.batch_to_process == 0 then + core.log.warn("removing batch processor stale object, conf: ", + core.json.delay_encode(key)) + buffers[key] = nil + end + end + + stale_timer_running = false +end + + +function _M.log(conf, ctx) + local metadata = plugin.plugin_metadata("http-logger") + core.log.info("metadata: ", core.json.delay_encode(metadata)) + local entry + + if metadata and metadata.value.log_format + and core.table.nkeys(metadata.value.log_format) > 0 + then + entry = log_util.get_custom_format_log(ctx, metadata.value.log_format) + else + entry = log_util.get_full_log(ngx, conf) + end + + if not entry.route_id then + entry.route_id = "no-matched" + end + + if not stale_timer_running then + -- run the timer every 30 mins if any log is present + timer_at(1800, remove_stale_objects) + stale_timer_running = true + end + + local log_buffer = buffers[conf] + if log_buffer then + log_buffer:push(entry) + return + end + + -- Generate a function to be executed by the batch processor + local func = function(entries, batch_max_size) + local data, err + + if batch_max_size == 1 then + data, err = core.json.encode(entries[1]) -- encode as single {} + else + local log_table = {} + for i = 1, #entries do + table.insert(log_table, core.json.encode(entries[i])) + end + data = table.concat(log_table, " ") -- assemble multi items as string "{} {}" + end + + if not data then + return false, 'error occurred while encoding the data: ' .. err + end + + return send_http_data(conf, data) + end + + local config = { + name = conf.name, + retry_delay = conf.retry_delay, + batch_max_size = conf.batch_max_size, + max_retry_count = conf.max_retry_count, + route_id = ctx.var.route_id, + server_addr = ctx.var.server_addr, + } + + local err + log_buffer, err = batch_processor:new(func, config) + + if not log_buffer then + core.log.error("error when creating the batch processor: ", err) + return + end + + buffers[conf] = log_buffer + log_buffer:push(entry) +end + + +return _M + diff --git a/conf/config-default.yaml b/conf/config-default.yaml index e2897abab282..10e24845a360 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -381,6 +381,7 @@ plugins: # plugin list (sorted by priority) - rocketmq-logger # priority: 402 - syslog # priority: 401 - udp-logger # priority: 400 + #- clickhouse-logger # priority: 399 - file-logger # priority: 399 #- log-rotate # priority: 100 # <- recommend to use priority (0, 100) for your custom plugins diff --git a/docs/en/latest/plugins/click-logger.md b/docs/en/latest/plugins/click-logger.md new file mode 100644 index 000000000000..d26e85ec10d8 --- /dev/null +++ b/docs/en/latest/plugins/click-logger.md @@ -0,0 +1,156 @@ +--- +title: clickhouse-logger +--- + + + +## Summary + +- [**Name**](#name) +- [**Attributes**](#attributes) +- [**How To Enable**](#how-to-enable) +- [**Test Plugin**](#test-plugin) +- [**Metadata**](#metadata) +- [**Disable Plugin**](#disable-plugin) + +## Name + +`clickhouse-logger` is a plugin which push Log data requests to clickhouse. + +## Attributes + +| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | +| ---------------- | ------- | ------ | ------------- | ------- | ------------------------------------------------ | +| endpoint_addr | string | required | | | The `clickhouse` endpoint. | +| database | string | required | | | The DB name to store log. | +| logtable | string | required | | | The table name. | +| user | string | required | | |clickhouse user. | +| password | string | required | | |clickhouse password. | +| timeout | integer | optional | 3 | [1,...] | Time to keep the connection alive after sending a request. | +| name | string | optional | "clickhouse logger" | | A unique identifier to identity the logger. | +| batch_max_size | integer | optional | 100 | [1,...] | Set the maximum number of logs sent in each batch. When the number of logs reaches the set maximum, all logs will be automatically pushed to the clickhouse. | +| max_retry_count | integer | optional | 0 | [0,...] | Maximum number of retries before removing from the processing pipe line. | +| retry_delay | integer | optional | 1 | [0,...] | Number of seconds the process execution should be delayed if the execution fails. | + + +## How To Enable + +The following is an example of how to enable the `click-logger` for a specific route. + +```shell +curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +{ + "plugins": { + "clickhouse-logger": { + "user": "default", + "password": "a", + "database": "default", + "logtable": "test", + "endpoint_addr": "http://127.0.0.1:8123" + } + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1 + } + }, + "uri": "/hello" +}' +``` + +## Test Plugin + +> success: + +```shell +$ curl -i http://127.0.0.1:9080/hello +HTTP/1.1 200 OK +... +hello, world +``` + +## Metadata + +| 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). | + + 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. + +**APISIX Variables** + +| Variable Name | Description | Usage Example | +|------------------|-------------------------|----------------| +| route_id | id of `route` | $route_id | +| route_name | name of `route` | $route_name | +| service_id | id of `service` | $service_id | +| service_name | name of `service` | $service_name | +| consumer_name | username of `consumer` | $consumer_name | + +### Example + +```shell +curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +{ + "log_format": { + "host": "$host", + "@timestamp": "$time_iso8601", + "client_ip": "$remote_addr" + } +}' +``` +create logtable +```sql +CREATE TABLE default.test ( + `host` String, + `client_ip` String, + `route_id` String, + `@timestamp` String, + PRIMARY KEY(`@timestamp`) +) ENGINE = MergeTree() +``` + +On clickhouse run `select * from default.test;`, will got below row: +``` +┌─host──────┬─client_ip─┬─route_id─┬─@timestamp────────────────┐ +│ 127.0.0.1 │ 127.0.0.1 │ 1 │ 2022-01-17T10:03:10+08:00 │ +└───────────┴───────────┴──────────┴───────────────────────────┘ +``` + +## Disable Plugin + +Remove the corresponding json configuration in the plugin configuration to disable the `clickhouse-logger`. +APISIX plugins are hot-reloaded, therefore no need to restart APISIX. + +```shell +$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +{ + "uri": "/hello", + "plugins": {}, + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1 + } + } +}' +``` + diff --git a/docs/zh/latest/plugins/click-logger.md b/docs/zh/latest/plugins/click-logger.md new file mode 100644 index 000000000000..636bd33804b8 --- /dev/null +++ b/docs/zh/latest/plugins/click-logger.md @@ -0,0 +1,158 @@ +--- +title: clickhouse-logger +--- + + + +## 目录 + +- [**定义**](#定义) +- [**属性列表**](#属性列表) +- [**如何开启**](#如何开启) +- [**测试插件**](#测试插件) +- [**插件元数据设置**](#插件元数据设置) +- [**禁用插件**](#禁用插件) + +## 定义 + +`clickhouse-logger` 是一个插件,可将Log数据请求推送到clickhouse服务器。 + + +## 属性列表 + +| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | +| ---------------- | ------- | ------ | ------------- | ------- | ------------------------------------------------ | +| endpoint_addr | string | 必须 | | | `clickhouse` 服务器的 endpoint。 | +| database | string | 必须 | | | 使用的数据库。 | +| logtable | string | 必须 | | | 写入的表名 。 | +| user | string | 必须 | | |clickhouse的用户。 | +| password | string | 必须 | | |clickhouse的密码 。 | +| timeout | integer | 可选 | 3 | [1,...] | 发送请求后保持连接活动的时间。 | +| name | string | 可选 | "clickhouse logger" | | 标识 logger 的唯一标识符。 | +| batch_max_size | integer | 可选 | 100 | [1,...] | 设置每批发送日志的最大条数,当日志条数达到设置的最大值时,会自动推送全部日志到 `clickhouse` 。 | +| max_retry_count | integer | 可选 | 0 | [0,...] | 从处理管道中移除之前的最大重试次数。 | +| retry_delay | integer | 可选 | 1 | [0,...] | 如果执行失败,则应延迟执行流程的秒数。 | + + +## 如何开启 + +这是有关如何为特定路由启用 `clickhouse-logger` 插件的示例。 + +```shell +curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +{ + "plugins": { + "clickhouse-logger": { + "user": "default", + "password": "a", + "database": "default", + "logtable": "test", + "endpoint_addr": "http://127.0.0.1:8123" + } + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1 + } + }, + "uri": "/hello" +}' +``` + +## 测试插件 + +> 成功: + +```shell +$ curl -i http://127.0.0.1:9080/hello +HTTP/1.1 200 OK +... +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 生效。 | + +**APISIX 变量** + +| 变量名 | 描述 | 使用示例 | +|------------------|-------------------------|----------------| +| route_id | `route` 的 id | $route_id | +| route_name | `route` 的 name | $route_name | +| service_id | `service` 的 id | $service_id | +| service_name | `service` 的 name | $service_name | +| consumer_name | `consumer` 的 username | $consumer_name | + +### 设置日志格式示例 + +```shell +curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +{ + "log_format": { + "host": "$host", + "@timestamp": "$time_iso8601", + "client_ip": "$remote_addr" + } +}' +``` + + +创建logtable +```sql +CREATE TABLE default.test ( + `host` String, + `client_ip` String, + `route_id` String, + `@timestamp` String, + PRIMARY KEY(`@timestamp`) +) ENGINE = MergeTree() +``` + +在clickhouse上执行`select * from default.test;`,将得到类似下面的数据: +``` +┌─host──────┬─client_ip─┬─route_id─┬─@timestamp────────────────┐ +│ 127.0.0.1 │ 127.0.0.1 │ 1 │ 2022-01-17T10:03:10+08:00 │ +└───────────┴───────────┴──────────┴───────────────────────────┘ +``` + + +## 禁用插件 + +在插件配置中删除相应的 json 配置以禁用 clickhouse-logger。APISIX 插件是热重载的,因此无需重新启动 APISIX: + +```shell +$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +{ + "methods": ["GET"], + "uri": "/hello", + "plugins": {}, + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1 + } + } +}' +``` + diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t new file mode 100644 index 000000000000..cea4cb2685f2 --- /dev/null +++ b/t/plugin/clickhouse-logger.t @@ -0,0 +1,194 @@ +# +# 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'; + +repeat_each(1); +no_long_string(); +no_root_location(); + +add_block_preprocessor(sub { + my ($block) = @_; + + if ((!defined $block->error_log) && (!defined $block->no_error_log)) { + $block->set_value("no_error_log", "[error]"); + } + + if (!defined $block->request) { + $block->set_value("request", "GET /t"); + } + +}); + +run_tests(); + +__DATA__ + +=== TEST 1: Full configuration verification +--- config + location /t { + content_by_lua_block { + local plugin = require("apisix.plugins.clickhouse-logger") + local ok, err = plugin.check_schema({ + "timeout": 3, + "retry_delay": 1, + "batch_max_size": 500, + "user": "default", + "password": "a", + "database": "default", + "logtable": "t", + "endpoint_addr": "http://127.0.0.1:8123", + "max_retry_count": 1, + "name": "clickhouse logger" + }) + + if not ok then + ngx.say(err) + else + ngx.say("passed") + end + } + } +--- response_body +passed + + + +=== TEST 2: Basic configuration verification +--- config + location /t { + content_by_lua_block { + local plugin = require("apisix.plugins.clickhouse-logger") + local ok, err = plugin.check_schema({ + "user": "default", + "password": "a", + "database": "default", + "logtable": "t", + "endpoint_addr": "http://127.0.0.1:8123" + }) + + if not ok then + ngx.say(err) + else + ngx.say("passed") + end + } + } +--- response_body +passed + + + +=== TEST 3: auth configure undefined +--- config + location /t { + content_by_lua_block { + local plugin = require("apisix.plugins.clickhouse-logger") + local ok, err = plugin.check_schema({ + log_id = "syslog", + max_retry_count = 0, + retry_delay = 1, + buffer_duration = 60, + inactive_timeout = 10, + batch_max_size = 100, + }) + if not ok then + ngx.say(err) + else + ngx.say("passed") + end + } + } +--- response_body +value should match only one schema, but matches none + + + +=== TEST 4: add plugin on routes +--- 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": { + "clickhouse-logger": { + "user": "default", + "password": "a", + "database": "default", + "logtable": "t", + "endpoint_addr": "http://127.0.0.1:8123" + } + }, + "upstream": { + "nodes": { + "127.0.0.1:1982": 1 + }, + "type": "roundrobin" + }, + "uri": "/opentracing" + }]], + [[{ + "node": { + "value": { + "plugins": { + "clickhouse-logger": { + "user": "default", + "password": "a", + "database": "default", + "logtable": "t", + "endpoint_addr": "http://127.0.0.1:8123" + } + }, + "upstream": { + "nodes": { + "127.0.0.1:1982": 1 + }, + "type": "roundrobin" + }, + "uri": "/opentracing" + }, + "key": "/apisix/routes/1" + }, + "action": "set" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 5: access local server +--- request +GET /opentracing +--- response_body +opentracing +--- error_log +Batch Processor[http logger] successfully processed the entries +--- wait: 0.5 From 234ac0428779b6ae8e7700b6c9de42c12b28f06f Mon Sep 17 00:00:00 2001 From: qizhendong Date: Thu, 27 Jan 2022 15:02:46 +0800 Subject: [PATCH 02/19] fix code lint error --- apisix/plugins/clickhouse-logger.lua | 4 ++-- docs/en/latest/plugins/click-logger.md | 5 ++--- docs/zh/latest/plugins/click-logger.md | 4 +--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/apisix/plugins/clickhouse-logger.lua b/apisix/plugins/clickhouse-logger.lua index 58b0ab5faa41..2c85c294e6ff 100644 --- a/apisix/plugins/clickhouse-logger.lua +++ b/apisix/plugins/clickhouse-logger.lua @@ -193,9 +193,9 @@ function _M.log(conf, ctx) else local log_table = {} for i = 1, #entries do - table.insert(log_table, core.json.encode(entries[i])) + core.table.insert(log_table, core.json.encode(entries[i])) end - data = table.concat(log_table, " ") -- assemble multi items as string "{} {}" + data = core.table.concat(log_table, " ") -- assemble multi items as string "{} {}" end if not data then diff --git a/docs/en/latest/plugins/click-logger.md b/docs/en/latest/plugins/click-logger.md index d26e85ec10d8..1bd81289bd4a 100644 --- a/docs/en/latest/plugins/click-logger.md +++ b/docs/en/latest/plugins/click-logger.md @@ -49,7 +49,6 @@ title: clickhouse-logger | max_retry_count | integer | optional | 0 | [0,...] | Maximum number of retries before removing from the processing pipe line. | | retry_delay | integer | optional | 1 | [0,...] | Number of seconds the process execution should be delayed if the execution fails. | - ## How To Enable The following is an example of how to enable the `click-logger` for a specific route. @@ -86,7 +85,6 @@ HTTP/1.1 200 OK ... hello, world ``` - ## Metadata | Name | Type | Requirement | Default | Valid | Description | @@ -117,7 +115,9 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KE } }' ``` + create logtable + ```sql CREATE TABLE default.test ( `host` String, @@ -153,4 +153,3 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335 } }' ``` - diff --git a/docs/zh/latest/plugins/click-logger.md b/docs/zh/latest/plugins/click-logger.md index 636bd33804b8..d60d130bfc64 100644 --- a/docs/zh/latest/plugins/click-logger.md +++ b/docs/zh/latest/plugins/click-logger.md @@ -117,7 +117,6 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KE }' ``` - 创建logtable ```sql CREATE TABLE default.test ( @@ -130,13 +129,13 @@ CREATE TABLE default.test ( ``` 在clickhouse上执行`select * from default.test;`,将得到类似下面的数据: + ``` ┌─host──────┬─client_ip─┬─route_id─┬─@timestamp────────────────┐ │ 127.0.0.1 │ 127.0.0.1 │ 1 │ 2022-01-17T10:03:10+08:00 │ └───────────┴───────────┴──────────┴───────────────────────────┘ ``` - ## 禁用插件 在插件配置中删除相应的 json 配置以禁用 clickhouse-logger。APISIX 插件是热重载的,因此无需重新启动 APISIX: @@ -155,4 +154,3 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335 } }' ``` - From 26830e52ead59ab319eababafe84f13a21d87606 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Thu, 27 Jan 2022 15:10:57 +0800 Subject: [PATCH 03/19] fix code lint error --- docs/en/latest/plugins/click-logger.md | 6 ++++-- docs/zh/latest/plugins/click-logger.md | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/en/latest/plugins/click-logger.md b/docs/en/latest/plugins/click-logger.md index 1bd81289bd4a..8eed82c38724 100644 --- a/docs/en/latest/plugins/click-logger.md +++ b/docs/en/latest/plugins/click-logger.md @@ -51,7 +51,7 @@ title: clickhouse-logger ## How To Enable -The following is an example of how to enable the `click-logger` for a specific route. +The following is an example of how to enable the `click-logger` for a specific route. ```shell curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' @@ -85,6 +85,7 @@ HTTP/1.1 200 OK ... hello, world ``` + ## Metadata | Name | Type | Requirement | Default | Valid | Description | @@ -128,7 +129,8 @@ CREATE TABLE default.test ( ) ENGINE = MergeTree() ``` -On clickhouse run `select * from default.test;`, will got below row: +On clickhouse run `select * from default.test;`, will got below row: + ``` ┌─host──────┬─client_ip─┬─route_id─┬─@timestamp────────────────┐ │ 127.0.0.1 │ 127.0.0.1 │ 1 │ 2022-01-17T10:03:10+08:00 │ diff --git a/docs/zh/latest/plugins/click-logger.md b/docs/zh/latest/plugins/click-logger.md index d60d130bfc64..d831d6b62333 100644 --- a/docs/zh/latest/plugins/click-logger.md +++ b/docs/zh/latest/plugins/click-logger.md @@ -34,7 +34,6 @@ title: clickhouse-logger `clickhouse-logger` 是一个插件,可将Log数据请求推送到clickhouse服务器。 - ## 属性列表 | 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 | @@ -50,7 +49,6 @@ title: clickhouse-logger | max_retry_count | integer | 可选 | 0 | [0,...] | 从处理管道中移除之前的最大重试次数。 | | retry_delay | integer | 可选 | 1 | [0,...] | 如果执行失败,则应延迟执行流程的秒数。 | - ## 如何开启 这是有关如何为特定路由启用 `clickhouse-logger` 插件的示例。 @@ -118,6 +116,7 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KE ``` 创建logtable + ```sql CREATE TABLE default.test ( `host` String, From ac2a148a9e063a6b6f7c1eab4f88f768319192f1 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Thu, 27 Jan 2022 15:47:02 +0800 Subject: [PATCH 04/19] add doc on sidebar config.json --- docs/en/latest/config.json | 1 + docs/en/latest/plugins/{click-logger.md => clickhouse-logger.md} | 0 docs/zh/latest/config.json | 1 + docs/zh/latest/plugins/{click-logger.md => clickhouse-logger.md} | 0 4 files changed, 2 insertions(+) rename docs/en/latest/plugins/{click-logger.md => clickhouse-logger.md} (100%) rename docs/zh/latest/plugins/{click-logger.md => clickhouse-logger.md} (100%) diff --git a/docs/en/latest/config.json b/docs/en/latest/config.json index f99e528ec937..a1897a3a29e1 100644 --- a/docs/en/latest/config.json +++ b/docs/en/latest/config.json @@ -124,6 +124,7 @@ "plugins/kafka-logger", "plugins/rocketmq-logger", "plugins/udp-logger", + "plugins/clickhouse-logger", "plugins/syslog", "plugins/log-rotate", "plugins/error-log-logger", diff --git a/docs/en/latest/plugins/click-logger.md b/docs/en/latest/plugins/clickhouse-logger.md similarity index 100% rename from docs/en/latest/plugins/click-logger.md rename to docs/en/latest/plugins/clickhouse-logger.md diff --git a/docs/zh/latest/config.json b/docs/zh/latest/config.json index 22026bedaad2..2cdd009a7894 100644 --- a/docs/zh/latest/config.json +++ b/docs/zh/latest/config.json @@ -119,6 +119,7 @@ "plugins/kafka-logger", "plugins/rocketmq-logger", "plugins/udp-logger", + "plugins/clickhouse-logger", "plugins/syslog", "plugins/log-rotate", "plugins/error-log-logger", diff --git a/docs/zh/latest/plugins/click-logger.md b/docs/zh/latest/plugins/clickhouse-logger.md similarity index 100% rename from docs/zh/latest/plugins/click-logger.md rename to docs/zh/latest/plugins/clickhouse-logger.md From 5a3ed37cba64a41cae6246ad7358a4843e5b6d04 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Fri, 28 Jan 2022 11:27:47 +0800 Subject: [PATCH 05/19] using batch process manager --- apisix/plugins/clickhouse-logger.lua | 64 +++------------------------- conf/config-default.yaml | 2 +- t/plugin/clickhouse-logger.t | 19 ++++++++- 3 files changed, 25 insertions(+), 60 deletions(-) diff --git a/apisix/plugins/clickhouse-logger.lua b/apisix/plugins/clickhouse-logger.lua index 2c85c294e6ff..5dfdd0a60adf 100644 --- a/apisix/plugins/clickhouse-logger.lua +++ b/apisix/plugins/clickhouse-logger.lua @@ -15,7 +15,7 @@ -- limitations under the License. -- -local batch_processor = require("apisix.utils.batch-processor") +local bp_manager_mod = require("apisix.utils.batch-processor-manager") local log_util = require("apisix.utils.log-util") local core = require("apisix.core") local http = require("resty.http") @@ -24,12 +24,9 @@ local plugin = require("apisix.plugin") local ngx = ngx local tostring = tostring -local ipairs = ipairs -local timer_at = ngx.timer.at local plugin_name = "clickhouse-logger" -local stale_timer_running = false -local buffers = {} +local batch_processor_manager = bp_manager_mod.new(plugin_name) local schema = { type = "object", @@ -59,7 +56,7 @@ local metadata_schema = { local _M = { version = 0.1, - priority = 399, + priority = 398, name = plugin_name, schema = schema, metadata_schema = metadata_schema, @@ -105,7 +102,6 @@ local function send_http_data(conf, log_message) .. "port[" .. tostring(port) .. "] " .. err end end - url_decoded.query['database'] = conf.database local httpc_res, httpc_err = httpc:request({ method = "POST", @@ -117,6 +113,7 @@ local function send_http_data(conf, log_message) ["Content-Type"] = "application/json", ["X-ClickHouse-User"] = conf.user, ["X-ClickHouse-Key"] = conf.password, + ["X-ClickHouse-Database"] = conf.database } }) @@ -137,24 +134,6 @@ local function send_http_data(conf, log_message) end --- remove stale objects from the memory after timer expires -local function remove_stale_objects(premature) - if premature then - return - end - - for key, batch in ipairs(buffers) do - if #batch.entry_buffer.entries == 0 and #batch.batch_to_process == 0 then - core.log.warn("removing batch processor stale object, conf: ", - core.json.delay_encode(key)) - buffers[key] = nil - end - end - - stale_timer_running = false -end - - function _M.log(conf, ctx) local metadata = plugin.plugin_metadata("http-logger") core.log.info("metadata: ", core.json.delay_encode(metadata)) @@ -168,19 +147,7 @@ function _M.log(conf, ctx) entry = log_util.get_full_log(ngx, conf) end - if not entry.route_id then - entry.route_id = "no-matched" - end - - if not stale_timer_running then - -- run the timer every 30 mins if any log is present - timer_at(1800, remove_stale_objects) - stale_timer_running = true - end - - local log_buffer = buffers[conf] - if log_buffer then - log_buffer:push(entry) + if batch_processor_manager:add_entry(conf, entry) then return end @@ -205,27 +172,8 @@ function _M.log(conf, ctx) return send_http_data(conf, data) end - local config = { - name = conf.name, - retry_delay = conf.retry_delay, - batch_max_size = conf.batch_max_size, - max_retry_count = conf.max_retry_count, - route_id = ctx.var.route_id, - server_addr = ctx.var.server_addr, - } - - local err - log_buffer, err = batch_processor:new(func, config) - - if not log_buffer then - core.log.error("error when creating the batch processor: ", err) - return - end - - buffers[conf] = log_buffer - log_buffer:push(entry) + batch_processor_manager:add_entry_to_new_processor(conf, entry, ctx, func) end return _M - diff --git a/conf/config-default.yaml b/conf/config-default.yaml index 10e24845a360..af5092dd4300 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -381,8 +381,8 @@ plugins: # plugin list (sorted by priority) - rocketmq-logger # priority: 402 - syslog # priority: 401 - udp-logger # priority: 400 - #- clickhouse-logger # priority: 399 - file-logger # priority: 399 + #- clickhouse-logger # priority: 398 #- log-rotate # priority: 100 # <- recommend to use priority (0, 100) for your custom plugins - example-plugin # priority: 0 diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index cea4cb2685f2..1b4273ca7b63 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -32,6 +32,23 @@ add_block_preprocessor(sub { $block->set_value("request", "GET /t"); } + my $http_config = $block->http_config // <<_EOC_; + server { + listen 10420; + location /loggly/bulk/tok/tag/bulk { + 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.say("ok") + } + } + } +_EOC_ + + $block->set_value("http_config", $http_config); }); run_tests(); @@ -190,5 +207,5 @@ GET /opentracing --- response_body opentracing --- error_log -Batch Processor[http logger] successfully processed the entries +Batch Processor[clickhouse logger] successfully processed the entries --- wait: 0.5 From bdd18930946ba3e0e6b5e04a38b43a3dc91062db Mon Sep 17 00:00:00 2001 From: qizhendong Date: Fri, 28 Jan 2022 11:30:41 +0800 Subject: [PATCH 06/19] fix misspell --- docs/en/latest/plugins/clickhouse-logger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/latest/plugins/clickhouse-logger.md b/docs/en/latest/plugins/clickhouse-logger.md index 8eed82c38724..a49ce695d923 100644 --- a/docs/en/latest/plugins/clickhouse-logger.md +++ b/docs/en/latest/plugins/clickhouse-logger.md @@ -51,7 +51,7 @@ title: clickhouse-logger ## How To Enable -The following is an example of how to enable the `click-logger` for a specific route. +The following is an example of how to enable the `clickhouse-logger` for a specific route. ```shell curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' From d9a898504bb8a784c25b2325296902c6e2af6dba Mon Sep 17 00:00:00 2001 From: qizhendong Date: Fri, 28 Jan 2022 14:35:16 +0800 Subject: [PATCH 07/19] add ssl verify --- apisix/plugins/clickhouse-logger.lua | 15 +++++++++------ docs/en/latest/plugins/clickhouse-logger.md | 1 + docs/zh/latest/plugins/clickhouse-logger.md | 1 + t/plugin/clickhouse-logger.t | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apisix/plugins/clickhouse-logger.lua b/apisix/plugins/clickhouse-logger.lua index 5dfdd0a60adf..7206e863e395 100644 --- a/apisix/plugins/clickhouse-logger.lua +++ b/apisix/plugins/clickhouse-logger.lua @@ -40,7 +40,8 @@ local schema = { name = {type = "string", default = "clickhouse logger"}, max_retry_count = {type = "integer", minimum = 0, default = 0}, retry_delay = {type = "integer", minimum = 0, default = 1}, - batch_max_size = {type = "integer", minimum = 1, default = 100} + batch_max_size = {type = "integer", minimum = 1, default = 100}, + ssl_verify = {type = "boolean", default = true}, }, required = {"endpoint_addr", "user", "password", "database", "logtable"} } @@ -80,10 +81,12 @@ local function send_http_data(conf, log_message) core.log.info("sending a batch logs to ", conf.endpoint_addr) - if ((not port) and url_decoded.scheme == "https") then - port = 443 - elseif not port then - port = 80 + if not port then + if url_decoded.scheme == "https" then + port = 443 + else + port = 80 + end end local httpc = http.new() @@ -95,7 +98,7 @@ local function send_http_data(conf, log_message) .. tostring(port) .. "] " .. err end - if url_decoded.scheme == "https" then + if url_decoded.scheme == "https" and conf.ssl_verify then ok, err = httpc:ssl_handshake(true, host, false) if not ok then return false, "failed to perform SSL with host[" .. host .. "] " diff --git a/docs/en/latest/plugins/clickhouse-logger.md b/docs/en/latest/plugins/clickhouse-logger.md index a49ce695d923..577d24407d9e 100644 --- a/docs/en/latest/plugins/clickhouse-logger.md +++ b/docs/en/latest/plugins/clickhouse-logger.md @@ -48,6 +48,7 @@ title: clickhouse-logger | batch_max_size | integer | optional | 100 | [1,...] | Set the maximum number of logs sent in each batch. When the number of logs reaches the set maximum, all logs will be automatically pushed to the clickhouse. | | max_retry_count | integer | optional | 0 | [0,...] | Maximum number of retries before removing from the processing pipe line. | | retry_delay | integer | optional | 1 | [0,...] | Number of seconds the process execution should be delayed if the execution fails. | +| ssl_verify | boolean | optional | true | [true,false] | verify ssl. | ## How To Enable diff --git a/docs/zh/latest/plugins/clickhouse-logger.md b/docs/zh/latest/plugins/clickhouse-logger.md index d831d6b62333..ae143ebdff64 100644 --- a/docs/zh/latest/plugins/clickhouse-logger.md +++ b/docs/zh/latest/plugins/clickhouse-logger.md @@ -48,6 +48,7 @@ title: clickhouse-logger | batch_max_size | integer | 可选 | 100 | [1,...] | 设置每批发送日志的最大条数,当日志条数达到设置的最大值时,会自动推送全部日志到 `clickhouse` 。 | | max_retry_count | integer | 可选 | 0 | [0,...] | 从处理管道中移除之前的最大重试次数。 | | retry_delay | integer | 可选 | 1 | [0,...] | 如果执行失败,则应延迟执行流程的秒数。 | +| ssl_verify | boolean | 可选 | true | [true,false] | 验证证书。 | ## 如何开启 diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index 1b4273ca7b63..7568c0d9b8c9 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -70,7 +70,8 @@ __DATA__ "logtable": "t", "endpoint_addr": "http://127.0.0.1:8123", "max_retry_count": 1, - "name": "clickhouse logger" + "name": "clickhouse logger", + "ssl_verify": false }) if not ok then From c268d5cfd7321d10d0e7a7ac6f6c43bae210d5b0 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Fri, 28 Jan 2022 16:04:52 +0800 Subject: [PATCH 08/19] using clickhouse-logger metadata --- apisix/plugins/clickhouse-logger.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apisix/plugins/clickhouse-logger.lua b/apisix/plugins/clickhouse-logger.lua index 7206e863e395..2bfa98167292 100644 --- a/apisix/plugins/clickhouse-logger.lua +++ b/apisix/plugins/clickhouse-logger.lua @@ -138,7 +138,7 @@ end function _M.log(conf, ctx) - local metadata = plugin.plugin_metadata("http-logger") + local metadata = plugin.plugin_metadata(plugin_name) core.log.info("metadata: ", core.json.delay_encode(metadata)) local entry From f2349555b6412736e20c6893e57a29e3ea222b85 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Sat, 29 Jan 2022 14:47:37 +0800 Subject: [PATCH 09/19] fix test cases fail --- t/plugin/clickhouse-logger.t | 53 +++++++++++++++++------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index 7568c0d9b8c9..ab908b12831a 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -60,19 +60,18 @@ __DATA__ location /t { content_by_lua_block { local plugin = require("apisix.plugins.clickhouse-logger") - local ok, err = plugin.check_schema({ - "timeout": 3, - "retry_delay": 1, - "batch_max_size": 500, - "user": "default", - "password": "a", - "database": "default", - "logtable": "t", - "endpoint_addr": "http://127.0.0.1:8123", - "max_retry_count": 1, - "name": "clickhouse logger", - "ssl_verify": false - }) + local ok, err = plugin.check_schema({timeout = 3, + retry_delay = 1, + batch_max_size = 500, + user = "default", + password = "a", + database = "default", + logtable = "t", + endpoint_addr = "http://127.0.0.1:8123", + max_retry_count = 1, + name = "clickhouse logger", + ssl_verify = false + }) if not ok then ngx.say(err) @@ -91,13 +90,12 @@ passed location /t { content_by_lua_block { local plugin = require("apisix.plugins.clickhouse-logger") - local ok, err = plugin.check_schema({ - "user": "default", - "password": "a", - "database": "default", - "logtable": "t", - "endpoint_addr": "http://127.0.0.1:8123" - }) + local ok, err = plugin.check_schema({user = "default", + password = "a", + database = "default", + logtable = "t", + endpoint_addr = "http://127.0.0.1:8123" + }) if not ok then ngx.say(err) @@ -116,14 +114,13 @@ passed location /t { content_by_lua_block { local plugin = require("apisix.plugins.clickhouse-logger") - local ok, err = plugin.check_schema({ - log_id = "syslog", - max_retry_count = 0, - retry_delay = 1, - buffer_duration = 60, - inactive_timeout = 10, - batch_max_size = 100, - }) + local ok, err = plugin.check_schema({log_id = "syslog", + max_retry_count = 0, + retry_delay = 1, + buffer_duration = 60, + inactive_timeout = 10, + batch_max_size = 100, + }) if not ok then ngx.say(err) else From e0b5f3d28b9c394eba64c41ea63a4e5bd3896288 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Sun, 30 Jan 2022 11:09:38 +0800 Subject: [PATCH 10/19] fix test case 'auth configure undefined' --- t/plugin/clickhouse-logger.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index ab908b12831a..cd327f1d8eee 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -129,7 +129,7 @@ passed } } --- response_body -value should match only one schema, but matches none +{"error_msg":"failed to check the configuration of plugin clickhouse-logger err: property \"endpoint_addr\" is required"} @@ -205,5 +205,5 @@ GET /opentracing --- response_body opentracing --- error_log -Batch Processor[clickhouse logger] successfully processed the entries +Batch Processor[clickhouse logger] failed to process entries --- wait: 0.5 From 27995aa9fcf4a725fd56825f3ab7b3c1abf6ee4a Mon Sep 17 00:00:00 2001 From: qizhendong Date: Sun, 30 Jan 2022 13:55:41 +0800 Subject: [PATCH 11/19] fix test case 'auth configure undefined' --- t/plugin/clickhouse-logger.t | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index cd327f1d8eee..dc7ed0e05cd2 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -56,6 +56,9 @@ run_tests(); __DATA__ === TEST 1: Full configuration verification +--- yaml_config +plugins: + - clickhouse-logger --- config location /t { content_by_lua_block { @@ -86,6 +89,9 @@ passed === TEST 2: Basic configuration verification +--- yaml_config +plugins: + - clickhouse-logger --- config location /t { content_by_lua_block { @@ -110,6 +116,9 @@ passed === TEST 3: auth configure undefined +--- yaml_config +plugins: + - clickhouse-logger --- config location /t { content_by_lua_block { @@ -128,12 +137,14 @@ passed end } } ---- response_body -{"error_msg":"failed to check the configuration of plugin clickhouse-logger err: property \"endpoint_addr\" is required"} - +--- response_body eval +qr/\{"error_msg":"failed to check the configuration of plugin clickhouse-logger err: property \\"endpoint_addr\\" is required"\}/ === TEST 4: add plugin on routes +--- yaml_config +plugins: + - clickhouse-logger --- config location /t { content_by_lua_block { From 74d59b5b9d562421713dcb5f65cd82dcecac9cfc Mon Sep 17 00:00:00 2001 From: qizhendong Date: Wed, 2 Feb 2022 21:04:19 +0800 Subject: [PATCH 12/19] use batch processer manager wrap --- apisix/plugins/clickhouse-logger.lua | 5 +-- docs/en/latest/plugins/clickhouse-logger.md | 14 +----- docs/zh/latest/plugins/clickhouse-logger.md | 14 +----- t/plugin/clickhouse-logger.t | 50 ++++++++++++--------- 4 files changed, 35 insertions(+), 48 deletions(-) diff --git a/apisix/plugins/clickhouse-logger.lua b/apisix/plugins/clickhouse-logger.lua index 2bfa98167292..1a2349471682 100644 --- a/apisix/plugins/clickhouse-logger.lua +++ b/apisix/plugins/clickhouse-logger.lua @@ -38,9 +38,6 @@ local schema = { logtable = {type = "string", default = ""}, timeout = {type = "integer", minimum = 1, default = 3}, name = {type = "string", default = "clickhouse logger"}, - max_retry_count = {type = "integer", minimum = 0, default = 0}, - retry_delay = {type = "integer", minimum = 0, default = 1}, - batch_max_size = {type = "integer", minimum = 1, default = 100}, ssl_verify = {type = "boolean", default = true}, }, required = {"endpoint_addr", "user", "password", "database", "logtable"} @@ -59,7 +56,7 @@ local _M = { version = 0.1, priority = 398, name = plugin_name, - schema = schema, + schema = batch_processor_manager:wrap_schema(schema), metadata_schema = metadata_schema, } diff --git a/docs/en/latest/plugins/clickhouse-logger.md b/docs/en/latest/plugins/clickhouse-logger.md index 577d24407d9e..d51e6bac38ee 100644 --- a/docs/en/latest/plugins/clickhouse-logger.md +++ b/docs/en/latest/plugins/clickhouse-logger.md @@ -95,20 +95,10 @@ hello, world 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. -**APISIX Variables** - -| Variable Name | Description | Usage Example | -|------------------|-------------------------|----------------| -| route_id | id of `route` | $route_id | -| route_name | name of `route` | $route_name | -| service_id | id of `service` | $service_id | -| service_name | name of `service` | $service_name | -| consumer_name | username of `consumer` | $consumer_name | - ### Example ```shell -curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/clickhouse-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { "log_format": { "host": "$host", @@ -118,7 +108,7 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KE }' ``` -create logtable +create clickhouse log table ```sql CREATE TABLE default.test ( diff --git a/docs/zh/latest/plugins/clickhouse-logger.md b/docs/zh/latest/plugins/clickhouse-logger.md index ae143ebdff64..fdadd9abeb67 100644 --- a/docs/zh/latest/plugins/clickhouse-logger.md +++ b/docs/zh/latest/plugins/clickhouse-logger.md @@ -93,20 +93,10 @@ 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 生效。 | -**APISIX 变量** - -| 变量名 | 描述 | 使用示例 | -|------------------|-------------------------|----------------| -| route_id | `route` 的 id | $route_id | -| route_name | `route` 的 name | $route_name | -| service_id | `service` 的 id | $service_id | -| service_name | `service` 的 name | $service_name | -| consumer_name | `consumer` 的 username | $consumer_name | - ### 设置日志格式示例 ```shell -curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' +curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/clickhouse-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { "log_format": { "host": "$host", @@ -116,7 +106,7 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/http-logger -H 'X-API-KE }' ``` -创建logtable +创建clickhouse log table ```sql CREATE TABLE default.test ( diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index dc7ed0e05cd2..e6c6126e5012 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -137,8 +137,9 @@ plugins: end } } ---- response_body eval -qr/\{"error_msg":"failed to check the configuration of plugin clickhouse-logger err: property \\"endpoint_addr\\" is required"\}/ +--- response_body +property "endpoint_addr" is required + === TEST 4: add plugin on routes @@ -170,28 +171,37 @@ plugins: "uri": "/opentracing" }]], [[{ - "node": { - "value": { - "plugins": { - "clickhouse-logger": { - "user": "default", - "password": "a", - "database": "default", - "logtable": "t", - "endpoint_addr": "http://127.0.0.1:8123" + "action":"set", + "node":{ + "value":{ + "uri":"/opentracing", + "upstream":{ + "scheme":"http", + "nodes":{ + "127.0.0.1:1982":1 } }, - "upstream": { - "nodes": { - "127.0.0.1:1982": 1 - }, - "type": "roundrobin" + "plugins":{ + "clickhouse-logger":{ + "batch_max_size":1000, + "max_retry_count":0, + "retry_delay":1, + "ssl_verify":true, + "endpoint_addr":"http://127.0.0.1:8123", + "password":"a", + "buffer_duration":60, + "timeout":3, + "user":"default", + "name":"clickhouse-logger", + "database":"default", + "logtable":"t", + "inactive_timeout":5 + } }, - "uri": "/opentracing" + "id":"1" }, - "key": "/apisix/routes/1" - }, - "action": "set" + "key":"/apisix/routes/1" + } }]] ) From d4a9c2c6105a213036c018838b8e9905d5378d89 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Mon, 7 Feb 2022 10:11:46 +0800 Subject: [PATCH 13/19] enable clickhouse-logger by default --- conf/config-default.yaml | 2 +- t/plugin/clickhouse-logger.t | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/conf/config-default.yaml b/conf/config-default.yaml index af5092dd4300..6a8362ab7399 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -382,7 +382,7 @@ plugins: # plugin list (sorted by priority) - syslog # priority: 401 - udp-logger # priority: 400 - file-logger # priority: 399 - #- clickhouse-logger # priority: 398 + - clickhouse-logger # priority: 398 #- log-rotate # priority: 100 # <- recommend to use priority (0, 100) for your custom plugins - example-plugin # priority: 0 diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index e6c6126e5012..cb494c3fe6d5 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -123,13 +123,12 @@ plugins: location /t { content_by_lua_block { local plugin = require("apisix.plugins.clickhouse-logger") - local ok, err = plugin.check_schema({log_id = "syslog", - max_retry_count = 0, - retry_delay = 1, - buffer_duration = 60, - inactive_timeout = 10, - batch_max_size = 100, + local ok, err = plugin.check_schema({user = "default", + password = "a", + database = "default", + logtable = "t" }) + if not ok then ngx.say(err) else @@ -211,12 +210,6 @@ plugins: ngx.say(body) } } ---- request -GET /t ---- response_body -passed ---- no_error_log -[error] From 234b920f9cc7477c1a93d1604c6922c76aadb76d Mon Sep 17 00:00:00 2001 From: qizhendong Date: Tue, 8 Feb 2022 14:44:18 +0800 Subject: [PATCH 14/19] fix test cases and doc --- docs/en/latest/plugins/clickhouse-logger.md | 4 ++-- docs/zh/latest/plugins/clickhouse-logger.md | 4 ++-- t/admin/plugins.t | 1 + t/debug/debug-mode.t | 1 + t/plugin/clickhouse-logger.t | 10 +++++++--- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/en/latest/plugins/clickhouse-logger.md b/docs/en/latest/plugins/clickhouse-logger.md index d51e6bac38ee..11ca4490bb3d 100644 --- a/docs/en/latest/plugins/clickhouse-logger.md +++ b/docs/en/latest/plugins/clickhouse-logger.md @@ -41,8 +41,8 @@ title: clickhouse-logger | endpoint_addr | string | required | | | The `clickhouse` endpoint. | | database | string | required | | | The DB name to store log. | | logtable | string | required | | | The table name. | -| user | string | required | | |clickhouse user. | -| password | string | required | | |clickhouse password. | +| user | string | required | | | clickhouse user. | +| password | string | required | | | clickhouse password. | | timeout | integer | optional | 3 | [1,...] | Time to keep the connection alive after sending a request. | | name | string | optional | "clickhouse logger" | | A unique identifier to identity the logger. | | batch_max_size | integer | optional | 100 | [1,...] | Set the maximum number of logs sent in each batch. When the number of logs reaches the set maximum, all logs will be automatically pushed to the clickhouse. | diff --git a/docs/zh/latest/plugins/clickhouse-logger.md b/docs/zh/latest/plugins/clickhouse-logger.md index fdadd9abeb67..3f816a638d14 100644 --- a/docs/zh/latest/plugins/clickhouse-logger.md +++ b/docs/zh/latest/plugins/clickhouse-logger.md @@ -41,8 +41,8 @@ title: clickhouse-logger | endpoint_addr | string | 必须 | | | `clickhouse` 服务器的 endpoint。 | | database | string | 必须 | | | 使用的数据库。 | | logtable | string | 必须 | | | 写入的表名 。 | -| user | string | 必须 | | |clickhouse的用户。 | -| password | string | 必须 | | |clickhouse的密码 。 | +| user | string | 必须 | | | clickhouse的用户。 | +| password | string | 必须 | | | clickhouse的密码 。 | | timeout | integer | 可选 | 3 | [1,...] | 发送请求后保持连接活动的时间。 | | name | string | 可选 | "clickhouse logger" | | 标识 logger 的唯一标识符。 | | batch_max_size | integer | 可选 | 100 | [1,...] | 设置每批发送日志的最大条数,当日志条数达到设置的最大值时,会自动推送全部日志到 `clickhouse` 。 | diff --git a/t/admin/plugins.t b/t/admin/plugins.t index f7435ccd9482..68b5721f6d16 100644 --- a/t/admin/plugins.t +++ b/t/admin/plugins.t @@ -117,6 +117,7 @@ rocketmq-logger syslog udp-logger file-logger +clickhouse-logger example-plugin aws-lambda azure-functions diff --git a/t/debug/debug-mode.t b/t/debug/debug-mode.t index 579068e5b90d..f5b6e359b50a 100644 --- a/t/debug/debug-mode.t +++ b/t/debug/debug-mode.t @@ -83,6 +83,7 @@ loaded plugin and sort by priority: 403 name: kafka-logger loaded plugin and sort by priority: 402 name: rocketmq-logger loaded plugin and sort by priority: 401 name: syslog loaded plugin and sort by priority: 400 name: udp-logger +loaded plugin and sort by priority: 398 name: clickhouse-logger loaded plugin and sort by priority: 0 name: example-plugin loaded plugin and sort by priority: -2000 name: serverless-post-function loaded plugin and sort by priority: -3000 name: ext-plugin-post-req diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index cb494c3fe6d5..99de12a6ac8c 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -17,6 +17,7 @@ use t::APISIX 'no_plan'; +log_level("info"); repeat_each(1); no_long_string(); no_root_location(); @@ -143,6 +144,9 @@ property "endpoint_addr" is required === TEST 4: add plugin on routes --- yaml_config +apisix: + node_listen: 1984 + admin_key: null plugins: - clickhouse-logger --- config @@ -210,6 +214,8 @@ plugins: ngx.say(body) } } +--- response_body +passed @@ -218,6 +224,4 @@ plugins: GET /opentracing --- response_body opentracing ---- error_log -Batch Processor[clickhouse logger] failed to process entries ---- wait: 0.5 +--- wait: 2 From d89631d4d9d76486bb38d79b143efd19e8699c16 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Wed, 9 Feb 2022 22:07:36 +0800 Subject: [PATCH 15/19] fix ssl handshake --- apisix/plugins/clickhouse-logger.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apisix/plugins/clickhouse-logger.lua b/apisix/plugins/clickhouse-logger.lua index 1a2349471682..416983721669 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, false) + ok, err = httpc:ssl_handshake(true, host, true) if not ok then return false, "failed to perform SSL with host[" .. host .. "] " .. "port[" .. tostring(port) .. "] " .. err From 22c3fb0d5bcbca5f19ed18df9896d21b703ca2ae Mon Sep 17 00:00:00 2001 From: qizhendong Date: Thu, 10 Feb 2022 14:09:15 +0800 Subject: [PATCH 16/19] 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 From 34f3dcb1af3a3268c9adc581a8ca5ac4afd9f8e6 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Fri, 11 Feb 2022 17:07:21 +0800 Subject: [PATCH 17/19] using reg tp match response body --- t/plugin/clickhouse-logger.t | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index 25d860d62f61..d6999c33a09a 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -56,7 +56,6 @@ run_tests(); __DATA__ === TEST 1: Full configuration verification ---- yaml_config --- config location /t { content_by_lua_block { @@ -87,7 +86,6 @@ passed === TEST 2: Basic configuration verification ---- yaml_config --- config location /t { content_by_lua_block { @@ -112,7 +110,6 @@ passed === TEST 3: auth configure undefined ---- yaml_config --- config location /t { content_by_lua_block { @@ -136,7 +133,6 @@ property "endpoint_addr" is required === TEST 4: add plugin on routes ---- yaml_config apisix: node_listen: 1984 admin_key: null @@ -216,5 +212,5 @@ GET /opentracing --- response_body opentracing --- grep_error_log_out -clickhouse body: +"clickhouse body: INSERT INTO t FORMAT JSONEachRow" --- wait: 5 From 9118fb06ee0892c4722ec75d52e8b1f6f718a183 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Mon, 14 Feb 2022 10:45:55 +0800 Subject: [PATCH 18/19] verify clickhouse headers on test cases --- apisix/plugins/clickhouse-logger.lua | 2 +- t/plugin/clickhouse-logger.t | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apisix/plugins/clickhouse-logger.lua b/apisix/plugins/clickhouse-logger.lua index ef5234b7c8d7..f7b734645334 100644 --- a/apisix/plugins/clickhouse-logger.lua +++ b/apisix/plugins/clickhouse-logger.lua @@ -95,7 +95,7 @@ local function send_http_data(conf, log_message) .. tostring(port) .. "] " .. err end - if url_decoded.scheme == "https" and conf.ssl_verify then + if url_decoded.scheme == "https" then ok, err = httpc:ssl_handshake(true, host, conf.ssl_verify) if not ok then return false, "failed to perform SSL with host[" .. host .. "] " diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index d6999c33a09a..459099d2e014 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -41,7 +41,10 @@ add_block_preprocessor(sub { ngx.req.read_body() local data = ngx.req.get_body_data() local headers = ngx.req.get_headers() - ngx.log(ngx.ERR, "clickhouse body: ", data) + ngx.log(ngx.WARN, "clickhouse body: ", data) + for k, v in pairs(headers) do + ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v) + end ngx.say("ok") } } @@ -133,9 +136,6 @@ property "endpoint_addr" is required === TEST 4: add plugin on routes -apisix: - node_listen: 1984 - admin_key: null --- config location /t { content_by_lua_block { @@ -211,6 +211,9 @@ passed GET /opentracing --- response_body opentracing ---- grep_error_log_out -"clickhouse body: INSERT INTO t FORMAT JSONEachRow" +--- error_log +clickhouse body: INSERT INTO t FORMAT JSONEachRow +clickhouse headers: X-ClickHouse-Key:a +clickhouse headers: X-ClickHouse-User:default +clickhouse headers: X-ClickHouse-Database:default --- wait: 5 From cede0166e11ec6bdce90a2002adfa072d908f8b4 Mon Sep 17 00:00:00 2001 From: qizhendong Date: Tue, 15 Feb 2022 16:42:17 +0800 Subject: [PATCH 19/19] set batch_max_size to 1 on test cases --- t/plugin/clickhouse-logger.t | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/t/plugin/clickhouse-logger.t b/t/plugin/clickhouse-logger.t index 459099d2e014..69e1a6f67d98 100644 --- a/t/plugin/clickhouse-logger.t +++ b/t/plugin/clickhouse-logger.t @@ -149,7 +149,9 @@ property "endpoint_addr" is required "password": "a", "database": "default", "logtable": "t", - "endpoint_addr": "http://127.0.0.1:10420/clickhouse-logger/test" + "endpoint_addr": "http://127.0.0.1:10420/clickhouse-logger/test", + "batch_max_size":1, + "inactive_timeout":1 } }, "upstream": { @@ -173,7 +175,7 @@ property "endpoint_addr" is required }, "plugins":{ "clickhouse-logger":{ - "batch_max_size":1000, + "batch_max_size":1, "max_retry_count":0, "retry_delay":1, "ssl_verify":true, @@ -185,7 +187,7 @@ property "endpoint_addr" is required "name":"clickhouse-logger", "database":"default", "logtable":"t", - "inactive_timeout":5 + "inactive_timeout":1 } }, "id":"1" @@ -213,7 +215,7 @@ GET /opentracing opentracing --- error_log clickhouse body: INSERT INTO t FORMAT JSONEachRow -clickhouse headers: X-ClickHouse-Key:a -clickhouse headers: X-ClickHouse-User:default -clickhouse headers: X-ClickHouse-Database:default +clickhouse headers: x-clickhouse-key:a +clickhouse headers: x-clickhouse-user:default +clickhouse headers: x-clickhouse-database:default --- wait: 5