Skip to content

Commit

Permalink
deprecated addr with host
Browse files Browse the repository at this point in the history
  • Loading branch information
zhendongcmss committed Jul 25, 2022
1 parent 1daf0ae commit a42c46f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
7 changes: 4 additions & 3 deletions apisix/plugins/clickhouse-logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ local batch_processor_manager = bp_manager_mod.new(plugin_name)
local schema = {
type = "object",
properties = {
endpoint_addrs = {items = core.schema.uri_def, type = "array", minItems = 1}, -- deprecated, use "host" instead
-- deprecated, use "host" instead
endpoint_addr = {items = core.schema.uri_def, type = "array", minItems = 1},
user = {type = "string", default = ""},
password = {type = "string", default = ""},
database = {type = "string", default = ""},
Expand All @@ -41,7 +42,7 @@ local schema = {
name = {type = "string", default = "clickhouse logger"},
ssl_verify = {type = "boolean", default = true},
},
required = {"endpoint_addrs", "user", "password", "database", "logtable"}
required = {"endpoint_addr", "user", "password", "database", "logtable"}
}


Expand Down Expand Up @@ -73,7 +74,7 @@ end
local function send_http_data(conf, log_message)
local err_msg
local res = true
local selected_endpoint_addr = conf.endpoint_addrs[math_random(#conf.endpoint_addrs)]
local selected_endpoint_addr = conf.endpoint_addr[math_random(#conf.endpoint_addr)]
local url_decoded = url.parse(selected_endpoint_addr)
local host = url_decoded.host
local port = url_decoded.port
Expand Down
4 changes: 2 additions & 2 deletions docs/en/latest/plugins/clickhouse-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The `clickhouse-logger` Plugin is used to push logs to [ClickHouse](https://clic

| Name | Type | Required | Default | Valid values | Description |
|---------------|---------|----------|---------------------|--------------|----------------------------------------------------------------|
| endpoint_addrs | array | True | | | ClickHouse endpoints. |
| endpoint_addr | Deprecated | True | | | Use `host` instead. ClickHouse endpoints. |
| database | string | True | | | Name of the database to store the logs. |
| logtable | string | True | | | Table name to store the logs. |
| user | string | True | | | ClickHouse username. |
Expand Down Expand Up @@ -108,7 +108,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
"password": "a",
"database": "default",
"logtable": "test",
"endpoint_addrs": ["http://127.0.0.1:8123"]
"endpoint_addr": ["http://127.0.0.1:8123"]
}
},
"upstream": {
Expand Down
12 changes: 6 additions & 6 deletions docs/zh/latest/plugins/clickhouse-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ title: clickhouse-logger

## 属性

| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
| ---------------- | ------- | ------ | ------------- | ------- | ------------------------------------------------ |
| endpoint_addrs | 数组 | 必须 | | | `clickhouse` 服务器的 endpoints。 |
| database | string | 必须 | | | 使用的数据库。 |
| logtable | string | 必须 | | | 写入的表名 。 |
| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
| ---------------- | ------- | ------ | ------------- | ------- | ------------------------------------------------ |
| endpoint_addr | 废弃 | 必须 | | | 推荐使用“host”代替。`clickhouse` 服务器的 endpoints。|
| database | string | 必须 | | | 使用的数据库。 |
| logtable | string | 必须 | | | 写入的表名 。 |
| user | string | 必须 | | | clickhouse 的用户。 |
| password | string | 必须 | | | clickhouse 的密码 。 |
| timeout | integer | 可选 | 3 | [1,...] | 发送请求后保持连接活动的时间。 |
Expand All @@ -54,7 +54,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
"password": "a",
"database": "default",
"logtable": "test",
"endpoint_addrs": ["http://127.0.0.1:8123"]
"endpoint_addr": ["http://127.0.0.1:8123"]
}
},
"upstream": {
Expand Down
31 changes: 9 additions & 22 deletions t/plugin/clickhouse-logger.t
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ __DATA__
password = "a",
database = "default",
logtable = "t",
endpoint_addrs = {"http://127.0.0.1:10420/clickhouse-logger/test"},
endpoint_addr = {"http://127.0.0.1:10420/clickhouse-logger/test"},
max_retry_count = 1,
name = "clickhouse logger",
ssl_verify = false
Expand All @@ -109,7 +109,7 @@ passed
password = "a",
database = "default",
logtable = "t",
endpoint_addrs = {"http://127.0.0.1:10420/clickhouse-logger/test"}
endpoint_addr = {"http://127.0.0.1:10420/clickhouse-logger/test"}
})
if not ok then
Expand Down Expand Up @@ -143,7 +143,7 @@ passed
}
}
--- response_body
property "endpoint_addrs" is required
property "endpoint_addr" is required
Expand All @@ -161,7 +161,7 @@ property "endpoint_addrs" is required
"password": "a",
"database": "default",
"logtable": "t",
"endpoint_addrs": "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
}
Expand All @@ -183,25 +183,12 @@ property "endpoint_addrs" is required
}
}
--- response_body
property "endpoint_addrs" validation failed: wrong type: expected array, got string
{"error_msg":"failed to check the configuration of plugin clickhouse-logger err: property \"endpoint_addr\" validation failed: wrong type: expected array, got string"}
--- error_code: 400
=== TEST 5: access local server
--- request
GET /opentracing
--- response_body
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
--- wait: 5
=== TEST 6: add plugin on routes using multi clickhouse-logger
=== TEST 5: add plugin on routes using multi clickhouse-logger
--- config
location /t {
content_by_lua_block {
Expand All @@ -215,7 +202,7 @@ clickhouse headers: x-clickhouse-database:default
"password": "a",
"database": "default",
"logtable": "t",
"endpoint_addrs": ["http://127.0.0.1:10420/clickhouse-logger/test",
"endpoint_addr": ["http://127.0.0.1:10420/clickhouse-logger/test",
"http://127.0.0.1:10420/clickhouse-logger/test1"],
"batch_max_size":1,
"inactive_timeout":1
Expand All @@ -242,7 +229,7 @@ passed
=== TEST 7: access local server
=== TEST 6: access local server
--- request
GET /opentracing
--- response_body
Expand Down

0 comments on commit a42c46f

Please sign in to comment.