bzp2010 commented on code in PR #9399:
URL: https://github.com/apache/apisix/pull/9399#discussion_r1206331029


##########
docs/en/latest/plugins/loki-logger.md:
##########
@@ -0,0 +1,165 @@
+---
+title: loki-logger
+keywords:
+  - Apache APISIX
+  - API Gateway
+  - Plugin
+  - Loki-logger
+  - Grafana Loki
+description: This document contains information about the Apache APISIX 
loki-logger Plugin.
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+The `loki-logger` plugin is used to forward logs to [Grafana 
Loki](https://grafana.com/oss/loki/) for analysis and storage.
+
+When the Plugin is enabled, APISIX will serialize the request context 
information to [Log entries in 
JSON](https://grafana.com/docs/loki/latest/api/#push-log-entries-to-loki) and 
submit it to the batch queue. When the maximum batch size is exceeded, the data 
in the queue is pushed to Grafana Loki. See [batch 
processor](../batch-processor.md) for more details.
+
+## Attributes
+
+| Name | Type | Required | Default | Description |
+|---|---|---|---|---|
+| endpoint_addrs | array | True |  | Loki API base URL, format like 
http://127.0.0.1:3100, supports HTTPS and domain names. If multiple endpoints 
are configured, they will be written randomly. |

Review Comment:
   @monkeyDluffy6017 fixed



##########
docs/en/latest/plugins/loki-logger.md:
##########
@@ -0,0 +1,165 @@
+---
+title: loki-logger
+keywords:
+  - Apache APISIX
+  - API Gateway
+  - Plugin
+  - Loki-logger
+  - Grafana Loki
+description: This document contains information about the Apache APISIX 
loki-logger Plugin.
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Description
+
+The `loki-logger` plugin is used to forward logs to [Grafana 
Loki](https://grafana.com/oss/loki/) for analysis and storage.
+
+When the Plugin is enabled, APISIX will serialize the request context 
information to [Log entries in 
JSON](https://grafana.com/docs/loki/latest/api/#push-log-entries-to-loki) and 
submit it to the batch queue. When the maximum batch size is exceeded, the data 
in the queue is pushed to Grafana Loki. See [batch 
processor](../batch-processor.md) for more details.
+
+## Attributes
+
+| Name | Type | Required | Default | Description |
+|---|---|---|---|---|
+| endpoint_addrs | array | True |  | Loki API base URL, format like 
http://127.0.0.1:3100, supports HTTPS and domain names. If multiple endpoints 
are configured, they will be written randomly. |
+| endpoint_uri | string | False | /loki/api/v1/push | If you are using a log 
collection service that is compatible with the Loki Push API, you can use this 
configuration item to customize the API path. |
+| tenant_id | string | False | fake | Loki tenant ID. According to Loki's 
[multi-tenancy 
documentation](https://grafana.com/docs/loki/latest/operations/multi-tenancy/#multi-tenancy),
 its default value is set to the default value `fake` under single-tenancy. |
+| log_labels | object | False | {job = "apisix"} | Loki log label. [APISIX 
variables](../apisix-variable.md) and [Nginx 
variables](http://nginx.org/en/docs/varindex.html) can be used by prefixing the 
string with `$`, both individual and combined, such as `$host` or 
`$remote_addr:$remote_port`. |
+| ssl_verify        | boolean       | False    | true | When set to `true`, 
verifies the SSL certificate. |
+| timeout           | integer       | False    | 3000ms  | [1, 60000]ms   | 
Timeout for the authorization service HTTP call. |
+| keepalive         | boolean       | False    | true | When set to `true`, 
keeps the connection alive for multiple requests. |
+| keepalive_timeout | integer       | False    | 60000ms | [1000, ...]ms  | 
Idle time after which the connection is closed. |
+| keepalive_pool    | integer       | False    | 5       | [1, ...]ms     | 
Connection pool limit. |
+| log_format | object | False    |          | Log format declared as key value 
pairs in JSON format. Values only support strings. [APISIX 
variables](../apisix-variable.md) and [Nginx 
variables](http://nginx.org/en/docs/varindex.html) can be used by prefixing the 
string with `$`. |
+| include_req_body       | boolean | False    | false | When set to `true` 
includes the request body in the log. If the request body is too big to be kept 
in the memory, it can't be logged due to Nginx's limitations. |
+| include_req_body_expr  | array   | False    |  | Filter for when the 
`include_req_body` attribute is set to `true`. Request body is only logged when 
the expression set here evaluates to `true`. See 
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more. |
+| include_resp_body      | boolean | False    | false | When set to `true` 
includes the response body in the log. |
+| include_resp_body_expr | array   | False    |  | Filter for when the 
`include_resp_body` attribute is set to `true`. Response body is only logged 
when the expression set here evaluates to `true`. See 
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more. |
+
+This plugin supports using batch processors to aggregate and process entries 
(logs/data) in a batch. This avoids the need for frequently submitting the 
data. The batch processor submits data every `5` seconds or when the data in 
the queue reaches `1000`. See [Batch 
Processor](../batch-processor.md#configuration) for more information or setting 
your custom configuration.
+
+## Metadata
+
+You can also set the format of the logs by configuring the Plugin metadata. 
The following configurations are available:
+
+| Name | Type | Required | Default | Description |
+|------|------|----------|---------|-------------|
+| log_format | object | False | {"host": "$host", "@timestamp": 
"$time_iso8601", "client_ip": "$remote_addr"} | Log format declared as key 
value pairs in JSON format. Values only support strings. [APISIX 
variables](../apisix-variable.md) and [Nginx 
variables](http://nginx.org/en/docs/varindex.html) can be used by prefixing the 
string with `$`. |
+
+:::info IMPORTANT
+
+Configuring the plugin metadata is global in scope. This means that it will 
take effect on all Routes and Services which use the `loki-logger` plugin.
+
+:::
+
+The example below shows how you can configure through the Admin API:
+
+```shell
+curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/loki-logger -H 
'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "log_format": {
+        "host": "$host",
+        "@timestamp": "$time_iso8601",
+        "client_ip": "$remote_addr"
+    }
+}'
+```
+
+With this configuration, your logs would be formatted as shown below:
+
+```shell
+{"host":"localhost","@timestamp":"2020-09-23T19:05:05-04:00","client_ip":"127.0.0.1","route_id":"1"}
+{"host":"localhost","@timestamp":"2020-09-23T19:05:05-04:00","client_ip":"127.0.0.1","route_id":"1"}
+```
+
+## Enabling the plugin
+
+The example below shows how you can enable the `loki-logger` plugin on a 
specific Route:
+
+```shell
+curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "plugins": {
+        "loki-logger": {
+            "endpoint_addrs" : ["http://127.0.0.1:3100";]
+        }
+    },
+    "upstream": {
+       "nodes": {
+           "127.0.0.1:1980": 1
+       },
+       "type": "roundrobin"
+    },
+    "uri": "/hello"
+}'
+```
+
+## Example usage
+
+Now, if you make a request to APISIX, it will be logged in your Loki server:
+
+```shell
+curl -i http://127.0.0.1:9080/hello
+```
+
+## Disable plugin

Review Comment:
   @monkeyDluffy6017 fixed



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to