Skip to content

fix: collect KafkaTopicSample on Kafka 4.x (DescribeConfigs version)#375

Merged
shashank-reddy-nr merged 1 commit into
masterfrom
fix/kafka-4x-describeconfigs-version
Jun 23, 2026
Merged

fix: collect KafkaTopicSample on Kafka 4.x (DescribeConfigs version)#375
shashank-reddy-nr merged 1 commit into
masterfrom
fix/kafka-4x-describeconfigs-version

Conversation

@shashank-reddy-nr

Copy link
Copy Markdown
Contributor

Summary

KafkaTopicSample is missing on Kafka 4.x clusters while KafkaBrokerSample, KafkaProducerSample, KafkaConsumerSample, and KafkaOffsetSample continue to report.

Root Cause: The integration issues DescribeConfigs requests at API version 0, which Kafka 4.0 removed (the broker's minimum supported version is now v1, per KIP-896). The v0 request is rejected by the broker, setTopicInfo() returns an error, and topicWorker() continues before the topic metric set is created — so the topic sample is dropped entirely. Broker/producer/consumer/offset samples are JMX- or higher-level-API-based, so they remain unaffected.

This was reproduced and verified on a real Kafka 3.8.1 (works) vs 4.0.0 (topic samples missing) cluster, confirmed both via the integration's -pretty output and in NRDB.


Changes

  • src/topic/topic_collection.go, src/broker/broker_collection.go: Derive the DescribeConfigs request version from the negotiated KAFKA_VERSION instead of hardcoding 0.
    • Logic: >= 2.0.0v2, >= 1.1.0v1, else v0. (Sarama v1.43.x supports DescribeConfigs up to v2; Kafka 4.0 supports 1–4). IncludeSynonyms is now set only when the version supports it (>= 1).
  • src/args/args.go: Raise the default KAFKA_VERSION from 1.0.0 to 2.1.0. This ensures topic/broker config collection works against Kafka 4.x out of the box without requiring manual user configuration.
  • src/args/args_test.go: Updated TestDefaultArgs expectation to match the new default.
  • CHANGELOG.md: Added unreleased bug-fix entry.

Why both changes are needed

Sarama refuses to send a request whose requiredVersion() exceeds config.Version (within broker.go). Simply fixing the hardcoded version is insufficient; with the old 1.0.0 default, a v2 (or even v1) request is rejected client-side. Bumping the default ensures functionality for Kafka 4.x users without forcing manual configuration changes. Deriving the version (rather than hardcoding v2) ensures we do not regress support for genuinely older brokers.


Testing

  • Unit Tests: go test ./src/... passes.
  • Manual/Agent Testing: Ran against a live single-node KRaft cluster:
    • Kafka 3.8.1: All sample types present (baseline, unchanged).
    • Kafka 4.0.0 (Before): KafkaTopicSample = 0, DescribeConfigs errors.
    • Kafka 4.0.0 (After, no KAFKA_VERSION set): KafkaTopicSample present for all topics, 0 DescribeConfigs errors; confirmed in NRDB.

Compatibility / Notes

  • No behavior change for Kafka < 4.0 except the higher default protocol version (2.1.0), which negotiates down per-API via ApiVersions.
  • Future Considerations: Upgrade Sarama to a release that natively supports Kafka 4.x (DescribeConfigs v4 / flexible versions), and improve error handling to make a malformed KAFKA_VERSION non-fatal (falling back to default instead of aborting the whole run).

@shashank-reddy-nr shashank-reddy-nr requested a review from a team as a code owner June 17, 2026 15:11
Kafka 4.0 removed DescribeConfigs API v0 (the broker minimum is now v1),
so the hardcoded v0 request used for topic and broker configuration
collection failed against 4.x brokers. As a result KafkaTopicSample was
dropped entirely, while KafkaBrokerSample/KafkaProducerSample/
KafkaConsumerSample/KafkaOffsetSample (JMX- and other-API-based) kept
working - matching the reported "topic samples missing on Kafka 4.x".

Derive the DescribeConfigs request version from the negotiated
KAFKA_VERSION (v2 if >= 2.0.0, v1 if >= 1.1.0, else v0; sarama v1.43.x
supports DescribeConfigs up to v2), and raise the default KAFKA_VERSION
from 1.0.0 to 2.1.0 so topic and broker configuration collection works
against Kafka 4.x out of the box with no user configuration.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shashank-reddy-nr shashank-reddy-nr force-pushed the fix/kafka-4x-describeconfigs-version branch from 1611e01 to 2f4e7d2 Compare June 17, 2026 15:21

@abhishuraina abhishuraina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, make sure you've tested it on kafka V4

@shashank-reddy-nr shashank-reddy-nr merged commit 90b7e64 into master Jun 23, 2026
15 of 16 checks passed
@shashank-reddy-nr shashank-reddy-nr deleted the fix/kafka-4x-describeconfigs-version branch June 23, 2026 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants