TLS provides log consumption via the Kafka protocol. That is to say, one log topic can be used as a Kafka topic for consumption. This topic describes the steps to consume log data using the Kafka protocol.
Background information
TLS supports enabling log consumption via the Kafka protocol for specified log topics. Once enabled, you can consume the log topic as a Kafka topic, with each log corresponding to a Kafka message. In actual business scenarios, after integrating TLS with an open-source Kafka SDK, you can use the Kafka Consumer to ship logs collected from designated log topics to downstream big data components or data warehouses. This is suitable for streaming analytics and big data storage.
When consuming logs via the Kafka protocol, you can consume data as a consumer or a consumer group. Cross-project consumption is not supported.
Limits
- Kafka protocol consumption supports Kafka Client versions 0.11.x to 2.0.x.
- When the Kafka protocol consumption feature is enabled, you can consume log data collected on the server side during the runtime of the Kafka Consumer.
- To ensure secure log transmission, you must use the SASL_SSL connection protocol. The corresponding username is your TLS project ID, and the password is Volcanoengine account access key. For more details, see Code examples.
- If a log topic contains multiple shards, orderly consumption can not be guaranteed. We recommend uploading logs in load balancing mode.
Billing description
- Private network read traffic: When consuming log data via Kafka protocol to other Volcengine private network services, if both the log topic and the consumer are in the same region, you can use private transmission. This incurs a private network read traffic fee. For example, if source data is located in a log topic of the TLS Beijing region, and log data is consumed using Kafka to an ECS self-managed program, the corresponding private network traffic fee will be charged.
- Public network read traffic: When consuming log data via Kafka protocol to external programs on the public network, you must use public transmission. This generates public network read traffic. For example, if source data is in a TLS log topic and log data is consumed via Kafka to a self-developed program in a self-built IDC, public network read traffic will be generated.
Tip
If the source log topic and the consumer end are in different regions, you must use public network transmission, which incurs public network read traffic.
Prerequisites
- Log service has been enabled; a project and a topic are created; log data has been successfully collected. For more details, see Overview.
- Ensure that your current account has permission to enable log consumption via Kafka protocol, i.e., the permission of Action ConsumeLogs. For more details, see Authorized actions.
1 Enable Kafka consumption
Before using various tools to consume log data via Kafka protocol, you need to enable Kafka consumption for the specified log topic.
- Select the region where log service is located from the top navigation bar.
- On the left navigation bar, select Resource Management > Project .
- On the Project page, locate the specified project and click the project name.
- In the Log topic section, find the specified log topic in the log topic list.
- Click the Kafka protocol consumption switch in the log topic list.
- Click the log topic name and select ... > Configure log consumption.
- In the pop-up dialog box, enable Kafka consumption protocol configuration, and then click OK.
- After successfully enabling the Kafka protocol consumption feature, the details page of this log topic will display consumption parameters like username, hosts, topics. etc.
- You can enable the Kafka protocol consumption feature again after it has been disabled for 2 minutes.
2 Consume logs via Kafka protocol
Currently, TLS supports log consumption through the Kafka Java SDK or Kafka Connector plugins used with frameworks like Spark and Flink. You can refer to the following section to configure basic Kafka parameters and review sample code for log data consumption.
Tip
Kafka protocol consumption feature takes about 30 seconds to start. We recommend that you begin consuming logs 30 seconds after enabling the feature.
Parameters description
When consuming logs via the Kafka protocol, you need to configure the following parameters, parameter details or format can be found in the details page of log topic.
Error message
If uploading logs using Kafka protocol fails, error messages will be returned based on Kafka error code. For more information, see Kafka error list. Additionally, TLS encapsulates authentication and configuration-related error information in the Java Kafka error code SASLAuthenticationException, as described below:
Code examples
Consume logs with Kafka Java SDK
With simple parameter configuration, you can use various Kafka Consumer SDKs to consume data collected in TLS. The dependencies and sample code for consuming logs using the Kafka Java SDK are as follows:
- Add the relevant kafka-clients dependency in the pom file.
- Refer to the following sample code to consume logs using Kafka Java SDK.
Consume logs using the Kafka Go SDK.
With simple parameter configuration, you can use various Kafka Consumer SDKs to consume data collected in TLS. The dependencies and sample code for consuming logs using the Kafka Go SDK are as follows:
- Run the following command to install Sarama.
- Import the required dependencies such as Sarama, and consume logs.
- Refer to the following sample code to use the Kafka Go SDK for log consumption.
After consuming log data using the Kafka Java SDK or frameworks such as Spark, Flink, and the Kafka Connector plugin, you can view consumer group information in the TLS console.
- Select the region where log service is located from the top navigation bar.
- In the left navigation bar, select Data processing > Log consumption.
- On the Kafka tab, locate and expand the project linked to the target Kafka consumer group, and then click the specified Kafka consumer group.
- View consumption information for the target consumer group.
-
Reset consumption checkpoint.
Notice
Before resetting the consumption checkpoint, stop the corresponding consumer group’s process. Once the reset is complete, restart the relevant consumer process.
After consuming log data through Kafka Java SDK or Kafka Connector plugins for frameworks like Spark and Flink, you can reset the consumption checkpoint in the TLS console. You can also reset the consumption checkpoint to consume historical data.
- Select the region where log service is located from the top navigation bar.
- In the left navigation bar, select Data processing > Log consumption.
- On the Kafka tab, locate and expand the project linked to the target Kafka consumer group, and then click the specified Kafka consumer group.
- Reset consumption checkpoint.
- Click Reset consumption checkpoint in the upper right corner of the Log topic List tab, or click Reset consumption checkpoint in the Actions column for the specified shard.
- Select reset checkpoint.
View monitoring dashboard
After consuming log data via the Kafka Java SDK or frameworks such as Spark, Flink, and their Kafka Connector plugins, you can monitor the latency and speed trends of consumer groups in the log service console.
- Select the region where log service is located from the top navigation bar.
- In the left navigation bar, select Data processing > Log consumption.
- On the Kafka tab, locate and expand the project linked to the target Kafka consumer group, and then click the specified Kafka consumer group.
- On the Monitoring dashboard tab, view consumption-related dashboards.
- The monitoring dashboard displays consumption latency, consumption rate, and related trends for the Kafka consumer group. You can monitor Kafka protocol consumption backlog in real time through the dashboard. For specific operations, see Visualization of Kafka protocol consumption metrics.
-