Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Kafka 3.8 #1093

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ micronaut-docs = "2.0.0"
micronaut-gradle-plugin = "4.4.3"

# Required to keep catalog compatibility with 3.4.x. Can be removed for 4.0.0
managed-kafka-compat = "3.8.0"
managed-kafka = '3.7.0'
managed-kafka = '3.8.0'

groovy = "4.0.15"

Expand All @@ -29,9 +28,6 @@ micronaut-test-resources="2.6.2"
# Core
micronaut-core = { module = 'io.micronaut:micronaut-core-bom', version.ref = 'micronaut' }

# Duplicated to keep catalog compatibility with 3.4.x. Can be removed for 4.0.0
managed-kafka = { module = 'org.apache.kafka:kafka-clients', version.ref = 'managed-kafka-compat' }

managed-kafka-clients = { module = 'org.apache.kafka:kafka-clients', version.ref = 'managed-kafka' }
managed-kafka-streams = { module = 'org.apache.kafka:kafka-streams', version.ref = 'managed-kafka' }

Expand Down
4 changes: 4 additions & 0 deletions kafka-bom/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ plugins {
micronautBom {
// exclude example projects
extraExcludedProjects.add("tasks-sasl-plaintext")
suppressions {
acceptedLibraryRegressions.add("kafka")
acceptedVersionRegressions.add("kafka-compat")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import jdk.jfr.Experimental;
import org.apache.kafka.clients.ApiVersions;
import org.apache.kafka.clients.Metadata;
import org.apache.kafka.clients.MetadataRecoveryStrategy;
import org.apache.kafka.clients.NetworkClient;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.common.ClusterResourceListener;
Expand Down Expand Up @@ -88,10 +89,24 @@ public NetworkClient create(@NonNull ClusterResourceListener... listeners) {
metrics = metrics();
channelBuilder = createChannelBuilder(config, SYSTEM, logContext);
selector = selector(metrics, channelBuilder);
return new NetworkClient(selector, metadata(listeners), clientId, 1,
reconnectBackoff, reconnectBackoffMax, socketSendBuffer, socketReceiveBuffer,
(int) HOURS.toMillis(1), connectionSetupTimeout, connectionSetupTimeoutMax,
SYSTEM, true, new ApiVersions(), logContext);
return new NetworkClient(
selector,
metadata(listeners),
clientId,
1,
reconnectBackoff,
reconnectBackoffMax,
socketSendBuffer,
socketReceiveBuffer,
(int) HOURS.toMillis(1),
connectionSetupTimeout,
connectionSetupTimeoutMax,
SYSTEM,
true,
new ApiVersions(),
logContext,
MetadataRecoveryStrategy.NONE
);
} catch (Throwable e) {
closeQuietly(metrics, "Metrics");
closeQuietly(selector, "Selector");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.micronaut.management.health.indicator.HealthResult;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import org.apache.kafka.clients.LeastLoadedNode;
import org.apache.kafka.clients.NetworkClient;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.Config;
Expand Down Expand Up @@ -225,9 +226,9 @@ private Optional<HealthResult> hasReadyNodes(NetworkClient networkClient) {

private HealthResult waitForLeastLoadedNode(NetworkClient networkClient) {
final long requestTimeoutMs = defaultConfiguration.getHealthTimeout().toMillis();
final Node node = networkClient.leastLoadedNode(SYSTEM.milliseconds());
final LeastLoadedNode leastLoadedNode = networkClient.leastLoadedNode(SYSTEM.milliseconds());
try {
return result(awaitReady(networkClient, node, SYSTEM, requestTimeoutMs), null).build();
return result(awaitReady(networkClient, leastLoadedNode.node(), SYSTEM, requestTimeoutMs), null).build();
} catch (IOException e) {
return failure(e, Collections.emptyMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class KafkaConfigurationSpec extends Specification {

then: "the new consumer's deserializers have the configured encoding"
consumer != null
(consumer.delegate.deserializers.keyDeserializer as StringDeserializer).encoding == StandardCharsets.US_ASCII.name()
(consumer.delegate.deserializers.valueDeserializer as StringDeserializer).encoding == StandardCharsets.ISO_8859_1.name()
(consumer.delegate.deserializers.keyDeserializer as StringDeserializer).encoding.name() == StandardCharsets.US_ASCII.name()
(consumer.delegate.deserializers.valueDeserializer as StringDeserializer).encoding.name() == StandardCharsets.ISO_8859_1.name()

cleanup:
consumer.close()
Expand All @@ -103,8 +103,8 @@ class KafkaConfigurationSpec extends Specification {

then: "the new producer's serializers have the configured encoding"
producer != null
(producer.keySerializer as StringSerializer).encoding == StandardCharsets.US_ASCII.name()
(producer.valueSerializer as StringSerializer).encoding == StandardCharsets.ISO_8859_1.name()
(producer.keySerializer as StringSerializer).encoding.name() == StandardCharsets.US_ASCII.name()
(producer.valueSerializer as StringSerializer).encoding.name() == StandardCharsets.ISO_8859_1.name()

cleanup:
producer.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class KafkaTypeConversionSpec extends AbstractKafkaContainerSpec {
myConsumer.lastException != null
myConsumer.lastException.cause instanceof SerializationException
myConsumer.lastException.cause.printStackTrace()
myConsumer.lastException.cause.message.contains("deserializing key/value for partition")
myConsumer.lastException.cause.message.contains("Error deserializing KEY for partition")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class KafkaBatchErrorStrategySpec extends AbstractEmbeddedServerSpec {

and: "The retry error strategy was honored"
myConsumer.exceptions.size() == 2
myConsumer.exceptions[0].message.startsWith('Error deserializing key/value')
myConsumer.exceptions[0].message.startsWith('Error deserializing VALUE')
(myConsumer.exceptions[0].cause as RecordDeserializationException).offset() == 3
myConsumer.exceptions[1].message.startsWith('Error deserializing key/value')
myConsumer.exceptions[1].message.startsWith('Error deserializing VALUE')
(myConsumer.exceptions[1].cause as RecordDeserializationException).offset() == 3
}

Expand All @@ -124,17 +124,15 @@ class KafkaBatchErrorStrategySpec extends AbstractEmbeddedServerSpec {
conditions.eventually {
myConsumer.received == ['111/222', '333', '444/555']
myConsumer.successful == ['111/222', '333', '444/555']
myConsumer.skippedOffsets == [4L]
myConsumer.skippedOffsets.contains(4L)
}

and: "The retry error strategy was honored"
myConsumer.exceptions.size() == 3
myConsumer.exceptions[0].message.startsWith('Error deserializing key/value')
myConsumer.exceptions.size() == 2
myConsumer.exceptions[0].message.startsWith('Error deserializing VALUE')
(myConsumer.exceptions[0].cause as RecordDeserializationException).offset() == 2
myConsumer.exceptions[1].message.startsWith('Error deserializing key/value')
(myConsumer.exceptions[1].cause as RecordDeserializationException).offset() == 2
myConsumer.exceptions[2].message.startsWith('Error deserializing key/value')
(myConsumer.exceptions[2].cause as RecordDeserializationException).offset() == 4
myConsumer.exceptions[1].message.startsWith('Error deserializing VALUE')
(myConsumer.exceptions[1].cause as RecordDeserializationException).offset() == 4
}

void "test batch mode with 'retry exp' error strategy"() {
Expand Down Expand Up @@ -342,7 +340,7 @@ class KafkaBatchErrorStrategySpec extends AbstractEmbeddedServerSpec {

@Override
ConditionalRetryBehaviour conditionalRetryBehaviour(KafkaListenerException exception) {
if(exception.getMessage() == "Error deserializing key/value for partition batch-mode-retry-conditionally-deser-0 at offset 4. If needed, please seek past the record to continue consumption.") {
if(exception.message.concat("at offset 4")) {
skippedOffsets << 4L
return ConditionalRetryBehaviour.SKIP
} else {
Expand Down
Loading