Skip to content

Commit 1611e01

Browse files
fix: collect KafkaTopicSample on Kafka 4.x (DescribeConfigs version)
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>
1 parent ea9a04d commit 1611e01

5 files changed

Lines changed: 31 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## Unreleased
99

10+
### 🐛 Bug fixes
11+
- Fixed missing `KafkaTopicSample` data on Kafka 4.x. The integration sent `DescribeConfigs` requests at API version 0, which Kafka 4.0 removed (the broker minimum is now v1), causing topic configuration collection to fail and the topic samples to be dropped entirely. The request version is now derived from the configured `KAFKA_VERSION` (v2/v1/v0), and the default `KAFKA_VERSION` was raised from `1.0.0` to `2.1.0` so topic and broker configuration collection works against Kafka 4.x out of the box.
12+
1013
## v3.20.0 - 2026-06-17
1114

1215
### 🛡️ Security notices

src/args/args.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type ArgumentList struct {
1111
sdkArgs.DefaultArgumentList
1212
ClusterName string `default:"" help:"A user-defined name to uniquely identify the cluster"`
13-
KafkaVersion string `default:"1.0.0" help:"What version of the API to use for connecting to Kafka. Versions older than 1.0.0 may be missing some features."`
13+
KafkaVersion string `default:"2.1.0" help:"What version of the API to use for connecting to Kafka. Defaults to 2.1.0. Set this to match your cluster's version. Kafka 4.x requires at least 2.0.0 for topic and broker configuration collection (DescribeConfigs v0 was removed). Versions older than 1.0.0 may be missing some features."`
1414

1515
AutodiscoverStrategy string `default:"zookeeper" help:"How to discover broker nodes to collect metrics from. One of 'zookeeper' (default) or 'bootstrap'"`
1616

src/args/args_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestDefaultArgs(t *testing.T) {
126126
CacheTTL: persist.DefaultTTL,
127127
},
128128
AutodiscoverStrategy: "zookeeper",
129-
KafkaVersion: sarama.V1_0_0_0,
129+
KafkaVersion: sarama.V2_1_0_0,
130130
ZookeeperHosts: []*ZookeeperHost{
131131
{
132132
Host: "localhost",

src/broker/broker_collection.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,20 @@ func collectBrokerTopicMetrics(b *connection.Broker, collectedTopics []string, i
191191
// Collect broker configuration from Zookeeper
192192
func getBrokerConfig(broker *connection.Broker) ([]*sarama.ConfigEntry, error) {
193193

194+
// DescribeConfigs v0 was removed in Kafka 4.0 (the broker's minimum supported
195+
// version is now v1). Derive the request version from the negotiated Kafka
196+
// version so we remain compatible with both older brokers and Kafka 4.x.
197+
// sarama v1.43.x supports DescribeConfigs up to v2.
198+
descVer := int16(0)
199+
switch {
200+
case args.GlobalArgs.KafkaVersion.IsAtLeast(sarama.V2_0_0_0):
201+
descVer = 2
202+
case args.GlobalArgs.KafkaVersion.IsAtLeast(sarama.V1_1_0_0):
203+
descVer = 1
204+
}
194205
configRequest := &sarama.DescribeConfigsRequest{
195-
Version: 0,
196-
IncludeSynonyms: true,
206+
Version: descVer,
207+
IncludeSynonyms: descVer >= 1,
197208
Resources: []*sarama.ConfigResource{
198209
{
199210
Type: sarama.BrokerResource,

src/topic/topic_collection.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,20 @@ func topicRespondsToMetadata(t *Topic, client connection.Client) int {
206206

207207
// Collect and populate the remainder of the topic struct fields
208208
func setTopicInfo(t *Topic, client connection.Client) error {
209+
// DescribeConfigs v0 was removed in Kafka 4.0 (the broker's minimum supported
210+
// version is now v1). Derive the request version from the negotiated Kafka
211+
// version so we remain compatible with both older brokers and Kafka 4.x.
212+
// sarama v1.43.x supports DescribeConfigs up to v2.
213+
descVer := int16(0)
214+
switch {
215+
case args.GlobalArgs.KafkaVersion.IsAtLeast(sarama.V2_0_0_0):
216+
descVer = 2
217+
case args.GlobalArgs.KafkaVersion.IsAtLeast(sarama.V1_1_0_0):
218+
descVer = 1
219+
}
209220
configRequest := &sarama.DescribeConfigsRequest{
210-
Version: 0,
211-
IncludeSynonyms: true,
221+
Version: descVer,
222+
IncludeSynonyms: descVer >= 1,
212223
Resources: []*sarama.ConfigResource{
213224
{
214225
Type: sarama.TopicResource,

0 commit comments

Comments
 (0)