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/03/04 04:36:41 UTC

[GitHub] [apisix-website] yzeng25 opened a new pull request #939: docs: add clickhouse blog

yzeng25 opened a new pull request #939:
URL: https://github.com/apache/apisix-website/pull/939


   Changes:
   
   Add clickhouse blog


-- 
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-website] netlify[bot] edited a comment on pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
netlify[bot] edited a comment on pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#issuecomment-1058820229


   ✔️ Deploy Preview for *apache-apisix* ready!
   
   
   🔨 Explore the source changes: f566f47b6aa5656eb0ea9822f41cbab2234e0fb7
   
   🔍 Inspect the deploy log: [https://app.netlify.com/sites/apache-apisix/deploys/6221aba68a34de0008341fe8](https://app.netlify.com/sites/apache-apisix/deploys/6221aba68a34de0008341fe8)
   
   😎 Browse the preview: [https://deploy-preview-939--apache-apisix.netlify.app](https://deploy-preview-939--apache-apisix.netlify.app)
   


-- 
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-website] SylviaBABY commented on a change in pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
SylviaBABY commented on a change in pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#discussion_r819286547



##########
File path: website/blog/2022/03/04/apisix-clickhouse-makes-logging-easier.md
##########
@@ -0,0 +1,248 @@
+---
+title: "Making It Simple, Apache APISIX Integrates ClickHouse to Improve Logging Efficiency"
+authors:
+  - name: "Zhendong Qi"
+    title: "Author"
+    url: "https://github.com/zhendongcmss"
+    image_url: "https://github.com/zhendongcmss.png"
+  - name: "Yilin Zeng"
+    title: "Technical Writer"
+    url: "https://github.com/yzeng25"
+    image_url: "https://github.com/yzeng25.png"
+keywords: 
+- Apache APISIX
+- API Gateway
+- ClickHouse
+- Logging
+- Ecosystem
+description: This blog describes the whole process of developing clickhouse-logger for Apache APISIX, and how to implement it with Grafana to achieve the same observability with simpler architechure and worlflows.
+tags: [Technology,Logging]
+---
+
+> This blog describes the whole process of developing `clickhouse-logger` for Apache APISIX, and how to implement it with Grafana to achieve the same observability with simpler architechure and worlflows.
+
+<!--truncate-->
+
+## Background Information
+
+Apache APISIX is a dynamic, real-time, high-performance API gateway that provides rich traffic management features such as load balancing, dynamic upstream, canary release, circuit breaking, authentication, observability, and more. It not only has many useful plugins, but also supports plugin dynamic change and hot reload.
+
+Developed by Yandex and open sourced in 2016, ClickHouse is not only a database, but also a database management system that allows creating tables and databases, loading data and running queries at runtime without reconfiguring or restarting services.
+
+As more and more companies start to migrate their business to the cloud, how to efficiently implement log sending and receiving and log analysis to enhance the observabilities of the system becomes a challenge. China Mobile, as a company providing public cloud services, the architecture of the initial Apache APISIX-based business log sending and receiving and analysis system is roughly like this.
+
+![initial bussiness architecture](https://static.apiseven.com/202108/1646363723740-f92d6a39-64e0-4464-8c44-c73832362bf6.png)
+
+As the business grows, the above solution is not only oddly expensive to maintain, but also difficult to meet our needs for fine-grained data analysis. Since the data received by rsyslog is a string rather than a JSON format log, it makes log analysis difficult.
+
+There is a famous saying in computing that "any problem can be solved by adding an indirect middle layer". We actually considered adding another intermediate layer between `tcp-logger` and rsyslog to convert strings to JSON, but this is obviously not a permanent solution.
+
+So let's look at the problem differently: if we consider the existing architecture of "tcp-logger+rsyslog+Promtail+Loki" as a huge middle layer, then no matter how many additional middle layers we add in between, it only solves the immediate problem. In the meantime, it makes it more bloated and difficult to maintain. Is there a product on the market that can directly replace "tcp-logger+rsyslog+Promtail+Loki"?
+
+With this question in mind, we spent some time researching and ended up choosing ClickHouse for several reasons.
+
+1. ClickHouse provides HTTP interface for easy calling of other modules.
+2. ClickHouse-based analysis toolbox is very mature and can meet our needs for log analysis.
+3. ClickHouse supports the use of object storage as a storage engine, very convenient.
+4. There is no need to repeat the "tool-building" process.
+
+There is only one problem left to solve: how to implement the interface between Apache APISIX and ClickHouse? A good way to do this is in the form of a plugin. As a member of the Apache APISIX community, I rarely speak up in the community. Seeing the recent progress in the ecosystem of Apache APISIX, I was actually a bit excited to use Apache APISIX, but I haven't contributed any code to the community yet, so I thought I'd like to take this opportunity to add some fire to the community's ecosystem development.
+
+## How It Works
+
+The `clickhouse-logger` plugin acts as an middle layer between Apache APISIX and ClickHouse. As mentioned above, we use Apache APISIX as a seven-layer load balancer and requests passing through Apache APISIX generate logs, such as access log and error log. The `clickhouse-logger` collects the logs and organizes them according to the log format set by its own metadata. Finally, it relies on a batch processor to send the collated logs to ClickHouse in bulk.
+
+![clickhouse-logger architecture](https://static.apiseven.com/202108/1646363936994-c2646095-1ea4-4c1f-8cad-1dcecfc41df3.png)
+
+`clickhouse-logger` serves as a replacement for "tcp-logger+rsyslog+Promtail+Loki" in our scenario. Eliminating the need for format conversion and data forwarding between multiple components, log data requests can be pushed directly to the ClickHouse server.
+
+![improved bussiness architecture](https://static.apiseven.com/202108/1646364005040-93d70286-e7e6-4fb5-a164-1de1c865ce2b.png)
+
+## How to Use the ClickHouse Plugin
+
+Here is a sample process to enable the `clickhouse-logger` plugin in a route.
+
+### Enable the ClickHouse Plugin
+
+Run the `curl` command to enable the `clickhouse-logger` plugin for the specified route.
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+      "plugins": {
+            "clickhouse-logger": {
+                "user": "default",
+                "password": "a",
+                "database": "default",
+                "logtable": "test",
+                "endpoint_addr": "http://127.0.0.1:8123"
+            }
+       },
+      "upstream": {
+           "type": "roundrobin",
+           "nodes": {
+               "127.0.0.1:1980": 1
+           }
+      },
+      "uri": "/hello"
+}'
+```
+
+The parameters of clickhouse-logger are listed in the chart below.
+
+|Name|Type|Required|Default Value|Range|Description|
+|----|----|--------|------------|-----|-----------|
+|endpoint_addr|string|Yes|n/a|n/a|ClickHouse server endpoint.|
+|database|string|Yes|n/a|n/a|The database used.|
+|logtable|string|Yes|n/a|n/a|The name of the table to write to.|
+|user|string|Yes|n/a|n/a|User for ClickHouse.|
+|password|string|Yes|n/a||Password for ClickHouse.|
+|timeout|integer|No|3|[1,...]|The time to keep the connection active after sending the request.|
+|name|string|No|"clickhouse-logger"|n/a|A unique identifier that identifies the logger.|
+|batch_max_size|integer|No|100|[1,...]|Set the maximum number of logs to be sent each time, and when the maximum number of logs reaches the set value, all logs will be automatically pushed to `clickhouse`.|
+|max_retry_count|integer|No|0|[0,...]|Maximum number of retries before being removed from the processing pipeline.|
+|retry_delay|integer|No|1|[0,...]|If the execution fails, the execution of the process should be delayed for a number of seconds.|
+|ssl_verify|boolean|No|true|[true,false]|Validate the certificate.|
+
+### Test the ClickHouse Plugin
+
+1. Use the `curl` command to test the plugin.
+  
+  ```shell
+  curl -i http://127.0.0.1:9080/hello
+  ```
+
+2. If the following result is returned, it means it is successfully enabled.
+
+  ```shell
+  HTTP/1.1 200 OK
+  ...
+  hello, world
+  ```
+
+### Advanced Skill: Configure Log Format
+
+You can set a custom log format using the `log_format` metadata, as shown in the example below.
+
+1. Configure the `log_format` metadata parameter.
+
+  ```shell
+  curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/clickhouse-logger \
+  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+  {
+      "log_format": {
+          "host": "$host",
+          "@timestamp": "$time_iso8601",
+          "client_ip": "$remote_addr"
+      }
+  }'
+  ```
+
+  > Declare the log format as a key-value pair in JSON format. For the value part, only strings are supported. If it starts with`$`, it indicates that it is to get [APISIX built-in variables](https://apisix.apache.org/docs/apisix/apisix-variable) or [Nginx built-in variables](http://nginx.org/en/docs/varindex.html). In particular, **this setting is global**, meaning that specifying `log_format` will take effect on all routes or services bound to `http-logger`.
+
+2. Create a table for ClickHouse to write in.
+
+  ```sql
+  CREATE TABLE default.test (
+    `host` String,
+    `client_ip` String,
+    `route_id` String,
+    `@timestamp` String,
+    PRIMARY KEY(`@timestamp`)
+  ) ENGINE = MergeTree()
+  ```
+
+3. Execute `select * from default.test;` on ClickHouse, you will get data similar to the following.
+
+  ```shell
+  ┌─host──────┬─client_ip─┬─route_id─┬─@timestamp────────────────┐
+  │ 127.0.0.1 │ 127.0.0.1 │    1     │ 2022-01-17T10:03:10+08:00 │
+  └───────────┴───────────┴──────────┴───────────────────────────┘
+  ```
+
+### Advanced Skill: Connect Grafana with ClickHouse
+
+1. Enable the clickhouse-logger plugin globally.
+
+  ```shell
+  curl http://127.0.0.1:9080/apisix/admin/global_rules/1 \
+  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+  {
+      "plugins": {
+          "clickhouse-logger": {
+              "timeout": 3,
+              "retry_delay": 1,
+              "batch_max_size": 100,
+              "user": "default",
+              "password": "a",
+              "database": "default",
+              "logtable": "t",  "max_retry_count": 1,
+              "endpoint_addr": "http://127.0.0.1:8123"
+          }
+      }
+  }'
+  ```
+
+2. Configure the log_format metadata parameter. log_format must be in the same format as the database table structure, otherwise it will cause write failure.
+
+  ```shell
+   curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/clickhouse-logger \
+  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+  {
+      "log_format": {
+          "upstream_header_time": "$upstream_header_time",
+          "upstream_connect_time": "$upstream_connect_time",
+          "status": "$status",
+          "host": "$host",
+          "body_bytes_sent": "$body_bytes_sent",
+          "request": "$request",
+          "remote_user": "$remote_user",
+          "client_ip": "$remote_addr",
+          "content_length": "$content_length",
+          "local_time": "$fmt_ms_time_local",
+          "http_referer": "$http_referer",
+          "http_x_amz_target": "$http_x_amz_target",
+          "http_x_request_id": "$http_x_request_id",
+          "upstream_response_time": "$upstream_response_time",
+          "upstream_status": "$upstream_status",
+          "http_user_agent": "$http_user_agent",
+          "request_time": "$request_time",
+          "upstream_addr": "$upstream_addr",
+          "http_host": "$http_host",
+          "content_type": "$content_type"
+      }
+  }'
+  ```
+
+Here are some screenshots of the dashboard after interfacing with Clickhouse using Grafana.
+
+![Grafana-1](https://static.apiseven.com/202108/1646366781343-ab2848fe-d10a-4222-a90d-79f4fe58999a.png)
+
+![Grafana-2](https://static.apiseven.com/202108/1646366807867-4391a9ff-8b71-411c-8353-38957a5a2da1.png)
+
+![Grafana-3](https://static.apiseven.com/202108/1646366832282-e8f24c63-c914-4051-8239-582bc3e58f50.png)
+
+### Disable the ClickHouse Plugin
+
+`clickhouse-logger` can be disabled by removing the appropriate configuration in the plugin configuration. Since the Apache APISIX plugin is hot-loaded, the configuration can be updated without a restart.
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1  \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "methods": ["GET"],
+    "uri": "/hello",
+    "plugins": {},
+    "upstream": {
+        "type": "roundrobin",
+        "nodes": {
+            "127.0.0.1:1980": 1
+        }
+    }
+}'
+```
+
+## Summary
+
+The above is the whole process of developing clickhouse-logger for Apache APISIX, and how to implement it with Grafana to achieve the same observability with simpler architechure and worlflows. I hope more people in the community will be willing to step out of their comfort zones. Switching from followers to contributors is much easier than you think.

Review comment:
       ```suggestion
   The above is the whole process of developing `clickhouse-logger` for Apache APISIX, and how to implement it with Grafana to achieve the same observability with simpler architechure and worlflows. I hope more people in the community will be willing to step out of their comfort zones. Switching from followers to contributors is much easier than you think.
   ```




-- 
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-website] yzeng25 merged pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
yzeng25 merged pull request #939:
URL: https://github.com/apache/apisix-website/pull/939


   


-- 
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-website] SylviaBABY commented on a change in pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
SylviaBABY commented on a change in pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#discussion_r819286088



##########
File path: website/i18n/zh/docusaurus-plugin-content-blog/2022/03/04/apisix-clickhouse-makes-logging-easier.md
##########
@@ -0,0 +1,248 @@
+---
+title: "化繁为简,Apache APISIX 集成 ClickHouse 插件提升全链路日志效率"
+authors:
+  - name: "齐振东"
+    title: "Author"
+    url: "https://github.com/zhendongcmss"
+    image_url: "https://github.com/zhendongcmss.png"
+  - name: "曾奕霖"
+    title: "Technical Writer"
+    url: "https://github.com/yzeng25"
+    image_url: "https://github.com/yzeng25.png"
+keywords: 
+- Apache APISIX
+- API 网关
+- ClickHouse
+- 日志
+- Ecosystem
+description: 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+tags: [Technology,Logging]
+---
+
+> 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+
+<!--truncate-->
+
+## 背景信息
+
+Apache APISIX 是一个动态、实时、高性能的 API 网关,提供负载均衡、动态上游、灰度发布、服务熔断、身份认证、可观测性等丰富的流量管理功能。作为 API 网关,Apache APISIX 拥有多种类型的实用插件。得益于 Apache APISIX 的插件热加载机制,我们无需重启便可启用插件、修改插件配置和停用插件。
+
+ClickHouse 由 Yandex 开发,在2016年开源。ClickHouse 不止是一个数据库, 也是一个数据库管理系统,它允许在运行时创建表和数据库、加载数据和运行查询,而无需重新配置或重启服务。

Review comment:
       ```suggestion
   ClickHouse 由 Yandex 开发,在 2016 年开源。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-website] hf400159 commented on a change in pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
hf400159 commented on a change in pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#discussion_r819292032



##########
File path: website/i18n/zh/docusaurus-plugin-content-blog/2022/03/04/apisix-clickhouse-makes-logging-easier.md
##########
@@ -0,0 +1,248 @@
+---
+title: "化繁为简,Apache APISIX 集成 ClickHouse 插件提升全链路日志效率"
+authors:
+  - name: "齐振东"
+    title: "Author"
+    url: "https://github.com/zhendongcmss"
+    image_url: "https://github.com/zhendongcmss.png"
+  - name: "曾奕霖"
+    title: "Technical Writer"
+    url: "https://github.com/yzeng25"
+    image_url: "https://github.com/yzeng25.png"
+keywords: 
+- Apache APISIX
+- API 网关
+- ClickHouse
+- 日志
+- Ecosystem
+description: 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+tags: [Technology,Logging]
+---
+
+> 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+
+<!--truncate-->
+
+## 背景信息
+
+Apache APISIX 是一个动态、实时、高性能的 API 网关,提供负载均衡、动态上游、灰度发布、服务熔断、身份认证、可观测性等丰富的流量管理功能。作为 API 网关,Apache APISIX 拥有多种类型的实用插件。得益于 Apache APISIX 的插件热加载机制,我们无需重启便可启用插件、修改插件配置和停用插件。
+
+ClickHouse 由 Yandex 开发,在 2016 年开源。ClickHouse 不止是一个数据库, 也是一个数据库管理系统,它允许在运行时创建表和数据库、加载数据和运行查询,而无需重新配置或重启服务。
+
+随着越来越多的公司开始将业务迁移上云,如何高效地实现日志收发及日志分析,增强系统的可观测性成为了一个难题。中国移动作为一家提供公有云服务的企业,前期基于 Apache APISIX 的业务日志收发和和分析系统的架构大致是这样的。
+
+![initial bussiness architecture](https://static.apiseven.com/202108/1646363723740-f92d6a39-64e0-4464-8c44-c73832362bf6.png)
+
+随着业务的增长,上述方案不仅维护成本奇高,而且难以满足我们对于精细化数据分析的需求。由于 rsyslog 接收到的数据是一个字符串,而不是 JSON 格式的日志,给日志分析带来了一定的难度。
+
+计算机领域有句名言: “任何问题都可以通过增加一个间接的中间层来解决”。我们其实也考虑过在 `tcp-logger` 和 rsyslog 之间再加一个中间层,使字符串转换为 JSON。但这显然不是长久之计。
+
+所以我们换了一种思路去看待这个问题:如果把现有架构中的 “tcp-logger+rsyslog+Promtail+Loki” 看作是一个巨大的中间层,那么不论我们在这中间怎么添加额外的中间层,除了能解决燃眉之急外,只会使它变得更加臃肿和难以维护。市面上有没有一个产品能直接把“tcp-logger+rsyslog+Promtail+Loki”给替换掉呢?

Review comment:
       ```suggestion
   所以我们换了一种思路去看待这个问题:如果把现有架构中的“tcp-logger+rsyslog+Promtail+Loki”看作是一个巨大的中间层,那么不论我们在这中间怎么添加额外的中间层,除了能解决燃眉之急外,只会使它变得更加臃肿和难以维护。市面上有没有一个产品能直接把“tcp-logger+rsyslog+Promtail+Loki”给替换掉呢?
   ```

##########
File path: website/i18n/zh/docusaurus-plugin-content-blog/2022/03/04/apisix-clickhouse-makes-logging-easier.md
##########
@@ -0,0 +1,248 @@
+---
+title: "化繁为简,Apache APISIX 集成 ClickHouse 插件提升全链路日志效率"
+authors:
+  - name: "齐振东"
+    title: "Author"
+    url: "https://github.com/zhendongcmss"
+    image_url: "https://github.com/zhendongcmss.png"
+  - name: "曾奕霖"
+    title: "Technical Writer"
+    url: "https://github.com/yzeng25"
+    image_url: "https://github.com/yzeng25.png"
+keywords: 
+- Apache APISIX
+- API 网关
+- ClickHouse
+- 日志
+- Ecosystem
+description: 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+tags: [Technology,Logging]
+---
+
+> 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+
+<!--truncate-->
+
+## 背景信息
+
+Apache APISIX 是一个动态、实时、高性能的 API 网关,提供负载均衡、动态上游、灰度发布、服务熔断、身份认证、可观测性等丰富的流量管理功能。作为 API 网关,Apache APISIX 拥有多种类型的实用插件。得益于 Apache APISIX 的插件热加载机制,我们无需重启便可启用插件、修改插件配置和停用插件。
+
+ClickHouse 由 Yandex 开发,在 2016 年开源。ClickHouse 不止是一个数据库, 也是一个数据库管理系统,它允许在运行时创建表和数据库、加载数据和运行查询,而无需重新配置或重启服务。
+
+随着越来越多的公司开始将业务迁移上云,如何高效地实现日志收发及日志分析,增强系统的可观测性成为了一个难题。中国移动作为一家提供公有云服务的企业,前期基于 Apache APISIX 的业务日志收发和和分析系统的架构大致是这样的。
+
+![initial bussiness architecture](https://static.apiseven.com/202108/1646363723740-f92d6a39-64e0-4464-8c44-c73832362bf6.png)
+
+随着业务的增长,上述方案不仅维护成本奇高,而且难以满足我们对于精细化数据分析的需求。由于 rsyslog 接收到的数据是一个字符串,而不是 JSON 格式的日志,给日志分析带来了一定的难度。
+
+计算机领域有句名言: “任何问题都可以通过增加一个间接的中间层来解决”。我们其实也考虑过在 `tcp-logger` 和 rsyslog 之间再加一个中间层,使字符串转换为 JSON。但这显然不是长久之计。
+
+所以我们换了一种思路去看待这个问题:如果把现有架构中的 “tcp-logger+rsyslog+Promtail+Loki” 看作是一个巨大的中间层,那么不论我们在这中间怎么添加额外的中间层,除了能解决燃眉之急外,只会使它变得更加臃肿和难以维护。市面上有没有一个产品能直接把“tcp-logger+rsyslog+Promtail+Loki”给替换掉呢?
+
+带着这个问题,我们花了些时间进行调研,最终选择 ClickHouse 主要有以下几点原因。
+
+1. ClickHouse 提供 HTTP 接口,方便其它模块调用。
+2. 基于 ClickHouse 的分析工具链很成熟,能够满足我们对日志分析的需求。
+3. ClickHouse 支持使用对象存储作为存储引擎,非常方便。
+4. 没有必要自己重复“造轮子”。
+
+接下来就只剩下一个问题需要解决了:如何实现 Apache APISIX 和 ClickHouse 之间的对接?以插件的形式实现对接其实是一个不错的方法。作为 Apache APISIX 社区的一员,我一直都在社区里面“潜水”,看到了最近 Apache APISIX 在生态方面的持续进步,其实我也有些心动,一直在使用 Apache APISIX,但还没有给社区贡献过代码,不如就借这个机会为社区的生态发展添一把火吧。
+
+## ClickHouse 插件实现原理
+
+`clickhouse-logger` 插件的作为一个中间层,对接 Apache APISIX 和 ClickHouse。如前文所说,我们使用Apache APISIX 作为七层负载均衡,请求经过 Apache APISIX 会产生日志,比如 access log 和 error log。`clickhouse-logger` 收集到日志后,会按照自身 metadata 所设置的日志格式,对这些日志进行整理。最后依靠批处理器将整理过的日志批量发送至 ClickHouse。
+
+![clickhouse-logger architecture](https://static.apiseven.com/202108/1646363936994-c2646095-1ea4-4c1f-8cad-1dcecfc41df3.png)
+
+`clickhouse-logger` 在我们这个场景下,起到了替代 “tcp-logger+rsyslog+Promtail+Loki”的作用。免除了多个组件之间的格式转换和数据转发,可将 Log 数据请求直接推送到 ClickHouse 服务器。

Review comment:
       ```suggestion
   `clickhouse-logger` 在我们这个场景下,起到了替代“tcp-logger+rsyslog+Promtail+Loki”的作用。免除了多个组件之间的格式转换和数据转发,可将 Log 数据请求直接推送到 ClickHouse 服务器。
   ```

##########
File path: website/i18n/zh/docusaurus-plugin-content-blog/2022/03/04/apisix-clickhouse-makes-logging-easier.md
##########
@@ -0,0 +1,248 @@
+---
+title: "化繁为简,Apache APISIX 集成 ClickHouse 插件提升全链路日志效率"
+authors:
+  - name: "齐振东"
+    title: "Author"
+    url: "https://github.com/zhendongcmss"
+    image_url: "https://github.com/zhendongcmss.png"
+  - name: "曾奕霖"
+    title: "Technical Writer"
+    url: "https://github.com/yzeng25"
+    image_url: "https://github.com/yzeng25.png"
+keywords: 
+- Apache APISIX
+- API 网关
+- ClickHouse
+- 日志
+- Ecosystem
+description: 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+tags: [Technology,Logging]
+---
+
+> 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+
+<!--truncate-->
+
+## 背景信息
+
+Apache APISIX 是一个动态、实时、高性能的 API 网关,提供负载均衡、动态上游、灰度发布、服务熔断、身份认证、可观测性等丰富的流量管理功能。作为 API 网关,Apache APISIX 拥有多种类型的实用插件。得益于 Apache APISIX 的插件热加载机制,我们无需重启便可启用插件、修改插件配置和停用插件。
+
+ClickHouse 由 Yandex 开发,在 2016 年开源。ClickHouse 不止是一个数据库, 也是一个数据库管理系统,它允许在运行时创建表和数据库、加载数据和运行查询,而无需重新配置或重启服务。
+
+随着越来越多的公司开始将业务迁移上云,如何高效地实现日志收发及日志分析,增强系统的可观测性成为了一个难题。中国移动作为一家提供公有云服务的企业,前期基于 Apache APISIX 的业务日志收发和和分析系统的架构大致是这样的。
+
+![initial bussiness architecture](https://static.apiseven.com/202108/1646363723740-f92d6a39-64e0-4464-8c44-c73832362bf6.png)
+
+随着业务的增长,上述方案不仅维护成本奇高,而且难以满足我们对于精细化数据分析的需求。由于 rsyslog 接收到的数据是一个字符串,而不是 JSON 格式的日志,给日志分析带来了一定的难度。
+
+计算机领域有句名言: “任何问题都可以通过增加一个间接的中间层来解决”。我们其实也考虑过在 `tcp-logger` 和 rsyslog 之间再加一个中间层,使字符串转换为 JSON。但这显然不是长久之计。
+
+所以我们换了一种思路去看待这个问题:如果把现有架构中的 “tcp-logger+rsyslog+Promtail+Loki” 看作是一个巨大的中间层,那么不论我们在这中间怎么添加额外的中间层,除了能解决燃眉之急外,只会使它变得更加臃肿和难以维护。市面上有没有一个产品能直接把“tcp-logger+rsyslog+Promtail+Loki”给替换掉呢?
+
+带着这个问题,我们花了些时间进行调研,最终选择 ClickHouse 主要有以下几点原因。
+
+1. ClickHouse 提供 HTTP 接口,方便其它模块调用。
+2. 基于 ClickHouse 的分析工具链很成熟,能够满足我们对日志分析的需求。
+3. ClickHouse 支持使用对象存储作为存储引擎,非常方便。
+4. 没有必要自己重复“造轮子”。
+
+接下来就只剩下一个问题需要解决了:如何实现 Apache APISIX 和 ClickHouse 之间的对接?以插件的形式实现对接其实是一个不错的方法。作为 Apache APISIX 社区的一员,我一直都在社区里面“潜水”,看到了最近 Apache APISIX 在生态方面的持续进步,其实我也有些心动,一直在使用 Apache APISIX,但还没有给社区贡献过代码,不如就借这个机会为社区的生态发展添一把火吧。
+
+## ClickHouse 插件实现原理
+
+`clickhouse-logger` 插件的作为一个中间层,对接 Apache APISIX 和 ClickHouse。如前文所说,我们使用Apache APISIX 作为七层负载均衡,请求经过 Apache APISIX 会产生日志,比如 access log 和 error log。`clickhouse-logger` 收集到日志后,会按照自身 metadata 所设置的日志格式,对这些日志进行整理。最后依靠批处理器将整理过的日志批量发送至 ClickHouse。
+
+![clickhouse-logger architecture](https://static.apiseven.com/202108/1646363936994-c2646095-1ea4-4c1f-8cad-1dcecfc41df3.png)
+
+`clickhouse-logger` 在我们这个场景下,起到了替代 “tcp-logger+rsyslog+Promtail+Loki”的作用。免除了多个组件之间的格式转换和数据转发,可将 Log 数据请求直接推送到 ClickHouse 服务器。
+
+![improved bussiness architecture](https://static.apiseven.com/202108/1646364005040-93d70286-e7e6-4fb5-a164-1de1c865ce2b.png)
+
+## 操作步骤
+
+以下是在一个路由中启用 `clickhouse-logger` 插件的示例过程。
+
+### 启用 ClickHouse 插件
+
+运行 `curl` 命令,为指定路由开启 `clickhouse-logger` 插件。
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+      "plugins": {
+            "clickhouse-logger": {
+                "user": "default",
+                "password": "a",
+                "database": "default",
+                "logtable": "test",
+                "endpoint_addr": "http://127.0.0.1:8123"
+            }
+       },
+      "upstream": {
+           "type": "roundrobin",
+           "nodes": {
+               "127.0.0.1:1980": 1
+           }
+      },
+      "uri": "/hello"
+}'
+```
+
+`clickhouse-logger` 的参数表如下。
+
+|名称|类型|必填|默认值|取值范围|描述|
+|----|----|--------|------------|-----|-----------|
+|endpoint_addr|string|是|n/a|n/a|ClickHouse 服务器的 endpoint。|
+|database|string|是|n/a|n/a|使用的数据库。|
+|logtable|string|是|n/a|n/a|写入的表名 。|
+|user|string|是|n/a|n/a|ClickHouse 的用户。|
+|password|string|是|n/a||ClickHouse 的密码 。|
+|timeout|integer|否|3|[1,...]|发送请求后保持连接活动的时间。|
+|name|string|否|"clickhouse-logger"|n/a|标识 logger 的唯一标识符。|
+|batch_max_size|integer|否|100|[1,...]|设置每批发送日志的最大条数,当日志条数达到设置的最大值时,会自动推送全部日志到 `clickhouse`。|
+|max_retry_count|integer|否|0|[0,...]|从处理管道中移除之前的最大重试次数。|
+|retry_delay|integer|否|1|[0,...]|如果执行失败,则应延迟执行流程的秒数。|
+|ssl_verify|boolean|否|true|[true,false]|验证证书。|
+
+### 测试 ClickHouse 插件
+
+1. 使用 `curl` 命令测试插件。
+  
+  ```shell
+  curl -i http://127.0.0.1:9080/hello
+  ```
+
+2. 返回结果如下,则表示成功启用。
+
+  ```shell
+  HTTP/1.1 200 OK
+  ...
+  hello, world
+  ```
+
+### 进阶操作 1:设置日志格式
+
+你可以使用 `log_format` 这个元数据设置自定义的日志格式,示例如下。
+
+1. 配置 `log_format` 元数据参数。
+
+  ```shell
+  curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/clickhouse-logger \
+  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+  {
+      "log_format": {
+          "host": "$host",
+          "@timestamp": "$time_iso8601",
+          "client_ip": "$remote_addr"
+      }
+  }'
+  ```
+
+  > 以 JSON 格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 [APISIX 变量](https://apisix.apache.org/docs/apisix/apisix-variable)或 [Nginx 内置变量](http://nginx.org/en/docs/varindex.html)。**该设置是全局生效的**,意味着指定 `log_format` 后,将对所有绑定 `http-logger` 的 Route 或 Service 生效。
+
+2. 创建 ClickHouse 写入的表格。
+
+  ```sql
+  CREATE TABLE default.test (
+    `host` String,
+    `client_ip` String,
+    `route_id` String,
+    `@timestamp` String,
+    PRIMARY KEY(`@timestamp`)
+  ) ENGINE = MergeTree()
+  ```
+
+3. 在 ClickHouse 上执行 `select * from default.test;`,将得到类似下面的数据。
+
+  ```shell
+  ┌─host──────┬─client_ip─┬─route_id─┬─@timestamp────────────────┐
+  │ 127.0.0.1 │ 127.0.0.1 │    1     │ 2022-01-17T10:03:10+08:00 │
+  └───────────┴───────────┴──────────┴───────────────────────────┘
+  ```
+
+### 进阶操作 2:使用 Grafana 与 ClickHouse 对接
+
+1. 全局开启 `clickhouse-logger` 插件。
+
+  ```shell
+  curl http://127.0.0.1:9080/apisix/admin/global_rules/1 \
+  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+  {
+      "plugins": {
+          "clickhouse-logger": {
+              "timeout": 3,
+              "retry_delay": 1,
+              "batch_max_size": 100,
+              "user": "default",
+              "password": "a",
+              "database": "default",
+              "logtable": "t",  "max_retry_count": 1,
+              "endpoint_addr": "http://127.0.0.1:8123"
+          }
+      }
+  }'
+  ```
+
+2. 配置 `log_format` 元数据参数。`log_format` 的格式必须与数据库表的结构保持一致,否则会导致写入失败。
+
+  ```shell
+   curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/clickhouse-logger \
+  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+  {
+      "log_format": {
+          "upstream_header_time": "$upstream_header_time",
+          "upstream_connect_time": "$upstream_connect_time",
+          "status": "$status",
+          "host": "$host",
+          "body_bytes_sent": "$body_bytes_sent",
+          "request": "$request",
+          "remote_user": "$remote_user",
+          "client_ip": "$remote_addr",
+          "content_length": "$content_length",
+          "local_time": "$fmt_ms_time_local",
+          "http_referer": "$http_referer",
+          "http_x_amz_target": "$http_x_amz_target",
+          "http_x_request_id": "$http_x_request_id",
+          "upstream_response_time": "$upstream_response_time",
+          "upstream_status": "$upstream_status",
+          "http_user_agent": "$http_user_agent",
+          "request_time": "$request_time",
+          "upstream_addr": "$upstream_addr",
+          "http_host": "$http_host",
+          "content_type": "$content_type"
+      }
+  }'
+  ```
+
+以下是使用 Grafana 与 Clickhouse 对接后的仪表盘视图。
+
+![Grafana-1](https://static.apiseven.com/202108/1646366781343-ab2848fe-d10a-4222-a90d-79f4fe58999a.png)
+
+![Grafana-2](https://static.apiseven.com/202108/1646366807867-4391a9ff-8b71-411c-8353-38957a5a2da1.png)
+
+![Grafana-3](https://static.apiseven.com/202108/1646366832282-e8f24c63-c914-4051-8239-582bc3e58f50.png)
+
+### 禁用 ClickHouse 插件
+
+在插件配置中删除相应的配置即可禁用 `clickhouse-logger`。由于 Apache APISIX 插件是热加载模式,因此无需重新启动即可更新配置。
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1  \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "methods": ["GET"],
+    "uri": "/hello",
+    "plugins": {},
+    "upstream": {
+        "type": "roundrobin",
+        "nodes": {
+            "127.0.0.1:1980": 1
+        }
+    }
+}'
+```
+
+## 总结
+
+以上就是我为 Apache APISIX 开发 `clickhouse-logger` 的全过程。希望社区里有更多的人愿意走出舒适区,实现自身的角色转换,从关注者变为贡献者的远比你想象的简单。

Review comment:
       ```suggestion
   以上就是我为 Apache APISIX 开发 `clickhouse-logger` 的全过程。希望社区里有更多的人愿意走出舒适区,实现自身的角色转换,从关注者变为贡献者的过程远比你想象的简单。
   ```




-- 
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-website] netlify[bot] edited a comment on pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
netlify[bot] edited a comment on pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#issuecomment-1058820229


   👷 Deploy Preview for *apache-apisix* processing.
   
   
   🔨 Explore the source changes: f566f47b6aa5656eb0ea9822f41cbab2234e0fb7
   
   🔍 Inspect the deploy log: [https://app.netlify.com/sites/apache-apisix/deploys/6221aba68a34de0008341fe8](https://app.netlify.com/sites/apache-apisix/deploys/6221aba68a34de0008341fe8)
   


-- 
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-website] netlify[bot] edited a comment on pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
netlify[bot] edited a comment on pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#issuecomment-1058820229


   ✔️ Deploy Preview for *apache-apisix* ready!
   
   
   🔨 Explore the source changes: 2c889ee009daaed3b126b28ba7bcf8f051397cee
   
   🔍 Inspect the deploy log: [https://app.netlify.com/sites/apache-apisix/deploys/62259aa1d02cc20007770017](https://app.netlify.com/sites/apache-apisix/deploys/62259aa1d02cc20007770017)
   
   😎 Browse the preview: [https://deploy-preview-939--apache-apisix.netlify.app](https://deploy-preview-939--apache-apisix.netlify.app)
   


-- 
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-website] netlify[bot] edited a comment on pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
netlify[bot] edited a comment on pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#issuecomment-1058820229


   👷 Deploy Preview for *apache-apisix* processing.
   
   
   🔨 Explore the source changes: 2c889ee009daaed3b126b28ba7bcf8f051397cee
   
   🔍 Inspect the deploy log: [https://app.netlify.com/sites/apache-apisix/deploys/62259aa1d02cc20007770017](https://app.netlify.com/sites/apache-apisix/deploys/62259aa1d02cc20007770017)
   


-- 
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-website] yzeng25 commented on a change in pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
yzeng25 commented on a change in pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#discussion_r820394460



##########
File path: website/blog/2022/03/04/apisix-clickhouse-makes-logging-easier.md
##########
@@ -0,0 +1,248 @@
+---
+title: "Making It Simple, Apache APISIX Integrates ClickHouse to Improve Logging Efficiency"

Review comment:
       updated both file names




-- 
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-website] SylviaBABY commented on a change in pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
SylviaBABY commented on a change in pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#discussion_r819286240



##########
File path: website/i18n/zh/docusaurus-plugin-content-blog/2022/03/04/apisix-clickhouse-makes-logging-easier.md
##########
@@ -0,0 +1,248 @@
+---
+title: "化繁为简,Apache APISIX 集成 ClickHouse 插件提升全链路日志效率"
+authors:
+  - name: "齐振东"
+    title: "Author"
+    url: "https://github.com/zhendongcmss"
+    image_url: "https://github.com/zhendongcmss.png"
+  - name: "曾奕霖"
+    title: "Technical Writer"
+    url: "https://github.com/yzeng25"
+    image_url: "https://github.com/yzeng25.png"
+keywords: 
+- Apache APISIX
+- API 网关
+- ClickHouse
+- 日志
+- Ecosystem
+description: 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+tags: [Technology,Logging]
+---
+
+> 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+
+<!--truncate-->
+
+## 背景信息
+
+Apache APISIX 是一个动态、实时、高性能的 API 网关,提供负载均衡、动态上游、灰度发布、服务熔断、身份认证、可观测性等丰富的流量管理功能。作为 API 网关,Apache APISIX 拥有多种类型的实用插件。得益于 Apache APISIX 的插件热加载机制,我们无需重启便可启用插件、修改插件配置和停用插件。
+
+ClickHouse 由 Yandex 开发,在2016年开源。ClickHouse 不止是一个数据库, 也是一个数据库管理系统,它允许在运行时创建表和数据库、加载数据和运行查询,而无需重新配置或重启服务。
+
+随着越来越多的公司开始将业务迁移上云,如何高效地实现日志收发及日志分析,增强系统的可观测性成为了一个难题。中国移动作为一家提供公有云服务的企业,前期基于 Apache APISIX 的业务日志收发和和分析系统的架构大致是这样的。
+
+![initial bussiness architecture](https://static.apiseven.com/202108/1646363723740-f92d6a39-64e0-4464-8c44-c73832362bf6.png)
+
+随着业务的增长,上述方案不仅维护成本奇高,而且难以满足我们对于精细化数据分析的需求。由于 rsyslog 接收到的数据是一个字符串,而不是 JSON 格式的日志,给日志分析带来了一定的难度。
+
+计算机领域有句名言: “任何问题都可以通过增加一个间接的中间层来解决”。我们其实也考虑过在 `tcp-logger` 和 rsyslog 之间再加一个中间层,使字符串转换为 JSON。但这显然不是长久之计。
+
+所以我们换了一种思路去看待这个问题:如果把现有架构中的 “tcp-logger+rsyslog+Promtail+Loki” 看作是一个巨大的中间层,那么不论我们在这中间怎么添加额外的中间层,除了能解决燃眉之急外,只会使它变得更加臃肿和难以维护。市面上有没有一个产品能直接把“tcp-logger+rsyslog+Promtail+Loki”给替换掉呢?
+
+带着这个问题,我们花了些时间进行调研,最终选择 ClickHouse 主要有以下几点原因。
+
+1. ClickHouse 提供 HTTP 接口,方便其它模块调用。
+2. 基于 ClickHouse 的分析工具链很成熟,能够满足我们对日志分析的需求。
+3. ClickHouse 支持使用对象存储作为存储引擎,非常方便。
+4. 没有必要自己重复“造轮子”。
+
+接下来就只剩下一个问题需要解决了:如何实现 Apache APISIX 和 ClickHouse 之间的对接?以插件的形式实现对接其实是一个不错的方法。作为 Apache APISIX 社区的一员,我一直都在社区里面“潜水”,看到了最近 Apache APISIX 在生态方面的持续进步,其实我也有些心动,一直在使用 Apache APISIX,但还没有给社区贡献过代码,不如就借这个机会为社区的生态发展添一把火吧。
+
+## ClickHouse 插件实现原理
+
+`clickhouse-logger` 插件的作为一个中间层,对接 Apache APISIX 和 ClickHouse。如前文所说,我们使用Apache APISIX 作为七层负载均衡,请求经过 Apache APISIX会产生日志,比如 access log 和 error log。`clickhouse-logger` 收集到日志后,会按照自身 metadata 所设置的日志格式,对这些日志进行整理。最后依靠批处理器将整理过的日志批量发送至 ClickHouse。
+
+![clickhouse-logger architecture](https://static.apiseven.com/202108/1646363936994-c2646095-1ea4-4c1f-8cad-1dcecfc41df3.png)
+
+`clickhouse-logger` 在我们这个场景下,起到了替代 “tcp-logger+rsyslog+Promtail+Loki”的作用。免除了多个组件之间的格式转换和数据转发,可将 Log 数据请求直接推送到 ClickHouse 服务器。
+
+![improved bussiness architecture](https://static.apiseven.com/202108/1646364005040-93d70286-e7e6-4fb5-a164-1de1c865ce2b.png)
+
+## 操作步骤
+
+以下是在一个路由中启用 `clickhouse-logger` 插件的示例过程。
+
+### 启用 ClickHouse 插件
+
+运行 `curl` 命令,为指定路由开启 `clickhouse-logger` 插件。
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 \
+-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+      "plugins": {
+            "clickhouse-logger": {
+                "user": "default",
+                "password": "a",
+                "database": "default",
+                "logtable": "test",
+                "endpoint_addr": "http://127.0.0.1:8123"
+            }
+       },
+      "upstream": {
+           "type": "roundrobin",
+           "nodes": {
+               "127.0.0.1:1980": 1
+           }
+      },
+      "uri": "/hello"
+}'
+```
+
+`clickhouse-logger` 的参数表如下。
+
+|名称|类型|必填|默认值|取值范围|描述|
+|----|----|--------|------------|-----|-----------|
+|endpoint_addr|string|是|n/a|n/a|ClickHouse 服务器的 endpoint。|
+|database|string|是|n/a|n/a|使用的数据库。|
+|logtable|string|是|n/a|n/a|写入的表名 。|
+|user|string|是|n/a|n/a|ClickHouse 的用户。|
+|password|string|是|n/a||ClickHouse 的密码 。|
+|timeout|integer|否|3|[1,...]|发送请求后保持连接活动的时间。|
+|name|string|否|"clickhouse-logger"|n/a|标识 logger 的唯一标识符。|
+|batch_max_size|integer|否|100|[1,...]|设置每批发送日志的最大条数,当日志条数达到设置的最大值时,会自动推送全部日志到 `clickhouse`。|
+|max_retry_count|integer|否|0|[0,...]|从处理管道中移除之前的最大重试次数。|
+|retry_delay|integer|否|1|[0,...]|如果执行失败,则应延迟执行流程的秒数。|
+|ssl_verify|boolean|否|true|[true,false]|验证证书。|
+
+### 测试 ClickHouse 插件
+
+1. 使用 `curl` 命令测试插件。
+  
+  ```shell
+  curl -i http://127.0.0.1:9080/hello
+  ```
+
+2. 返回结果如下,则表示成功启用。
+
+  ```shell
+  HTTP/1.1 200 OK
+  ...
+  hello, world
+  ```
+
+### 进阶操作 1:设置日志格式
+
+你可以使用 `log_format` 这个元数据设置自定义的日志格式,示例如下。
+
+1. 配置 `log_format` 元数据参数。
+
+  ```shell
+  curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/clickhouse-logger \
+  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+  {
+      "log_format": {
+          "host": "$host",
+          "@timestamp": "$time_iso8601",
+          "client_ip": "$remote_addr"
+      }
+  }'
+  ```
+
+  > 以 JSON 格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 [APISIX 变量](https://apisix.apache.org/docs/apisix/apisix-variable)或 [Nginx 内置变量](http://nginx.org/en/docs/varindex.html)。**该设置是全局生效的**,意味着指定 `log_format` 后,将对所有绑定 `http-logger` 的 Route 或 Service 生效。
+
+2. 创建 ClickHouse 写入的表格。
+
+  ```sql
+  CREATE TABLE default.test (
+    `host` String,
+    `client_ip` String,
+    `route_id` String,
+    `@timestamp` String,
+    PRIMARY KEY(`@timestamp`)
+  ) ENGINE = MergeTree()
+  ```
+
+3. 在 ClickHouse 上执行 `select * from default.test;`,将得到类似下面的数据。
+
+  ```shell
+  ┌─host──────┬─client_ip─┬─route_id─┬─@timestamp────────────────┐
+  │ 127.0.0.1 │ 127.0.0.1 │    1     │ 2022-01-17T10:03:10+08:00 │
+  └───────────┴───────────┴──────────┴───────────────────────────┘
+  ```
+
+### 进阶操作 2:使用 Grafana 与 ClickHouse 对接
+
+1. 全局开启 `clickhouse-logger` 插件。
+
+  ```shell
+  curl http://127.0.0.1:9080/apisix/admin/global_rules/1 \
+  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+  {
+      "plugins": {
+          "clickhouse-logger": {
+              "timeout": 3,
+              "retry_delay": 1,
+              "batch_max_size": 100,
+              "user": "default",
+              "password": "a",
+              "database": "default",
+              "logtable": "t",  "max_retry_count": 1,
+              "endpoint_addr": "http://127.0.0.1:8123"
+          }
+      }
+  }'
+  ```
+
+2. 配置 `log_format` 元数据参数。`log_format` 的格式必须与数据库表的结构保持一致,否则会导致写入失败。
+
+  ```shell
+   curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/clickhouse-logger \
+  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+  {
+      "log_format": {
+          "upstream_header_time": "$upstream_header_time",
+          "upstream_connect_time": "$upstream_connect_time",
+          "status": "$status",
+          "host": "$host",
+          "body_bytes_sent": "$body_bytes_sent",
+          "request": "$request",
+          "remote_user": "$remote_user",
+          "client_ip": "$remote_addr",
+          "content_length": "$content_length",
+          "local_time": "$fmt_ms_time_local",
+          "http_referer": "$http_referer",
+          "http_x_amz_target": "$http_x_amz_target",
+          "http_x_request_id": "$http_x_request_id",
+          "upstream_response_time": "$upstream_response_time",
+          "upstream_status": "$upstream_status",
+          "http_user_agent": "$http_user_agent",
+          "request_time": "$request_time",
+          "upstream_addr": "$upstream_addr",
+          "http_host": "$http_host",
+          "content_type": "$content_type"
+      }
+  }'
+  ```
+
+以下是使用 Grafana  与 Clickhouse 对接后的仪表盘视图。

Review comment:
       ```suggestion
   以下是使用 Grafana 与 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-website] netlify[bot] edited a comment on pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
netlify[bot] edited a comment on pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#issuecomment-1058820229


   👷 Deploy Preview for *apache-apisix* processing.
   
   
   🔨 Explore the source changes: 05a065d40b1a5cac791f406b7291d697a0047bac
   
   🔍 Inspect the deploy log: [https://app.netlify.com/sites/apache-apisix/deploys/6221b3e5bbb6020008df402b](https://app.netlify.com/sites/apache-apisix/deploys/6221b3e5bbb6020008df402b)
   


-- 
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-website] SylviaBABY commented on a change in pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
SylviaBABY commented on a change in pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#discussion_r819286440



##########
File path: website/i18n/zh/docusaurus-plugin-content-blog/2022/03/04/apisix-clickhouse-makes-logging-easier.md
##########
@@ -0,0 +1,248 @@
+---
+title: "化繁为简,Apache APISIX 集成 ClickHouse 插件提升全链路日志效率"
+authors:
+  - name: "齐振东"
+    title: "Author"
+    url: "https://github.com/zhendongcmss"
+    image_url: "https://github.com/zhendongcmss.png"
+  - name: "曾奕霖"
+    title: "Technical Writer"
+    url: "https://github.com/yzeng25"
+    image_url: "https://github.com/yzeng25.png"
+keywords: 
+- Apache APISIX
+- API 网关
+- ClickHouse
+- 日志
+- Ecosystem
+description: 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+tags: [Technology,Logging]
+---
+
+> 本文讲述了社区贡献者齐振东为 Apache APISIX 贡献 `clickhouse-logger` 的历程,以及如何使用该插件简化业务架构,提升全链路日志效率。
+
+<!--truncate-->
+
+## 背景信息
+
+Apache APISIX 是一个动态、实时、高性能的 API 网关,提供负载均衡、动态上游、灰度发布、服务熔断、身份认证、可观测性等丰富的流量管理功能。作为 API 网关,Apache APISIX 拥有多种类型的实用插件。得益于 Apache APISIX 的插件热加载机制,我们无需重启便可启用插件、修改插件配置和停用插件。
+
+ClickHouse 由 Yandex 开发,在2016年开源。ClickHouse 不止是一个数据库, 也是一个数据库管理系统,它允许在运行时创建表和数据库、加载数据和运行查询,而无需重新配置或重启服务。
+
+随着越来越多的公司开始将业务迁移上云,如何高效地实现日志收发及日志分析,增强系统的可观测性成为了一个难题。中国移动作为一家提供公有云服务的企业,前期基于 Apache APISIX 的业务日志收发和和分析系统的架构大致是这样的。
+
+![initial bussiness architecture](https://static.apiseven.com/202108/1646363723740-f92d6a39-64e0-4464-8c44-c73832362bf6.png)
+
+随着业务的增长,上述方案不仅维护成本奇高,而且难以满足我们对于精细化数据分析的需求。由于 rsyslog 接收到的数据是一个字符串,而不是 JSON 格式的日志,给日志分析带来了一定的难度。
+
+计算机领域有句名言: “任何问题都可以通过增加一个间接的中间层来解决”。我们其实也考虑过在 `tcp-logger` 和 rsyslog 之间再加一个中间层,使字符串转换为 JSON。但这显然不是长久之计。
+
+所以我们换了一种思路去看待这个问题:如果把现有架构中的 “tcp-logger+rsyslog+Promtail+Loki” 看作是一个巨大的中间层,那么不论我们在这中间怎么添加额外的中间层,除了能解决燃眉之急外,只会使它变得更加臃肿和难以维护。市面上有没有一个产品能直接把“tcp-logger+rsyslog+Promtail+Loki”给替换掉呢?
+
+带着这个问题,我们花了些时间进行调研,最终选择 ClickHouse 主要有以下几点原因。
+
+1. ClickHouse 提供 HTTP 接口,方便其它模块调用。
+2. 基于 ClickHouse 的分析工具链很成熟,能够满足我们对日志分析的需求。
+3. ClickHouse 支持使用对象存储作为存储引擎,非常方便。
+4. 没有必要自己重复“造轮子”。
+
+接下来就只剩下一个问题需要解决了:如何实现 Apache APISIX 和 ClickHouse 之间的对接?以插件的形式实现对接其实是一个不错的方法。作为 Apache APISIX 社区的一员,我一直都在社区里面“潜水”,看到了最近 Apache APISIX 在生态方面的持续进步,其实我也有些心动,一直在使用 Apache APISIX,但还没有给社区贡献过代码,不如就借这个机会为社区的生态发展添一把火吧。
+
+## ClickHouse 插件实现原理
+
+`clickhouse-logger` 插件的作为一个中间层,对接 Apache APISIX 和 ClickHouse。如前文所说,我们使用Apache APISIX 作为七层负载均衡,请求经过 Apache APISIX会产生日志,比如 access log 和 error log。`clickhouse-logger` 收集到日志后,会按照自身 metadata 所设置的日志格式,对这些日志进行整理。最后依靠批处理器将整理过的日志批量发送至 ClickHouse。

Review comment:
       ```suggestion
   `clickhouse-logger` 插件的作为一个中间层,对接 Apache APISIX 和 ClickHouse。如前文所说,我们使用 Apache APISIX 作为七层负载均衡,请求经过 Apache APISIX会产生日志,比如 access log 和 error log。`clickhouse-logger` 收集到日志后,会按照自身 metadata 所设置的日志格式,对这些日志进行整理。最后依靠批处理器将整理过的日志批量发送至 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-website] netlify[bot] edited a comment on pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
netlify[bot] edited a comment on pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#issuecomment-1058820229


   ✔️ Deploy Preview for *apache-apisix* ready!
   
   
   🔨 Explore the source changes: 05a065d40b1a5cac791f406b7291d697a0047bac
   
   🔍 Inspect the deploy log: [https://app.netlify.com/sites/apache-apisix/deploys/6221b3e5bbb6020008df402b](https://app.netlify.com/sites/apache-apisix/deploys/6221b3e5bbb6020008df402b)
   
   😎 Browse the preview: [https://deploy-preview-939--apache-apisix.netlify.app](https://deploy-preview-939--apache-apisix.netlify.app)
   


-- 
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-website] juzhiyuan commented on a change in pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on a change in pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#discussion_r820227616



##########
File path: website/blog/2022/03/04/apisix-clickhouse-makes-logging-easier.md
##########
@@ -0,0 +1,248 @@
+---
+title: "Making It Simple, Apache APISIX Integrates ClickHouse to Improve Logging Efficiency"

Review comment:
       How about using `api gateway` instead of `apisix` in url?




-- 
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-website] netlify[bot] edited a comment on pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
netlify[bot] edited a comment on pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#issuecomment-1058820229


   ✔️ Deploy Preview for *apache-apisix* ready!
   
   
   🔨 Explore the source changes: f769320c0878bf0467d73f683c9c087ce7a25f3a
   
   🔍 Inspect the deploy log: [https://app.netlify.com/sites/apache-apisix/deploys/622198bb8176700009960310](https://app.netlify.com/sites/apache-apisix/deploys/622198bb8176700009960310)
   
   😎 Browse the preview: [https://deploy-preview-939--apache-apisix.netlify.app](https://deploy-preview-939--apache-apisix.netlify.app)
   


-- 
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-website] netlify[bot] commented on pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
netlify[bot] commented on pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#issuecomment-1058820229


   👷 Deploy Preview for *apache-apisix* processing.
   
   
   🔨 Explore the source changes: d07e31d9bd5b1fea3f7190f6655068bd3650bb2b
   
   🔍 Inspect the deploy log: [https://app.netlify.com/sites/apache-apisix/deploys/62219751f0f8b60008bb7b1b](https://app.netlify.com/sites/apache-apisix/deploys/62219751f0f8b60008bb7b1b)
   


-- 
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-website] netlify[bot] edited a comment on pull request #939: docs: add clickhouse blog

Posted by GitBox <gi...@apache.org>.
netlify[bot] edited a comment on pull request #939:
URL: https://github.com/apache/apisix-website/pull/939#issuecomment-1058820229






-- 
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