You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/02/07 06:57:16 UTC
[GitHub] [apisix] zhendongcmss opened a new pull request #6256: feat(error-log-logger): add clickouse for error-log-logger
zhendongcmss opened a new pull request #6256:
URL: https://github.com/apache/apisix/pull/6256
### What this PR does / why we need it:
Add error-log-logger supports clickhouse.
### Pre-submission checklist:
<!--
Please follow the PR manners:
1. Use Draft if the PR is not ready to be reviewed
2. Test is required for the feat/fix PR, unless you have a good reason
3. Doc is required for the feat PR
4. Use a new commit to resolve review instead of `push -f`
5. If you need to resolve merge conflicts after the PR is reviewed, please merge master but do not rebase
6. Use "request review" to notify the reviewer once you have resolved the review
7. Only reviewer can click "Resolve conversation" to mark the reviewer's review resolved
-->
* [ ] Did you explain what problem does this PR solve? Or what new features have been added?
* [ ] Have you added corresponding test cases?
* [ ] Have you modified the corresponding document?
* [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#issuecomment-1044229651
> Now that we have the clickhouse plugin, can we implement it in this plugin?
>
> I am concerned that this will introduce duplicate code.
I think it is a good idea. One side we can reduce duplicate code, antoher avoid `error-log-logger.lua` oversize. It is friendly for new plugin.
@spacewander How about you ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#issuecomment-1046229675
> The former needs to be configured at the global level
I got. Let's keep it that way for now and leave the optimization for later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on a change in pull request #6256: feat(error-log-logger): add clickouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r809658570
##########
File path: docs/zh/latest/plugins/error-log-logger.md
##########
@@ -50,6 +50,11 @@ title: error-log-logger
| skywalking.endpoint_addr | string | 可选 | http://127.0.0.1:12900/v3/logs | | Skywalking 的 HTTP endpoint 地址,例如:http://127.0.0.1:12800 |
| skywalking.service_name | string | 可选 | APISIX | | skywalking 上报的 service 名称 |
| skywalking.service_instance_name | String | 可选 | APISIX Instance Name | | skywalking 上报的 service 实例名, 如果期望直接获取本机主机名则设置为 `$hostname` |
+| clickhouse.endpoint_addr | String | 可选 | http://127.0.0.1:8213 | | clickhouse的HTTP endpoint地址,例如 http://127.0.0.1:8213 |
Review comment:
```suggestion
| clickhouse.endpoint_addr | String | 可选 | http://127.0.0.1:8213 | | clickhouse 的 HTTP endpoint 地址,例如 http://127.0.0.1:8213 |
```
Note the format, the following is also
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r809825591
##########
File path: docs/zh/latest/plugins/error-log-logger.md
##########
@@ -50,6 +50,11 @@ title: error-log-logger
| skywalking.endpoint_addr | string | 可选 | http://127.0.0.1:12900/v3/logs | | Skywalking 的 HTTP endpoint 地址,例如:http://127.0.0.1:12800 |
| skywalking.service_name | string | 可选 | APISIX | | skywalking 上报的 service 名称 |
| skywalking.service_instance_name | String | 可选 | APISIX Instance Name | | skywalking 上报的 service 实例名, 如果期望直接获取本机主机名则设置为 `$hostname` |
+| clickhouse.endpoint_addr | String | 可选 | http://127.0.0.1:8213 | | clickhouse的HTTP endpoint地址,例如 http://127.0.0.1:8213 |
Review comment:
ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#issuecomment-1053808149
LGTM, @zhendongcmss CI/build was failed, I will rerun it and if it still fails, we need to focus on it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander merged pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #6256:
URL: https://github.com/apache/apisix/pull/6256
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r808693582
##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -214,6 +227,78 @@ local function send_to_skywalking(log_message)
end
+local function send_to_clickhouse(log_message)
+ local err_msg
+ local res = true
+ local url_decoded = url.parse(config.clickhouse.endpoint_addr)
+ local host = url_decoded.host
+ local port = url_decoded.port
+ core.log.info("sending a batch logs to ", config.clickhouse.endpoint_addr)
+
+ if not port then
+ if url_decoded.scheme == "https" then
+ port = 443
+ else
+ port = 80
+ end
+ end
+
+ local httpc = http.new()
+ httpc:set_timeout(config.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
Review comment:
There need add a ssl_verify ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r810754771
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is a warning message for test2.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: 3
+
+
+
+=== TEST 3: put plugin metadata and log an error level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "batch_max_size": 15,
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is an error message for test3.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 4: log a warn level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.warn("this is a warning message for test4.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 5: log some messages
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.warn("this is a warning message for test5.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: log an info level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.info("this is an info message for test6.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+this is an info message for test6
+--- wait: 5
+
+
+
+=== TEST 7: delete metadata for the plugin, recover to the default
Review comment:
should we test the format is recover by sending another log to clickhouse?
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is a warning message for test2.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: 3
+
+
+
+=== TEST 3: put plugin metadata and log an error level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
Review comment:
```suggestion
"clickhouse": {
"user": "default",
"password": "a",
"database": "default",
"logtable": "t",
"endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
},
```
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is a warning message for test2.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: 3
+
+
+
+=== TEST 3: put plugin metadata and log an error level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "batch_max_size": 15,
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is an error message for test3.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 4: log a warn level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.warn("this is a warning message for test4.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 5: log some messages
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.warn("this is a warning message for test5.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
Review comment:
is there log body releated to `"this is a warning message for test5."`?
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is a warning message for test2.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: 3
+
+
+
+=== TEST 3: put plugin metadata and log an error level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "batch_max_size": 15,
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is an error message for test3.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 4: log a warn level message
Review comment:
How do we distinguish log levels in clickhouse?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss edited a comment on pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss edited a comment on pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#issuecomment-1047383975
There is a test case failed. How to fix it ? @spacewander @tzssangglass @leslie-tsang
https://github.com/apache/apisix/runs/5282480987?check_suite_focus=true#step:6:4
```
Run ./utils/check-category.py
Entry docs/zh/latest/plugins/datadog.md in the sidebar can't be found. Please remove it from docs/zh/latest/config.json.
Error: Process completed with exit code 2[5](https://github.com/apache/apisix/runs/5282480987?check_suite_focus=true#step:6:5)5.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#issuecomment-1047383975
There is a test case failed. How to fix it ? @spacewander @tzssangglass @leslie-tsang
```
Run ./utils/check-category.py
Entry docs/zh/latest/plugins/datadog.md in the sidebar can't be found. Please remove it from docs/zh/latest/config.json.
Error: Process completed with exit code 2[5](https://github.com/apache/apisix/runs/5282480987?check_suite_focus=true#step:6:5)5.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] leslie-tsang commented on pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#issuecomment-1050483228
Hello there, Plz don't force push during the <ins>review</ins>.
Commit history allows reviewers to see what has changed since the last review, which is <ins>useful</ins> for them.
A forced push could <ins>**ruin**</ins> the review experience.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r809855021
##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -214,6 +227,70 @@ local function send_to_skywalking(log_message)
end
+local function send_to_clickhouse(log_message)
+ local err_msg
+ local res = true
+ local url_decoded = url.parse(config.clickhouse.endpoint_addr)
Review comment:
yes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r814438581
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is a warning message for test2.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: 3
+
+
+
+=== TEST 3: put plugin metadata and log an error level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "batch_max_size": 15,
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is an error message for test3.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 4: log a warn level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.warn("this is a warning message for test4.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 5: log some messages
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.warn("this is a warning message for test5.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
Review comment:
yes, I will add it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
spacewander commented on pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#issuecomment-1046207489
No.
@tzssangglass
Handling the error log and access log are two different things. The former needs to be configured at the global level, the latter can be done in a smaller scope.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r809699020
##########
File path: docs/en/latest/plugins/error-log-logger.md
##########
@@ -124,3 +129,21 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/error-log-logger -H 'X-A
"inactive_timeout": 1
}'
```
+
+## How to set the clickhouse
+
+The plugin sends the error log as a string to the `data` field of the clickhouse table.
+Step: update the attributes of the plugin
Review comment:
What does this sentence mean?
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is a warning message for test2.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
Review comment:
Is it possible to verify the reported error log in the test?
##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -214,6 +227,70 @@ local function send_to_skywalking(log_message)
end
+local function send_to_clickhouse(log_message)
+ local err_msg
+ local res = true
+ local url_decoded = url.parse(config.clickhouse.endpoint_addr)
Review comment:
we can use `httpc:request_uri` directly like the skywalking destination?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r811198502
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is a warning message for test2.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: 3
+
+
+
+=== TEST 3: put plugin metadata and log an error level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "batch_max_size": 15,
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is an error message for test3.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 4: log a warn level message
Review comment:
The entire log is sent as a whole. That means that analyze processer need to parse error logs.
The error-log-logger received the log logs is not a format data. It is a string.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
spacewander commented on pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#issuecomment-1047389813
>
Thanks for your report. I am fixing it via https://github.com/apache/apisix/pull/6411
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r815603827
##########
File path: docs/zh/latest/plugins/error-log-logger.md
##########
@@ -122,3 +127,21 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/error-log-logger -H 'X-A
"inactive_timeout": 1
}'
```
+
+## 如何设置接收日志的 clickhouse 数据库
+
+插件将 error log 作为一个字符串发送到 clickhouse 表的 `data` 字段。
+步骤:更新插件属性
Review comment:
ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r815598943
##########
File path: docs/zh/latest/plugins/error-log-logger.md
##########
@@ -122,3 +127,21 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/error-log-logger -H 'X-A
"inactive_timeout": 1
}'
```
+
+## 如何设置接收日志的 clickhouse 数据库
+
+插件将 error log 作为一个字符串发送到 clickhouse 表的 `data` 字段。
+步骤:更新插件属性
Review comment:
Is it some kind of `TODO`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r809849404
##########
File path: docs/en/latest/plugins/error-log-logger.md
##########
@@ -124,3 +129,21 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/error-log-logger -H 'X-A
"inactive_timeout": 1
}'
```
+
+## How to set the clickhouse
+
+The plugin sends the error log as a string to the `data` field of the clickhouse table.
+Step: update the attributes of the plugin
Review comment:
it's means that the plugins insert error logs to the clickhouse table with `data` column default.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r811189782
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is a warning message for test2.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log body: INSERT INTO t FORMAT JSONEachRow
Review comment:
It is difficult because the error logs are different each other.
clickhouse error log body: INSERT INTO t FORMAT JSONEachRow {"data": " 2022/02/16 16:45:07 [error] 4279#4279: *7272 [lua] batch-processor.lua:73: Batch ... "}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] leslie-tsang commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r810758453
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
Review comment:
```suggestion
```
Need to be removed
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
Review comment:
```suggestion
```
Need to be removed
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
Review comment:
```suggestion
clickhouse = {
user = "default",
password = "a",
database = "default",
logtable = "t",
endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
}
```
Please avoid useless indentations.
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
Review comment:
```suggestion
```
Ditto
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
Review comment:
```suggestion
location /t {
```
Can we use `/t` instead ?
##########
File path: docs/zh/latest/plugins/error-log-logger.md
##########
@@ -122,3 +127,21 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/error-log-logger -H 'X-A
"inactive_timeout": 1
}'
```
+
+## 如何设置接收日志的 clickhouse 数据库
+
+插件将error log作为一个字符串发送到clickhouse表的 `data` 字段。
Review comment:
```suggestion
插件将 error log 作为一个字符串发送到 clickhouse 表的 `data` 字段。
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r814437556
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is a warning message for test2.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: 3
+
+
+
+=== TEST 3: put plugin metadata and log an error level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "batch_max_size": 15,
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is an error message for test3.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 4: log a warn level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.warn("this is a warning message for test4.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 5: log some messages
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.warn("this is a warning message for test5.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: log an info level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.info("this is an info message for test6.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+this is an info message for test6
+--- wait: 5
+
+
+
+=== TEST 7: delete metadata for the plugin, recover to the default
Review comment:
I doesn't understand.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r808693582
##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -214,6 +227,78 @@ local function send_to_skywalking(log_message)
end
+local function send_to_clickhouse(log_message)
+ local err_msg
+ local res = true
+ local url_decoded = url.parse(config.clickhouse.endpoint_addr)
+ local host = url_decoded.host
+ local port = url_decoded.port
+ core.log.info("sending a batch logs to ", config.clickhouse.endpoint_addr)
+
+ if not port then
+ if url_decoded.scheme == "https" then
+ port = 443
+ else
+ port = 80
+ end
+ end
+
+ local httpc = http.new()
+ httpc:set_timeout(config.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
Review comment:
There need add a ssl_verify ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#issuecomment-1043865625
Now that we have the clickhouse plugin, can we implement it in this plugin?
I am concerned that this will introduce duplicate code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r815540454
##########
File path: t/plugin/error-log-logger-clickhouse.t
##########
@@ -0,0 +1,279 @@
+#
+# 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';
+
+log_level("info");
+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");
+ }
+
+ my $http_config = $block->http_config // <<_EOC_;
+ server {
+ listen 10420;
+ location /error-logger-clickhouse/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.WARN, "clickhouse error log body: ", data)
+ for k, v in pairs(headers) do
+ ngx.log(ngx.WARN, "clickhouse headers: " .. k .. ":" .. v)
+ end
+ ngx.say("ok")
+ }
+ }
+ }
+_EOC_
+
+ $block->set_value("http_config", $http_config);
+});
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: test schema checker
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.error-log-logger")
+ local ok, err = plugin.check_schema(
+ {
+ clickhouse = {
+ user = "default",
+ password = "a",
+ database = "default",
+ logtable = "t",
+ endpoint_addr = "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ }
+ },
+ core.schema.TYPE_METADATA
+ )
+ if not ok then
+ ngx.say(err)
+ end
+
+ ngx.say("done")
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: test unreachable server
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is a warning message for test2.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: 3
+
+
+
+=== TEST 3: put plugin metadata and log an error level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/plugin_metadata/error-log-logger',
+ ngx.HTTP_PUT,
+ [[{
+ "clickhouse": {
+ "user": "default",
+ "password": "a",
+ "database": "default",
+ "logtable": "t",
+ "endpoint_addr": "http://127.0.0.1:10420/error-logger-clickhouse/test"
+ },
+ "batch_max_size": 15,
+ "inactive_timeout": 1
+ }]]
+ )
+ ngx.sleep(2)
+ core.log.warn("this is an error message for test3.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 4: log a warn level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.warn("this is a warning message for test4.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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 5: log some messages
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.warn("this is a warning message for test5.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+clickhouse error log 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: log an info level message
+--- yaml_config
+apisix:
+ enable_admin: true
+ admin_key: null
+plugins:
+ - error-log-logger
+--- config
+ location /tg {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ core.log.info("this is an info message for test6.")
+ }
+ }
+--- request
+GET /tg
+--- response_body
+--- error_log
+this is an info message for test6
+--- wait: 5
+
+
+
+=== TEST 7: delete metadata for the plugin, recover to the default
Review comment:
ok, I see that the original test case has covered the: https://github.com/apache/apisix/blob/acbb111afbbd096444bdd6dc0307d18187b19829/t/plugin/error-log-logger.t#L259-L334
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] zhendongcmss commented on a change in pull request #6256: feat(error-log-logger): add clickhouse for error-log-logger
Posted by GitBox <gi...@apache.org>.
zhendongcmss commented on a change in pull request #6256:
URL: https://github.com/apache/apisix/pull/6256#discussion_r809854760
##########
File path: docs/en/latest/plugins/error-log-logger.md
##########
@@ -124,3 +129,21 @@ curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/error-log-logger -H 'X-A
"inactive_timeout": 1
}'
```
+
+## How to set the clickhouse
+
+The plugin sends the error log as a string to the `data` field of the clickhouse table.
+Step: update the attributes of the plugin
Review comment:
```
┌─data──────────────────────────────────────────────────────────────────┬
│ 2022/02/16 16:45:07 [error] 4279#4279: *7272 [lua] batch-processor.lua:73: Batch ... │
└───────────────────────────────────────────────────────────────────────┴
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org