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

Add ConfluentSchemaRegistry#compatibility_issues for debugging breaking changes #212

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Add `compatibility_issues` method to `ConfluentSchemaRegistry` to debug compatibility issues between a schema versions for a given subject (#212)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I popped it into this section, but let me know if you wanted me to add to a new v1.18.0 heading instead 😁

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perfect!


## v1.17.0

- Add `register_schemas` option to `encode` method [#210](https://github.com/dasch/avro_turf/pull/210)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ registry = AvroTurf::ConfluentSchemaRegistry.new("http://my-registry:8081/")

# Returns true if the schema is compatible, nil if the subject or version is not registered, and false if incompatible.
registry.compatible?("person", schema)

# Returns an array of any breaking changes, nil if the subject or version is not registered
registry.compatibility_issues("person", schema)
```

The ConfluentSchemaRegistry client can also change the global compatibility level or the compatibility level for an individual subject using the [Config API](http://docs.confluent.io/3.1.2/schema-registry/docs/api.html#config):
Expand Down
12 changes: 12 additions & 0 deletions lib/avro_turf/confluent_schema_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ def compatible?(subject, schema, version = 'latest')
data.fetch('is_compatible', false) unless data.has_key?('error_code')
end

# Check for specific schema compatibility issues
# Returns:
# - nil if the subject or version does not exist
# - a list of compatibility issues
# https://docs.confluent.io/platform/current/schema-registry/develop/api.html#sr-api-compatibility
def compatibility_issues(subject, schema, version = 'latest')
data = post("/compatibility/subjects/#{@schema_context_prefix}#{subject}/versions/#{version}",
expects: [200, 404], body: { schema: schema.to_s }.to_json, query: { verbose: true }, idempotent: true)

data.fetch('messages', []) unless data.has_key?('error_code')
end

# Get global config
def global_config
get("/config", idempotent: true)
Expand Down
Loading