kafka-ui icon indicating copy to clipboard operation
kafka-ui copied to clipboard

Avro messages with Union type are not shown correctly

Open christoph110 opened this issue 2 years ago • 5 comments

Describe the bug Avro messages are not shown correctly when using Union type.

Set up Use provectuslabs/kafka-ui:0.4.0 image. Use confluentinc schema registry confluentinc/cp-schema-registry:7.0.1

version: '3.5'
...
services:
...
  schema-registry:
    image: confluentinc/cp-schema-registry:7.0.1
    environment:
      SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: zookeeper:2181
      SCHEMA_REGISTRY_HOST_NAME: schema-registry
      SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: kafka:9092
    ports:
      - "8081:8081"
    depends_on:
      - zookeeper
      - kafka
...
  kafka-ui:
    image: provectuslabs/kafka-ui:v0.4.0
    ports:
      - "8080:8080"
    depends_on:
      - schema-registry
    environment:
      KAFKA_CLUSTERS_0_NAME: local
      KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9092
      KAFKA_CLUSTERS_0_SCHEMAREGISTRY: http://schema-registry:8081
...

Steps to Reproduce Steps to reproduce the behavior:

  1. Run docker compose
  2. Send Avro message using confluent_kafka.schema_registry.avro.AvroSerializer

Expected behavior The message for an Avro schema that contains Union types should be displayed correctly.

Screenshots Using this schema: image

Creates this rendered message: image

Expected message rendering would be the same as for the consumer using the confluent_kafka.schema_registry.avro.AvroDeserializer module:

{'a': 'hello'}

Additional context

christoph110 avatar May 04 '22 13:05 christoph110

Hello there christoph110! 👋

Thank you and congratulations 🎉 for opening your very first issue in this project! 💖

In case you want to claim this issue, please comment down below! We will try to get back to you as soon as we can. 👀

github-actions[bot] avatar May 04 '22 13:05 github-actions[bot]

Hey, thanks for reaching out. We'll schedule the fix for current release.

Haarolean avatar May 05 '22 23:05 Haarolean

@Haarolean Can i work on this ?

shubhwip avatar Sep 15 '22 06:09 shubhwip

@shubhwip please keep in mind that we're gonna change serdes a lot within #2125, so it might be a good idea to postpone it and do a PR for the new codebase

Haarolean avatar Sep 15 '22 09:09 Haarolean

@shubhwip please keep in mind that we're gonna change serdes a lot within #2125, so it might be a good idea to postpone it and do a PR for the new codebase

Okay sure will wait for #2125 to get merged.

shubhwip avatar Sep 15 '22 09:09 shubhwip

Hello @christoph110,

This behaviour is actually expected. Current json rendering policy is following json encoding spec for avro (https://avro.apache.org/docs/1.11.1/specification/_print/#json-encoding).

Reason why this is required is that for some types like int-long, string-bytes, float-double it is not possible to infer what exact type should be set in avro from json. I mean, for some simple cases like yours it can be done, but this is not universal.

I agree that we can make it configurable (or do it only when it is possible), but we should think about it more carefully.

PS. we should also check protobuf oneof fields, since they have pretty similar sttucture.

cc @Haarolean @shubhwip

iliax avatar Sep 23 '22 10:09 iliax

Hi @iliax ,

that makes sense, didn't know about these specs. Thanks for looking into this. In this case, since it is an Avro specification and not related to kafka-ui, I would say this issue can be closed unless you want to keep it for further investigations (e.g. what you wrote under PS: )

christoph110 avatar Sep 25 '22 12:09 christoph110