mostafa/xk6-kafka

ERRO[0002] Failed to get controller., OriginalError: %!w(*errors.errorString=&{multiple Read calls return no data or error})

arpitaso opened this issue · 3 comments

@mostafa

Below is my script. I am trying to establish a jks connection and trying to produce message to a kafka topic. But i get the below error.
PFA script and error
Can you please help here?

import { check } from "k6";
import {
Writer,
Reader,
Connection,
SchemaRegistry,
CODEC_SNAPPY,
SCHEMA_TYPE_JSON,
} from "k6/x/kafka";

import { LoadJKS, TLS_1_2 } from "k6/x/kafka";
const jks = LoadJKS({
path: "/Users/arpita.sood/Documents/k6-code/src/resources/truststore.jks",
password: "abc",
clientCertAlias: "kafka",
clientKeyAlias: "kafka",
clientKeyPassword: "abc",
serverCaAlias: "root",
});

const tlsConfig = {
enableTls: true,
insecureSkipTlsVerify: false,
minVersion: TLS_1_2,
clientCertPem: jks["clientCertsPem"][0],
clientKeyPem: jks["clientKeyPem"],
serverCaPem: jks["serverCaPem"],
};

const brokers = ["broker:443"];
const topic = "dev.topic";

const writer = new Writer({
brokers: brokers,
tlsConfig,
topic: topic,
autoCreateTopic: true,
compression: CODEC_SNAPPY,
});

const reader = new Reader({
brokers: brokers,
tlsConfig,
topic: topic,
});

const connection = new Connection({
address: brokers[0],
tlsConfig,
});

const schemaRegistry = new SchemaRegistry();

if (__VU == 0) {
connection.createTopic({
topic: topic,
configEntries: [
{
configName: "compression.type",
configValue: CODEC_SNAPPY,
},
],
});
}

export const options = {
thresholds: {
kafka_writer_error_count: ["count == 0"],
kafka_reader_error_count: ["count == 0"],
},
};

function getRandomInt(min, max) {
return min + Math.floor(Math.random() * (max - min + 1));
}

export default function () {
let messages = [
{
key: schemaRegistry.serialize({
data: {
correlationId: "test-id-abc-" + getRandomInt(10, 100),
},
schemaType: SCHEMA_TYPE_JSON,
}),
value: schemaRegistry.serialize({
data: {
menu: {
version: "test_1",
author: "test_2",
description: "test_3",
}

    },
    schemaType: SCHEMA_TYPE_JSON,
  })

}

];

writer.produce({ messages: messages });

messages = reader.consume({});

}

export function teardown(data) {
console.log(Object.keys(jks));
console.log(jks);
console.log(tlsConfig);

writer.close();
reader.close();
connection.close();
}

error

ERRO[0002] Failed to get controller., OriginalError: %!w(*errors.errorString=&{multiple Read calls return no data or error}) error="Failed to get controller., OriginalError: %!w(*errors.errorString=&{multiple Read calls return no data or error})"
ERRO[0002] GoError: Failed to get controller., OriginalError: %!w(*errors.errorString=&{multiple Read calls return no data or error})
at file:///Users/arpita.sood/Documents/k6-code/src/scripts/dev-test-script.js:211:19(111) hint="script exception"

@mostafa can you please help here.?
Thanks

@arpitaso
Is this fixed? Or do you still have the issue?

@arpitaso

I suppose this is resolved. Feel free to reopen it if the issue persists.