Skip to content

feat: add ENV to control Kafka sdk log level #21865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2025
Merged

feat: add ENV to control Kafka sdk log level #21865

merged 2 commits into from
May 28, 2025

Conversation

tabVersion
Copy link
Contributor

@tabVersion tabVersion commented May 14, 2025

  • Introduced a new function read_kafka_log_level to read the log level from the environment variable RISINGWAVE_KAFKA_LOG_LEVEL.
  • Updated KafkaConnection, KafkaSinkWriter, and KafkaSplitReader to utilize the dynamic log level configuration.
  • Ensured that an invalid log level falls back to the default level of INFO with a warning log.

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

proposed by @arkbriar

introduce RISINGWAVE_KAFKA_LOG_LEVEL to control the log level of kafka sdk

accept

DEBUG
INFO
WARN
ERROR
CRITICAL
EMERG
ALERT
NOTICE

What's changed and what's your intention?

Checklist

  • I have written necessary rustdoc comments.
  • I have added necessary unit tests and integration tests.
  • I have added test labels as necessary.
  • I have added fuzzing tests or opened an issue to track them.
  • My PR contains breaking changes.
  • My PR changes performance-critical code, so I will run (micro) benchmarks and present the results.
  • I have checked the Release Timeline and Currently Supported Versions to determine which release branches I need to cherry-pick this PR into.

Documentation

  • My PR needs documentation updates.
Release note

- Introduced a new function `read_kafka_log_level` to read the log level from the environment variable `RISINGWAVE_KAFKA_LOG_LEVEL`.
- Updated `KafkaConnection`, `KafkaSinkWriter`, and `KafkaSplitReader` to utilize the dynamic log level configuration.
- Ensured that an invalid log level falls back to the default level of INFO with a warning log.
@tabVersion tabVersion requested review from arkbriar, xxchan and Copilot May 14, 2025 08:05
@github-actions github-actions bot added the type/feature Type: New feature. label May 14, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces dynamic control of the Kafka SDK log level via the new environment variable RISINGWAVE_KAFKA_LOG_LEVEL.

  • Introduces the function read_kafka_log_level to read and parse the log level from the environment.
  • Updates multiple Kafka-related modules (consumer, sink writer, and enumerator) to use the dynamic log level configuration.
  • Adjusts module exports to incorporate the new log level reader for better configurability.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/connector/src/source/kafka/source/reader.rs Updated consumer initialization to use dynamic log level.
src/connector/src/source/kafka/enumerator.rs Configured enumerator with dynamic log level.
src/connector/src/sink/kafka.rs Updated sink writer to set dynamic log level.
src/connector/src/connector_common/mod.rs Added export for the read_kafka_log_level function.
src/connector/src/connector_common/connection.rs New function read_kafka_log_level reading environment variable and falling back to INFO.
Comments suppressed due to low confidence (1)

src/connector/src/connector_common/connection.rs:116

  • The PR description specifies that an invalid log level should fall back to INFO with a warning log; consider using 'tracing::warn!' here instead of 'tracing::info!' to accurately reflect the intended log severity.
tracing::info!("Invalid RISINGWAVE_KAFKA_LOG_LEVEL: {}, using INFO instead", log_level);

Copy link
Contributor

@arkbriar arkbriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@@ -477,7 +477,9 @@ impl KafkaSinkWriter {
.await?;
let producer_ctx = RwProducerContext::new(ctx_common);
// Generate the producer
c.create_with_context(producer_ctx).await?
c.set_log_level(read_kafka_log_level())
Copy link
Member

@xxchan xxchan May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can set sth like RUST_LOG="librdkafka=trace", why need a separate env var? 👀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@tabVersion tabVersion mentioned this pull request May 14, 2025
8 tasks
- Modified `read_kafka_log_level` to return an `Option<RDKafkaLogLevel>` instead of a direct value.
- Updated all instances in `KafkaConnection`, `KafkaSinkWriter`, `KafkaSplitReader`, and `KafkaSplitEnumerator` to handle the new return type, ensuring log level is set only if valid.
- Improved error handling by returning `None` for invalid log levels instead of defaulting to INFO.
@tabVersion tabVersion enabled auto-merge May 27, 2025 23:26
@tabVersion tabVersion added this pull request to the merge queue May 27, 2025
Merged via the queue into main with commit 89b778e May 28, 2025
28 of 29 checks passed
@tabVersion tabVersion deleted the tab/bualbula branch May 28, 2025 00:36
xxhZs pushed a commit that referenced this pull request May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature Type: New feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants