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

chore: confluent API spec evolution #925

Merged
merged 5 commits into from
Aug 2, 2024

Conversation

amstee
Copy link
Contributor

@amstee amstee commented Jul 26, 2024

About this change - What it does

Allow definition of two new fields when schema is registered to keep compatibility with confluent clients

Issue Number 916

Why this way

See: https://docs.confluent.io/platform/current/schema-registry/develop/api.html#post--subjects-(string-%20subject)

@amstee amstee requested review from a team as code owners July 26, 2024 16:15
@amstee amstee changed the title chore: allow definition of two new fields when schema is registered t… chore: confluent API spec evolution Jul 26, 2024
@nosahama nosahama enabled auto-merge (squash) August 2, 2024 15:24
@nosahama nosahama merged commit ac7fabd into Aiven-Open:main Aug 2, 2024
9 of 10 checks passed
@amstee amstee deleted the support-confluent-api-spec branch August 2, 2024 20:22
@fijolekProjects
Copy link

fijolekProjects commented Aug 5, 2024

Thank you guys! I'm testing these changes using ghcr.io/aiven-open/karapace:develop docker image, and indeed I can create a subject that contains new ruleSet field without errors, but unfortunately the new fields are not stored in __schemas topic which means that the new fields data is lost and cannot be used.

Example

Create a subject:

curl -X POST --location "http://localhost:8081/subjects/example_order-value/versions?normalize=false" \
    -d '{"ruleSet": {"domainRules": [{"name": "checkPersonAge", "kind": "CONDITION", "mode": "WRITE", "type": "CEL", "params": {"dlq.topic": "bad-data"}, "expr": "message.person.age > 18", "onFailure": "DLQ", "disabled": false}]}, "schema": "{\"type\":\"record\",\"name\":\"OutboxOrder\",\"namespace\":\"com.example.outbox.messages\",\"doc\":\"Order avro message\",\"fields\":[{\"name\":\"id\",\"type\":[\"null\",\"string\"],\"doc\":\"Order Id\",\"default\":null},{\"name\":\"store_id\",\"type\":\"string\"},{\"name\":\"person\",\"type\":{\"type\":\"record\",\"name\":\"OutboxPerson\",\"doc\":\"Person avro message\",\"fields\":[{\"name\":\"first_name\",\"type\":\"string\",\"doc\":\"The person first name - mandatory\"},{\"name\":\"last_name\",\"type\":[\"null\",\"string\"],\"doc\":\"The person last name - optional\",\"default\":null},{\"name\":\"age\",\"type\":[\"null\",\"int\"],\"doc\":\"The person age\",\"default\":null}]},\"doc\":\"The person making the order\"},{\"name\":\"product_id\",\"type\":\"long\"},{\"name\":\"timestamp\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"},\"doc\":\"Original timestamp of the event\"}]}"}'

Fetch a subject:

curl -X GET --location "http://localhost:8081/subjects/example_order-value/versions/latest"

Fetched subject from karapace:

{
  "id": 1,
  "schema": "{\"doc\":\"Order avro message\",\"fields\":[{\"default\":null,\"doc\":\"Order Id\",\"name\":\"id\",\"type\":[\"null\",\"string\"]},{\"name\":\"store_id\",\"type\":\"string\"},{\"doc\":\"The person making the order\",\"name\":\"person\",\"type\":{\"doc\":\"Person avro message\",\"fields\":[{\"doc\":\"The person first name - mandatory\",\"name\":\"first_name\",\"type\":\"string\"},{\"default\":null,\"doc\":\"The person last name - optional\",\"name\":\"last_name\",\"type\":[\"null\",\"string\"]},{\"default\":null,\"doc\":\"The person age\",\"name\":\"age\",\"type\":[\"null\",\"int\"]}],\"name\":\"OutboxPerson\",\"type\":\"record\"}},{\"name\":\"product_id\",\"type\":\"long\"},{\"doc\":\"Original timestamp of the event\",\"name\":\"timestamp\",\"type\":{\"logicalType\":\"timestamp-millis\",\"type\":\"long\"}}],\"name\":\"OutboxOrder\",\"namespace\":\"com.example.outbox.messages\",\"type\":\"record\"}",
  "subject": "example_order-value",
  "version": 1
}

Fetched subject when using confluent's schema registry

{
  "subject": "example_order-value",
  "version": 1,
  "id": 1,
  "schema": "{\"type\":\"record\",\"name\":\"OutboxOrder\",\"namespace\":\"com.example.outbox.messages\",\"doc\":\"Order avro message\",\"fields\":[{\"name\":\"id\",\"type\":[\"null\",\"string\"],\"doc\":\"Order Id\",\"default\":null},{\"name\":\"store_id\",\"type\":\"string\"},{\"name\":\"person\",\"type\":{\"type\":\"record\",\"name\":\"OutboxPerson\",\"doc\":\"Person avro message\",\"fields\":[{\"name\":\"first_name\",\"type\":\"string\",\"doc\":\"The person first name - mandatory\"},{\"name\":\"last_name\",\"type\":[\"null\",\"string\"],\"doc\":\"The person last name - optional\",\"default\":null},{\"name\":\"age\",\"type\":[\"null\",\"int\"],\"doc\":\"The person age\",\"default\":null}]},\"doc\":\"The person making the order\"},{\"name\":\"product_id\",\"type\":\"long\"},{\"name\":\"timestamp\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"},\"doc\":\"Original timestamp of the event\"}]}",
  "ruleSet": {
    "domainRules": [
      {
        "name": "checkPersonAge",
        "kind": "CONDITION",
        "mode": "WRITE",
        "type": "CEL",
        "params": {
          "dlq.topic": "bad-data"
        },
        "expr": "message.person.age > 18",
        "onFailure": "DLQ",
        "disabled": false
      }
    ]
  }
}

@nosahama
Copy link
Contributor

nosahama commented Aug 5, 2024

Hello @fijolekProjects exactly what I had discussed with @amstee , these changes are just to allow the API validation. Going further with adding the new attributes to the stored schema and updating the API response is something that might cause breaking changes, should be well tested and properly versioned, thus, the issue is still left open.

@fijolekProjects
Copy link

Thank you @nosahama

@nosahama
Copy link
Contributor

nosahama commented Aug 7, 2024

We will look into the full implementation in the coming weeks 👍

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

Successfully merging this pull request may close these issues.

3 participants