Skip to content

Commit

Permalink
Debugging for failed kafka containers
Browse files Browse the repository at this point in the history
Adds detailed output and hopefully fixes this error:
quarkus-qe#1186
  • Loading branch information
fedinskiy committed Jul 8, 2024
1 parent a59592f commit 70dfa22
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<oracle.image>docker.io/gvenzl/oracle-free:23-slim-faststart</oracle.image>
<postgresql.image>docker.io/postgres:16.1</postgresql.image>
<mysql.image>docker.io/mysql:8.3.0</mysql.image>
<strimzi.testcontainers.version>0.106.0</strimzi.testcontainers.version>
<infinispan.image>docker.io/infinispan/server:14.0</infinispan.image>
<infinispan-legacy.image>docker.io/infinispan/server:13.0</infinispan-legacy.image>
<!-- TODO use official image if this fixed https://github.com/hashicorp/docker-consul/issues/184 -->
Expand Down Expand Up @@ -91,6 +92,22 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<!-- The import above brings older version of this dependency, so we need to override it manually -->
<groupId>io.strimzi</groupId>
<artifactId>strimzi-test-container</artifactId>
<version>${strimzi.testcontainers.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus.qe</groupId>
<artifactId>quarkus-test-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.quarkus.test.bootstrap.ManagedResource;
import io.quarkus.test.bootstrap.Protocol;
import io.quarkus.test.bootstrap.ServiceContext;
import io.quarkus.test.logging.Log;
import io.quarkus.test.logging.LoggingHandler;
import io.quarkus.test.logging.TestContainersLoggingHandler;
import io.quarkus.test.services.URILike;
Expand Down Expand Up @@ -121,7 +122,7 @@ private void doStart() {
innerContainer.start();
} catch (Exception ex) {
stop();

loggingHandler.logs().forEach(Log::info);
throw ex;
}
}
Expand Down
12 changes: 0 additions & 12 deletions quarkus-test-service-kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<artifactId>quarkus-test-service-kafka</artifactId>
<name>Quarkus - Test Framework - Service - Kafka</name>
<properties>
<strimzi.testcontainers.version>0.106.0</strimzi.testcontainers.version>
<log4j.version>2.23.1</log4j.version>
</properties>
<dependencies>
Expand All @@ -24,17 +23,6 @@
<dependency>
<groupId>io.strimzi</groupId>
<artifactId>strimzi-test-container</artifactId>
<version>${strimzi.testcontainers.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.github.dockerjava.api.command.InspectContainerResponse;

import io.quarkus.test.logging.Log;
import io.quarkus.test.services.containers.model.KafkaVendor;
import io.smallrye.mutiny.tuples.Tuple2;
import io.strimzi.test.container.StrimziKafkaContainer;
Expand Down Expand Up @@ -36,15 +37,17 @@ public void useCustomServerProperties() {
@Override
protected void containerIsStarting(InspectContainerResponse containerInfo, boolean reused) {
if (useCustomServerProperties) {
Log.info("Starting container using custom server properties");
List<String> script = new ArrayList<>();
script.add("#!/bin/bash");
script.add("set -euv");
int kafkaExposedPort = this.getMappedPort(KafkaVendor.STRIMZI.getPort());
script.add("sed 's/" + KAFKA_MAPPED_PORT + "/" + kafkaExposedPort + "/g' "
+ "config/kraft/server.properties > /tmp/effective_server.properties");
script.add("KAFKA_CLUSTER_ID=\"$(bin/kafka-storage.sh random-uuid)\"");
StringBuilder storageFormat = new StringBuilder()
.append("/opt/kafka/bin/kafka-storage.sh format")
.append(" -t ${KAFKA_CLUSTER_ID}")
.append(" -t=${KAFKA_CLUSTER_ID}")
.append(" -c /tmp/effective_server.properties");
credentials.ifPresent(credentials -> {
storageFormat.append(" --add-scram 'SCRAM-SHA-512=[name=%s,password=%s]'"
Expand All @@ -57,6 +60,7 @@ protected void containerIsStarting(InspectContainerResponse containerInfo, boole
// we do not process credentials here, since SASL always used together with custom properties
// see StrimziKafkaContainerManagedResource#getServerProperties
super.containerIsStarting(containerInfo, reused);
Log.info("Starting container using standard server properties and cluster id " + super.getClusterId());
// if that is to change, we will need to copy script from test containers, modify it and copy back again
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ items:
data:
start.sh: |-
#!/bin/bash
set -euv
KAFKA_CLUSTER_ID="$(/opt/kafka/bin/kafka-storage.sh random-uuid)"
/opt/kafka/bin/kafka-storage.sh format -t ${KAFKA_CLUSTER_ID} -c config/kraft/server.properties
/opt/kafka/bin/kafka-storage.sh format -t=${KAFKA_CLUSTER_ID} -c config/kraft/server.properties
/opt/kafka/bin/kafka-server-start.sh config/kraft/server.properties --override listeners=PLAINTEXT://0.0.0.0:${KAFKA_PORT},CONTROLLER://localhost:9093 --override advertised.listeners=PLAINTEXT://${SERVICE_NAME}:${KAFKA_PORT}
- apiVersion: "apps/v1"
kind: "Deployment"
Expand Down

0 comments on commit 70dfa22

Please sign in to comment.