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

invalid character 'd' after top-level value 3 #237

Open
arpitaso opened this issue Jul 16, 2023 · 3 comments
Open

invalid character 'd' after top-level value 3 #237

arpitaso opened this issue Jul 16, 2023 · 3 comments

Comments

@arpitaso
Copy link

@mostafa

Below is my script, while logging the

 console.log("correlation------>>>>>", schemaRegistry.deserialize({
           data: messages[0].key,
           schemaType: SCHEMA_TYPE_JSON,
           }));
       it gives below error
       ERRO[0015] GoError: Failed to unmarshal JSON data, OriginalError: %!w(*json.SyntaxError=&{invalid character 'd' after top-level value 3})

running at github.com/mostafa/xk6-kafka.(*Kafka).schemaRegistryClientClass.func5 (native)
default at file:////dev-test.js:134:68(135) executor=shared-iterations scenario=default source=stacktrace

Below is the full script



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

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

export const vault = new VaultManager('Dev', 'DEV');

let offset = -1;
// partition and groupId are mutually exclusive
let partition = 0;
let numPartitions = 1;
let replicationFactor = 1;

let username = "";
let password = "";
let passwordToAccessTrustore = "";
let saslConfig = {};

let writer;
let reader;
let connection;


export function setup() {
    console.log('Inside setup function ');
    username = vault.getSecretFromVault("USERNAME");
    password = vault.getSecretFromVault("PASSWORD");
}

export function initializeCredentials() {
    console.log('Inside initializeCredentials function');
    if (!username || !password) {
      username = vault.getSecretFromVault("USERNAME");
    password = vault.getSecretFromVault("PASSWORD");
        passwordToAccessTrustore = vault.getSecretFromVault("AZURE-IPACE-PASSWORD-JKS");

        saslConfig = {
            username: username,
            password: password,
            algorithm: SASL_SCRAM_SHA512
        };
        console.log('saslConfig = ' + saslConfig);
    }
}

const clientCertPem = vault.getIPaceEnvConfig().getValueFromEnvFor('ROOTDIR')+'/client-cert-0.pem';
const clientKeyPem = vault.getIPaceEnvConfig().getValueFromEnvFor('ROOTDIR')+'/client-key.pem';
const serverCaPem = vault.getIPaceEnvConfig().getValueFromEnvFor('ROOTDIR')+'/server-ca.pem';


export default function(data) {
    initializeCredentials();

    const tlsConfig = {
        enableTls: true,
        insecureSkipTlsVerify: true,
        minVersion: TLS_1_2,
        clientCertPem: clientCertPem, // The first certificate in the chain
        clientKeyPem: clientKeyPem,
        serverCaPem: serverCaPem,
    };

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

    const schemaRegistry = new SchemaRegistry();

    writer = new Writer({
        brokers: brokers,
        topic: topic,
        sasl: saslConfig,
        partition: partition,
        tls: tlsConfig,
    });

    reader = new Reader({
        brokers: brokers,
        topic: topic,
        partition: partition,
        offset: offset,
        sasl: saslConfig,
        tls: tlsConfig,
    });

    connection = new Connection({
        address: brokers[0],
        sasl: saslConfig,
        tls: tlsConfig,
    });
    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,
    });

      messages = reader.consume({ limit: 10 });

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


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

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



@mostafa mostafa changed the title ERRO[0015] GoError: Failed to unmarshal JSON data, OriginalError: %!w(*json.SyntaxError=&{invalid character 'd' after top-level value 3}) running at github.com/mostafa/xk6-kafka.(*Kafka).schemaRegistryClientClass.func5 (native) /invalid character 'd' after top-level value 3 Jul 18, 2023
@mostafa
Copy link
Owner

mostafa commented Jul 18, 2023

@arpitaso Have you been able to fix this?

@mostafa mostafa changed the title /invalid character 'd' after top-level value 3 invalid character 'd' after top-level value 3 Jul 18, 2023
@arpitaso
Copy link
Author

no @mostafa this issue still exists.

@arpitaso
Copy link
Author

@mostafa can you please help here?
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants