Skip to content

Commit

Permalink
use batch processer manager wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
qizhendong committed Feb 3, 2022
1 parent 27995aa commit 74d59b5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 48 deletions.
5 changes: 1 addition & 4 deletions apisix/plugins/clickhouse-logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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,
}

Expand Down
14 changes: 2 additions & 12 deletions docs/en/latest/plugins/clickhouse-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 (
Expand Down
14 changes: 2 additions & 12 deletions docs/zh/latest/plugins/clickhouse-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 (
Expand Down
50 changes: 30 additions & 20 deletions t/plugin/clickhouse-logger.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
}]]
)
Expand Down

0 comments on commit 74d59b5

Please sign in to comment.