mostafa / xk6-kafka

k6 extension to load test Apache Kafka with support for various serialization formats, SASL, TLS, compression, Schema Registry client and beyond
Apache License 2.0
154 stars 69 forks source link

Issue with Topic Creation Using ReplicaAssignments in xk6-kafka #310

Open vereshchagin-d opened 5 hours ago

vereshchagin-d commented 5 hours ago

Hi!

Environment:

Description: I'm encountering an issue when trying to create a topic with replicaAssignments. Below is the code snippet used:

connection.createTopic({
  topic: "my-topic", 
  numPartitions: -1, // Also tried declaring only `topic` and `replicaAssignments`
  replicationFactor: -1, //
  replicaAssignments: [{partition: 0, replicas: [0,1,2]}]
});

The error message I receive is:

time="2024-11-22T11:23:47Z" level=error msg="Failed to create topic., OriginalError: [42] Invalid Request: this most likely occurs because of a request being malformed by the client library or the message was sent to an incompatible broker, se the broker logs for more details" error="Failed to create topic., OriginalError: [42] Invalid Request: this most likely occurs because of a request being malformed by the client library or the message was sent to an incompatible broker, se the broker logs for more details"

Observations: Upon checking the code, I noticed that in this section of the source code, default values for NumPartitions and ReplicationFactor are set to 1 if they are <= 0.

        if topicConfig.NumPartitions <= 0 {
        topicConfig.NumPartitions = 1
    }

    if topicConfig.ReplicationFactor <= 0 {
        topicConfig.ReplicationFactor = 1
    }

This behavior seems incorrect when using replicaAssignments since NumPartitions and ReplicationFactor should be inferred from the replicaAssignments field according to the Kafka protocol.

References:

Suggested Fix: The library should allow NumPartitions and ReplicationFactor to remain unset or explicitly -1 when replicaAssignments is provided. This would align the behavior with Kafka’s protocol and similar libraries.

vereshchagin-d commented 5 hours ago

Hi @mostafa,

Thank you for your work on the xk6-kafka project—it’s been incredibly useful for our Kafka-related testing needs.

I’ve encountered an issue when trying to create a topic with replicaAssignments and have provided a detailed report [above/in this issue]. It seems like the library sets default values for NumPartitions and ReplicationFactor even when replicaAssignments is provided, which contradicts Kafka’s protocol.

Would you be able to take a look when you have time? I’ve included links to relevant Kafka documentation and test cases from kafka-go library to help clarify the context.

Let me know if there’s any additional information I can provide or steps I can take to assist. Thanks again for maintaining this project!

Best regards, Dmitriy

mostafa commented 4 hours ago

Hey @vereshchagin-d,

Looks like a bug. Would you please create a PR to fix this?