Skip to main content
Version: 2.6.1

1. Overview

1.1 Plugin Name#

  • Logging-TencentCls Plugin

1.2 Appropriate Scenario#

  • collect http request information to tencent cls, analysis request information by tencent cls platform.

1.3 Plugin functionality#

  • The gateway receives requests from the client, forwards them to the server, and returns the server results to the client. The gateway can record the details of each request,
  • the plugin records access logs and sends to tencent cls platform.

1.4 Plugin code#

  • Core Module shenyu-plugin-logging-tencent-cls

  • Core Class org.apache.shenyu.plugin.tencent.cls.LoggingTencentClsPlugin

  • Core Class org.apache.shenyu.plugin.tencent.cls.client.TencentClsLogCollectClient

1.5 Added Since Which shenyu version#

ShenYu 2.5.1

2. How to use plugin

2.1 Plugin-use procedure chart#

2.2 Import pom#

  • import maven config in shenyu-bootstrap project's pom.xml file.
<!-- shenyu logging-tencent-cls plugin start --><dependency>  <groupId>org.apache.shenyu</groupId>  <artifactId>shenyu-spring-boot-starter-plugin-logging-tencent-cls</artifactId>  <version>${project.version}</version></dependency><!-- shenyu logging-tencent-cls plugin end -->

2.3 Enable plugin#

  • In shenyu-admin --> BasicConfig --> Plugin --> loggingTencentCls set Status enable.

2.4 Config plugin#

2.4.1 Plugin configuration#

config-itemtyperemarksdescription
secretIdStringmustsecretId
secretKeyStringmustsecretKey
endpointStringmusthost name, example:ap-guangzhou.cls.tencentcs.com
topicStringoptional, default shenyu-topictopic
sendThreadCountStringoptional, default 1Number of core threads for log consumption callback
TotalSizeInBytesIntegeroptional, default 104857600The maximum log size that the instance can cache
MaxSendThreadCountIntegeroptional, default 50The maximum number of "goroutines" that the client can concurrently
MaxBlockSecIntegeroptional, default 60000 msThe maximum amount of time the caller can block on the send method if the client is running out of free space.
If the required space cannot be satisfied after this time,
the send method will throw a TimeoutException. Set this value to a negative number if you want the send method to block until the required space is met
MaxBatchSizeIntegeroptional, default 512 * 1024 (512KB)When the cached log size in a Batch is greater than or equal to batchSizeThresholdInBytes, the batch will be sent, and the maximum size can be set to 5MB
MaxBatchCountIntegeroptional, default 4096When the number of logs cached in a batch is greater than or equal to batchCountThreshold, the batch will be sent and the maximum can be set to 40960
LingerMsIntegeroptional, default 2000 msThe duration of the batch from the creation to the time it can be sent, the minimum can be set to 100 milliseconds
RetriesIntegeroptional, default 10If a Batch fails to be sent for the first time, the number of times it can be retried, if the retries is less than or equal to 0, the ProducerBatch will directly enter the failure queue after the first failure of sending
MaxReservedAttemptsIntegeroptional, default 11Each batch that is attempted to be sent corresponds to an Attemp. This parameter is used to control the number of attempts returned to the user. By default, only the latest 11 attempts are retained. A larger parameter allows you to trace more information, but also consumes more memory
BaseRetryBackoffMsIntegeroptional, default 100 msBackoff time for the first retry The client samples the exponential backoff algorithm, and the planned waiting time for the Nth retry is baseRetryBackoffMs * 2^(N-1
MaxRetryBackoffMsIntegeroptional, default 50 sMaximum backoff time for retries
  • get topic

2.4.2 Configuration Selectors and Rules#

2.5 Logging Info#

collect request info as follows

Field NameMeaningDescriptionRemarks
clientIpClient IP
timeLocalRequest time string, format: yyyy-MM-dd HH:mm:ss.SSS
methodrequest method (different rpc type is not the same, http class for: get, post wait, rpc class for the interface name)
requestHeaderRequest header (json format)
responseHeaderResponse header (json format)
queryParamsRequest query parameters
requestBodyRequest Body (body of binary type will not be captured)
requestUriRequest uri
responseBodyResponse body
responseContentLengthResponse body size
rpcTyperpc type
statusresponse status
upstreamIpUpstream (program providing the service) IP
upstreamResponseTimeTime taken by the upstream (program providing the service) to respond to the request (ms ms)
userAgentRequested user agent
hostThe requested host
moduleRequested modules
pathThe requested path
traceIdRequested Link Tracking IDNeed to access link tracking plugins, such as skywalking,zipkin

2.6 Examples#

2.6.1 Collect Http Log by tencent cls platform#

2.6.1.1 Plugin Configuration#

  • Open the plugin and configure tencent-cls, configure it as follows.

2.6.1.2 Selector Configuration#

2.6.1.3 Rule Configuration#

2.6.1.4 Send Request#

2.6.1.5 Tencent cls Platform Display#

3. How to disable plugin

  • In shenyu-admin --> BasicConfig --> Plugin --> loggingTencentCls set Status disable.