Skip to content

Commit 55b52e0

Browse files
Fix Kafka version fallback for MSK clusters
Signed-off-by: srinivas chennupati <[email protected]>
1 parent 260f9e8 commit 55b52e0

2 files changed

Lines changed: 64 additions & 4 deletions

File tree

api/src/main/java/io/kafbat/ui/service/ReactiveAdminClient.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
@AllArgsConstructor
103103
public class ReactiveAdminClient implements Closeable {
104104
private static final String DEFAULT_UNKNOWN_VERSION = "Unknown";
105+
private static final String INTER_BROKER_PROTOCOL_VERSION_CONFIG = "inter.broker.protocol.version";
106+
private static final String LOG_MESSAGE_FORMAT_VERSION_CONFIG = "log.message.format.version";
105107

106108
public enum SupportedFeature {
107109
INCREMENTAL_ALTER_CONFIGS(2.3f),
@@ -164,12 +166,9 @@ private static Mono<ConfigRelatedInfo> extract(AdminClient ac) {
164166
.flatMap(tuple -> {
165167
List<ConfigEntry> configs = tuple.getT1();
166168
FeatureMetadata featureMetadata = tuple.getT2();
167-
Optional<String> version = Optional.empty();
169+
Optional<String> version = extractKafkaVersion(configs);
168170
boolean topicDeletionEnabled = true;
169171
for (ConfigEntry entry : configs) {
170-
if (entry.name().contains("inter.broker.protocol.version")) {
171-
version = Optional.ofNullable(entry.value());
172-
}
173172
if (entry.name().equals("delete.topic.enable") && entry.value() != null) {
174173
topicDeletionEnabled = Boolean.parseBoolean(entry.value());
175174
}
@@ -193,6 +192,21 @@ private static Mono<ConfigRelatedInfo> extract(AdminClient ac) {
193192
})
194193
.cache(UPDATE_DURATION);
195194
}
195+
196+
}
197+
198+
@VisibleForTesting
199+
static Optional<String> extractKafkaVersion(List<ConfigEntry> configs) {
200+
Optional<String> logMessageFormatVersion = Optional.empty();
201+
for (ConfigEntry entry : configs) {
202+
if (entry.name().equals(INTER_BROKER_PROTOCOL_VERSION_CONFIG) && entry.value() != null) {
203+
return Optional.of(entry.value());
204+
}
205+
if (entry.name().equals(LOG_MESSAGE_FORMAT_VERSION_CONFIG) && entry.value() != null) {
206+
logMessageFormatVersion = Optional.of(entry.value());
207+
}
208+
}
209+
return logMessageFormatVersion;
196210
}
197211

198212
public static Mono<ReactiveAdminClient> create(AdminClient adminClient, ClustersProperties.AdminClient properties) {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.kafbat.ui.service;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.List;
6+
import org.apache.kafka.clients.admin.ConfigEntry;
7+
import org.junit.jupiter.api.Test;
8+
9+
class ReactiveAdminClientVersionTest {
10+
11+
@Test
12+
void extractKafkaVersionUsesInterBrokerProtocolVersionFirst() {
13+
var configs = List.of(
14+
new ConfigEntry("log.message.format.version", "3.8-IV0"),
15+
new ConfigEntry("inter.broker.protocol.version", "3.9-IV0")
16+
);
17+
18+
assertThat(ReactiveAdminClient.extractKafkaVersion(configs)).contains("3.9-IV0");
19+
}
20+
21+
@Test
22+
void extractKafkaVersionFallsBackToLogMessageFormatVersion() {
23+
var configs = List.of(
24+
new ConfigEntry("log.message.format.version", "3.8-IV0")
25+
);
26+
27+
assertThat(ReactiveAdminClient.extractKafkaVersion(configs)).contains("3.8-IV0");
28+
}
29+
30+
@Test
31+
void extractKafkaVersionFallsBackWhenInterBrokerProtocolVersionIsNull() {
32+
var configs = List.of(
33+
new ConfigEntry("inter.broker.protocol.version", null),
34+
new ConfigEntry("log.message.format.version", "3.8-IV0")
35+
);
36+
37+
assertThat(ReactiveAdminClient.extractKafkaVersion(configs)).contains("3.8-IV0");
38+
}
39+
40+
@Test
41+
void extractKafkaVersionReturnsEmptyWhenVersionConfigsAreMissing() {
42+
var configs = List.of(new ConfigEntry("delete.topic.enable", "true"));
43+
44+
assertThat(ReactiveAdminClient.extractKafkaVersion(configs)).isEmpty();
45+
}
46+
}

0 commit comments

Comments
 (0)