xk6-kafka: ERRO[0002] Failed to get controller., OriginalError: %!w(*errors.errorString=&{EOF})

hi @mostafa i am trying to get username password for saslConfig from keyvault, i have added the saslConfig inside a method and called it from the setup method but it gives below error ERRO[0002] Failed to get controller., OriginalError: %!w(*errors.errorString=&{EOF}) error=“Failed to get controller., OriginalError: %!w(*errors.errorString=&{EOF})” ERRO[0002] GoError: Failed to get controller., OriginalError: %!w(*errors.errorString=&{EOF})

import { LoadJKS, TLS_1_2 } from "k6/x/kafka";
import {
    Writer,
    Reader,
    Connection,
    SchemaRegistry,
    SCHEMA_TYPE_JSON,
    SASL_SCRAM_SHA512,
    TOPIC_NAME_STRATEGY, KEY, VALUE
} from "k6/x/kafka";
import VaultManager from "./VaultManager.js";

let username;
let password;
let saslConfig={};
let offset = 0;
// partition and groupId are mutually exclusive
let partition = 0;
let numPartitions = 1;
let replicationFactor = 1;

export const options = {
    stages: [
      { target: 1, duration: '30s' },
      { target: 3, duration: '30s' },
      { target: 1, duration: '30s' }
    ],
  };

// Write your Vault access code in setup() - Called only Once
export function setup() {
    //This would be taken from environment in the future
    const acccesTokenToiPACE = 'Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
    const teamName = 'team';
    let vault = new VaultManager(acccesTokenToiPACE, teamName, 'DEV');
    console.log('Empty MAP = ' + vault.getJSONFromSecretMap());
    username = vault.getSecretFromVault("AZURE-USERNAME");
    console.log('username = ' + username);
    password = vault.getSecretFromVault("AZURE-PASWORD");
      console.log('password = ' + password)
    setSslConfig(username, password);
    return "abc";
  }

 function setSslConfig(username, password){
   saslConfig = {
          username: username,
          password: password,
          algorithm: SASL_SCRAM_SHA512
     };
   }

const jks = LoadJKS({
  path: "/truststore.jks",
  password: "password",
  clientCertAlias: "kafka",
  clientKeyAlias: "kafka",
  clientKeyPassword: "password",
  serverCaAlias: "root",
});

const tlsConfig = {
  enableTls: true,
  insecureSkipTlsVerify: true,
  minVersion: TLS_1_2,
  clientCertPem: jks["clientCertsPem"][0], // The first certificate in the chain
  clientKeyPem: jks["clientKeyPem"],
  serverCaPem: jks["serverCaPem"],
};

  const brokers = ["emp-digital.net:443"];
  const topic = "topic.internal.any.v1";

  const schemaRegistry = new SchemaRegistry();

  const writer = new Writer({
      brokers: brokers,
      topic: topic,
      sasl: saslConfig,
      partition: partition,
      tls: tlsConfig,
  });
  const reader = new Reader({
      brokers: brokers,
      topic: topic,
      partition: partition,
      offset: offset,
      sasl: saslConfig,
      tls: tlsConfig,
  });
  const connection = new Connection({
      address: brokers[0],
      sasl: saslConfig,
      tls: tlsConfig,
  });
//

export default function (data) {
 console.log('You get access to the data variable which contains your secrets in default = ' + data);
  // const obj = JSON.parse(data);

        let messages = [
            {
                key: schemaRegistry.serialize({
                    data: {
                        correlationId: "test-id-abc-" + 1,
                    },
                    schemaType: SCHEMA_TYPE_JSON,
                }),
                value: schemaRegistry.serialize({
                    data: {
                        templateId: 5,
                        testId: 4,
                        status: "deactive",
                        message: "Hi, i am testing",
                    },
                    schemaType: SCHEMA_TYPE_JSON,
                }),
            },
        ];
        writer.produce({ messages: messages });

    // console.log("---------_>>>>>",messages.length)
    let mesg = reader.consume({ limit: 10 });

        console.log("correlation=====>>>", schemaRegistry
        .deserialize({ data: mesg[0].key, schemaType: SCHEMA_TYPE_JSON })
        .correlationId);

        console.log("schema------>>>>>", schemaRegistry.deserialize({
        data: messages[0].value,
        schemaType: SCHEMA_TYPE_JSON,
        }));

}

export function teardown(data) {
    writer.close();
    reader.close();
    connection.close();
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

thanks for your help and extension! it actually worked this way. as i mentioned the issue was in import. other class was lazy initializing? new connect that was not used and was not given sasl config but was failing main test. hence connectLogger was not giving more info)

i tried logger, but output was not showing much. just error and code lines. i can attach output tomorrow. and i added tls conf after reading this thread, just set it to false.

thank you, Mostafa. i have seen these files. our kafka server requires jaas config.

when i test connection with performance tester.sh from kafka i can only send messages with saasl.jaas.config property provided in producer. same with offset explorer tool. it requires jaas config property.

in k6 i can create topic with my saslconfig, but when i need to produce messages i get eof error (i added sasl to Writer). i tried everything it seems. we use scram sha 512. on my local env same code sends messages just fine. but i have no sasl, no auth etc .

i will look at setting sasl on my local kafka and see when it will start failing)) i copied Writer from your examples, very simple, yet on Sasl scram sha 512 it throws eof errors 😦

I received the same error because I didn’t have TLS configuration set up. Just an FYI.