xk6-kafka: Error serializing value data when using type array using Avro schema

Hello, I’m running some Kafka load test using xk6-kafka and i’m getting some errors when serializing objects. In my Avro schema there is some fields that are array type and seems that when calling schemaRegistry.serialize() i’m getting the following error:

k6-1 | time="2024-01-09T06:55:21Z" level=error msg="panic: runtime error: invalid memory address or nil pointer dereference\ngoroutine 59 [running]:\nruntime/debug.Stack()\n\truntime/debug/stack.go:24 +0x5e\ngo.k6.io/k6/js/common.RunWithPanicCatching.func1()\n\tgo.k6.io/k6@v0.48.0/js/common/util.go:82 +0x1df\npanic({0x17c3520?, 0x2d13300?})\n\truntime/panic.go:914 +0x21f\ngithub.com/dop251/goja.(*Runtime).runWrapped.func1()\n\tgithub.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/runtime.go:2442 +0x171\npanic({0x17c3520?, 0x2d13300?})\n\truntime/panic.go:914 +0x21f\ngithub.com/dop251/goja.(*vm).handleThrow(0xc002b547e0, {0x17c3520, 0x2d13300})\n\tgithub.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:788 +0x425\ngithub.com/dop251/goja.(*vm).try.func1()\n\tgithub.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:807 +0x3f\npanic({0x17c3520?, 0x2d13300?})\n\truntime/panic.go:914 +0x21f\ngithub.com/dop251/goja.(*vm).handleThrow(0xc002b547e0, {0x17c3520, 0x2d13300})\n\tgithub.com/dop251/goja@v0.0.0-20231027120936-b396bb4c349d/vm.go:788 +0x425\ngithub.com/dop251/goja.(*vm).runTryInner.func1()\n\tgithub.com/dop251/goja@v0.0.0-20231027120936

I tried with another Avro schema without that type array and it worked. Is there a way to pass that data to the serialice method? Thanks in advance.

About this issue

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

Most upvoted comments

Hello @mostafa

it worked! Thanks for your help 😃

@ricardpons @ferrange @irenedmg

Found the issue! You have to use the type with its namespace to provide meaningful data to the Avro codec. So, instead of using the bare "EmailAddressBasicInfo", use "internalservices.itoperation.emailmessage.EmailAddressBasicInfo" instead. The following collapsibles include a working schema and a JSON data object:

Schema
{
"type": "record",
  "name": "EmailMessageEventRestrictedInValue",
  "namespace": "internalservices.itoperation.emailmessage",
  "fields": [
    {
      "name": "payload",
      "type": {
        "type": "record",
        "name": "EmailMessage",
        "fields": [
          {
            "name": "id",
            "type": [
              "null",
              {
                "type": "string",
                "avro.java.string": "String"
              }
            ],
            "default": null
          },
          {
            "name": "smtpConfigName",
            "type": [
              "null",
              {
                "type": "string",
                "avro.java.string": "String"
              }
            ],
            "default": null
          },
          {
            "name": "emailAddressFrom",
            "type": {
              "type": "record",
              "name": "EmailAddressBasicInfo",
              "fields": [
                {
                  "name": "emailAddress",
                  "type": [
                    "null",
                    {
                      "type": "string",
                      "avro.java.string": "String"
                    }
                  ],
                  "default": null
                },
                {
                  "name": "alias",
                  "type": [
                    "null",
                    {
                      "type": "string",
                      "avro.java.string": "String"
                    }
                  ],
                  "default": null
                }
              ]
            }
          },
          {
            "name": "emailAddressTo",
            "type": {
              "type": "array",
              "items": "EmailAddressBasicInfo"
            }
          },
          {
            "name": "emailAddressCc",
            "type": [
              "null",
              {
                "type": "array",
                "items": "EmailAddressBasicInfo"
              }
            ],
            "default": null
          },
          {
            "name": "emailAddressBcc",
            "type": [
              "null",
              {
                "type": "array",
                "items": "EmailAddressBasicInfo"
              }
            ],
            "default": null
          },
          {
            "name": "subject",
            "type": [
              "null",
              {
                "type": "string",
                "avro.java.string": "String"
              }
            ],
            "default": null
          },
          {
            "name": "body",
            "type": [
              "null",
              {
                "type": "string",
                "avro.java.string": "String"
              }
            ],
            "default": null
          },
          {
            "name": "isHtmlBody",
            "type": [
              "null",
              "boolean"
            ],
            "default": null
          },
          {
            "name": "emailAddressReplyTo",
            "type": [
              "null",
              "EmailAddressBasicInfo"
            ],
            "default": null
          },
          {
            "name": "attachments",
            "type": [
              "null",
              {
                "type": "array",
                "items": {
                  "type": "record",
                  "name": "EmailMessageAttachment",
                  "fields": [
                    {
                      "name": "name",
                      "type": [
                        "null",
                        {
                          "type": "string",
                          "avro.java.string": "String"
                        }
                      ],
                      "default": null
                    },
                    {
                      "name": "attachment",
                      "type": [
                        "null",
                        {
                          "type": "string",
                          "avro.java.string": "String"
                        }
                      ],
                      "default": null
                    }
                  ]
                }
              }
            ],
            "default": null
          },
          {
            "name": "priority",
            "type": [
              "null",
              "int"
            ],
            "default": null
          }
        ]
      }
    }
  ]
}
Data
{
  "payload": {
    "id": {
      "string": "1234567890"
    },
    "smtpConfigName": {
      "string": "Config 1"
    },
    "emailAddressFrom": {
      "emailAddress": {
        "string": "nameapp@mail.test.com"
      },
      "alias": {
        "string": "nameapp"
      }
    },
    "emailAddressTo": [
      {
        "emailAddress": {
          "string": "dest1@test.com"
        },
        "alias": {
          "string": "dest 1"
        }
      }
    ],
    "emailAddressCc": {
      "array": [
        {
          "emailAddress": {
            "string": "dest2@test.com"
          },
          "alias": {
            "string": "dest 2"
          }
        }
      ]
    },
    "emailAddressBcc": {
      "array": [
        {
          "emailAddress": {
            "string": "dest3@test.com"
          },
          "alias": {
            "string": "dest 3"
          }
        }
      ]
    },
    "subject": {
      "string": "test info"
    },
    "body": {
      "string": "test info body"
    },
    "isHtmlBody": {
      "boolean": true
    },
    "emailAddressReplyTo": {
      "internalservices.itoperation.emailmessage.EmailAddressBasicInfo": {
        "emailAddress": {
          "string": "app-nameapp@test.com"
        },
        "alias": {
          "string": "App name App"
        }
      }
    },
    "attachments": {
      "array": [
        {
          "name": {
            "string": "attachmentfile.png"
          },
          "attachment": {
            "string": "http://www.test.com"
          }
        }
      ]
    },
    "priority": {
      "int": 0
    }
  }
}

I created this repo to test your schema and data.

Hi @mostafa sure, here is an example of the message we produce working, which has commented the fragment I think it should work but it doesn’t. You will see the same property “emailAddressReplyTo” as null, which works fine:

{
    "payload": {
        "id": { string: "1234567890" },
        "smtpConfigName": { string: "Config 1" },
        "emailAddressFrom": {
            "emailAddress": { string: "nameapp@mail.test.com" },
            "alias": { string: "nameapp" },
        },
        "emailAddressTo": [
            {
                "emailAddress": { string: "dest1@test.com" },
                "alias": { string: "dest 1" },
            }
        ],
        "emailAddressCc": {
            array: [
                {
                    "emailAddress": { string: "dest2@test.com" },
                    "alias": { string: "dest 2" },
                }
            ]
        },
        "emailAddressBcc": {
            array: [
                {
                    "emailAddress": { string: "dest3@test.com" },
                    "alias": { string: "dest 3" },
                }
            ]
        },
        "subject": { string: "test info" },
        "body": { string: "test info body" },
        "isHtmlBody": { boolean: true },
        // "emailAddressReplyTo": {
        //     EmailAddressBasicInfo: {
        //         "emailAddress": { string: "app-nameapp@test.com" },
        //         "alias": { string: "App name App" }
        //     }
        // },
        "emailAddressReplyTo": null,
        "attachments": {
            array: [
                {
                    "name": { string: "attachmentfile.png" },
                    "attachment": { string: "http://www.test.com" }
                }
            ]
        },
        "priority": { int: 0 }
    }
}

@mostafa here you have the full schema which works fine when we send the message like this {"emailAddressReplyTo": null}:

{
"type": "record",
  "name": "EmailMessageEventRestrictedInValue",
  "namespace": "internalservices.itoperation.emailmessage",
  "fields": [
    {
      "name": "payload",
      "type": {
        "type": "record",
        "name": "EmailMessage",
        "fields": [
          {
            "name": "id",
            "type": [
              "null",
              {
                "type": "string",
                "avro.java.string": "String"
              }
            ],
            "default": null
          },
          {
            "name": "smtpConfigName",
            "type": [
              "null",
              {
                "type": "string",
                "avro.java.string": "String"
              }
            ],
            "default": null
          },
          {
            "name": "emailAddressFrom",
            "type": {
              "type": "record",
              "name": "EmailAddressBasicInfo",
              "fields": [
                {
                  "name": "emailAddress",
                  "type": [
                    "null",
                    {
                      "type": "string",
                      "avro.java.string": "String"
                    }
                  ],
                  "default": null
                },
                {
                  "name": "alias",
                  "type": [
                    "null",
                    {
                      "type": "string",
                      "avro.java.string": "String"
                    }
                  ],
                  "default": null
                }
              ]
            }
          },
          {
            "name": "emailAddressTo",
            "type": {
              "type": "array",
              "items": "EmailAddressBasicInfo"
            }
          },
          {
            "name": "emailAddressCc",
            "type": [
              "null",
              {
                "type": "array",
                "items": "EmailAddressBasicInfo"
              }
            ],
            "default": null
          },
          {
            "name": "emailAddressBcc",
            "type": [
              "null",
              {
                "type": "array",
                "items": "EmailAddressBasicInfo"
              }
            ],
            "default": null
          },
          {
            "name": "subject",
            "type": [
              "null",
              {
                "type": "string",
                "avro.java.string": "String"
              }
            ],
            "default": null
          },
          {
            "name": "body",
            "type": [
              "null",
              {
                "type": "string",
                "avro.java.string": "String"
              }
            ],
            "default": null
          },
          {
            "name": "isHtmlBody",
            "type": [
              "null",
              "boolean"
            ],
            "default": null
          },
          {
            "name": "emailAddressReplyTo",
            "type": [
              "null",
              "EmailAddressBasicInfo"
            ],
            "default": null
          },
          {
            "name": "attachments",
            "type": [
              "null",
              {
                "type": "array",
                "items": {
                  "type": "record",
                  "name": "EmailMessageAttachment",
                  "fields": [
                    {
                      "name": "name",
                      "type": [
                        "null",
                        {
                          "type": "string",
                          "avro.java.string": "String"
                        }
                      ],
                      "default": null
                    },
                    {
                      "name": "attachment",
                      "type": [
                        "null",
                        {
                          "type": "string",
                          "avro.java.string": "String"
                        }
                      ],
                      "default": null
                    }
                  ]
                }
              }
            ],
            "default": null
          },
          {
            "name": "priority",
            "type": [
              "null",
              "int"
            ],
            "default": null
          }
        ]
      }
    }
  ]
}

The problem comes when we try to use the emailAddressReplyTo != null, as @irenedmg showed above

Thanks in advance!