Repository: provectus/kafka-ui
Issue: Cannot Connect to IBM Event Streams
Labels: type/bug
scope/backend
status/accepted
status/confirmed

**Describe the bug**
I'm trying to connect to an IBM Event Streams instance (IBMs managed kafka) using kafka-ui.
I'm using docker compose to connect with this configuration:

```
---
version: '2'
services:

  kafka-ui:
    container_name: kafka-ui
    image: provectuslabs/kafka-ui:latest
    ports:
      - 8080:8080
    environment:
      KAFKA_CLUSTERS_0_NAME: sandbox
      KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: <multible brokers>
      KAFKA_CLUSTERS_0_PROPERTIES_SECURITY_PROTOCOL: SASL_SSL
      KAFKA_CLUSTERS_0_PROPERTIES_SASL_MECHANISM: PLAIN
      KAFKA_CLUSTERS_0_PROPERTIES_SASL_JAAS_CONFIG: 'org.apache.kafka.common.security.plain.PlainLoginModule required username="xxxxx" password="xxxxx";'
      KAFKA_CLUSTERS_0_SSL_PROTOCOL: TLSv1.2
```
I get the following error after the container starts:

```
 ERROR [parallel-5] c.p.k.u.u.NumberUtil: Conversion clusterVersion  to float value failed
kafka-ui  | 2022-08-18 10:20:13,209 ERROR [parallel-5] c.p.k.u.s.MetricsService: Failed to collect cluster sandbox info
kafka-ui  | java.lang.IllegalStateException: Error while creating AdminClient for Cluster sandbox
kafka-ui  |     at com.provectus.kafka.ui.service.AdminClientServiceImpl.lambda$createAdminClient$3(AdminClientServiceImpl.java:45)
kafka-ui  |     at reactor.core.publisher.Mono.lambda$onErrorMap$31(Mono.java:3733)
kafka-ui  |     at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:94)
kafka-ui  |     at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onError(FluxMapFuseable.java:140)
kafka-ui  |     at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:119)
kafka-ui  |     at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1816)
kafka-ui  |     at reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:249)
kafka-ui  |     at reactor.core.publisher.MonoPublishOn$PublishOnSubscriber.run(MonoPublishOn.java:181)
kafka-ui  |     at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
kafka-ui  |     at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
kafka-ui  |     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
kafka-ui  |     at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
kafka-ui  |     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
kafka-ui  |     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
kafka-ui  |     at java.base/java.lang.Thread.run(Thread.java:830)
kafka-ui  | Caused by: java.lang.NumberFormatException: empty String
kafka-ui  |     at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
kafka-ui  |     at java.base/jdk.internal.math.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
kafka-ui  |     at java.base/java.lang.Float.parseFloat(Float.java:461)
kafka-ui  |     at com.provectus.kafka.ui.util.NumberUtil.parserClusterVersion(NumberUtil.java:22)
kafka-ui  |     at com.provectus.kafka.ui.service.ReactiveAdminClient.getSupportedUpdateFeatureForVersion(ReactiveAdminClient.java:88)
kafka-ui  |     at com.provectus.kafka.ui.service.ReactiveAdminClient.lambda$create$0(ReactiveAdminClient.java:84)
kafka-ui  |     at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:113)
kafka-ui  |     ... 10 common frames omitted
```

I get the same error when trying to connect using a docker container. 
Any help is appreciated! 


Issue comments:
Hello there KyriacosP! 👋

Thank you and congratulations 🎉 for opening your very first issue in this project! 💖

In case you want to claim this issue, please comment down below! We will try to get back to you as soon as we can. 👀
Hi, thanks for reaching out. We'll look into this gladly, but, is this event streams publicly available for free? After a quick search I haven't found anything like a demo or a free tier thing. 
i don't think that they have a free tier, sorry. 

edit: sorry about that, they seem to have a free tier called lite plan but you need an ibm cloud account 
@KyriacosP seems like this platform returns an empty string instead of a proper version number. We're used to verify some of the features availability by kafka's cluster version, which is impossible in this case, I guess.

Please try this docker image with a workaround: `public.ecr.aws/provectus/kafka-ui-custom-build:2473`
Let me know how it goes.


This issue has been automatically marked as stale because no requested feedback has been provided. It will be closed if no further activity occurs. Thank you for your contributions.
@Haarolean Sorry for the late reply i have tested the image. It seems to work fine i still get the same error on startup but only in the logs, kafka-ui works fine after that. Thank you!
> @Haarolean Sorry for the late reply i have tested the image. It seems to work fine i still get the same error on startup but only in the logs, kafka-ui works fine after that. Thank you!

Glad to hear. That's intended, at least we know something went wrong. Let me know if you experience any other issue(-s) with event streams.
Do we have any time frame for when will this fix be released?
@KyriacosP you can pull `master`-labeled docker image :)
@Haarolean thank you!

Pull request review comments:
I would add NumberFormatException to throws cause here (even it is non checked)
I would catch NumberFormatException here instead of Exception
sure
okay done

Patch that resolved the issue:
diff --git a/kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/ReactiveAdminClient.java b/kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/ReactiveAdminClient.java
index 731824cdf08..85f0d17fb1e 100644
--- a/kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/ReactiveAdminClient.java
+++ b/kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/ReactiveAdminClient.java
@@ -90,10 +90,15 @@ public static Mono<ReactiveAdminClient> create(AdminClient adminClient) {
   }
 
   private static SupportedFeature getSupportedUpdateFeatureForVersion(String versionStr) {
-    float version = NumberUtil.parserClusterVersion(versionStr);
-    return version <= 2.3f
-        ? SupportedFeature.ALTER_CONFIGS
-        : SupportedFeature.INCREMENTAL_ALTER_CONFIGS;
+    try {
+      float version = NumberUtil.parserClusterVersion(versionStr);
+      return version <= 2.3f
+          ? SupportedFeature.ALTER_CONFIGS
+          : SupportedFeature.INCREMENTAL_ALTER_CONFIGS;
+    } catch (NumberFormatException e) {
+      log.info("Assuming non-incremental alter configs due to version parsing error");
+      return SupportedFeature.ALTER_CONFIGS;
+    }
   }
 
   //TODO: discuss - maybe we should map kafka-library's exceptions to our exceptions here
diff --git a/kafka-ui-api/src/main/java/com/provectus/kafka/ui/util/NumberUtil.java b/kafka-ui-api/src/main/java/com/provectus/kafka/ui/util/NumberUtil.java
index cb1f08b3ab1..9ea8c037cce 100644
--- a/kafka-ui-api/src/main/java/com/provectus/kafka/ui/util/NumberUtil.java
+++ b/kafka-ui-api/src/main/java/com/provectus/kafka/ui/util/NumberUtil.java
@@ -13,7 +13,8 @@ public static boolean isNumeric(Object value) {
     return value != null && NumberUtils.isCreatable(value.toString());
   }
 
-  public static float parserClusterVersion(String version) {
+  public static float parserClusterVersion(String version) throws NumberFormatException {
+    log.trace("Parsing cluster version [{}]", version);
     try {
       final String[] parts = version.split("\\.");
       if (parts.length > 2) {
@@ -21,7 +22,7 @@ public static float parserClusterVersion(String version) {
       }
       return Float.parseFloat(version.split("-")[0]);
     } catch (Exception e) {
-      log.error("Conversion clusterVersion {} to float value failed", version);
+      log.error("Conversion clusterVersion [{}] to float value failed", version, e);
       throw e;
     }
   }


Test patch: