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

CORE-6860 Schema Registry: add detailed verbose compatibility checks #22958

Merged
merged 4 commits into from
Aug 28, 2024

Conversation

pgellert
Copy link
Contributor

@pgellert pgellert commented Aug 20, 2024

This implements detailed compatibility checks for protobuf and avro in schema registry. This enabled the schema registry and rpk to surface more specific information about the cause of the incompatibility between a new schema and the existing schemas by pointing the user to the exact incompatibility. This PR aims only to change the error reporting behaviour of the check compatibility endpoint when the ?verbose=true parameter is explicitly specified and does not change the rules of what schema pairs are (in)compatible.

This PR was cherry-picked and then adapted from @oleiman's earlier PR #18332.

Fixes https://redpandadata.atlassian.net/browse/CORE-6860

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v24.2.x
  • v24.1.x
  • v23.3.x

Release Notes

Improvements

  • Schema Registry: now reports more specific error messages for Avro and Protobuf schemas when they are incompatible with earlier schemas.

Bug Fixes

  • Schema Registry: fixes a bug in the protobuf compatibility checks of nested fields where nested paths were incorrectly handled.

@pgellert pgellert requested a review from a team August 20, 2024 11:06
@pgellert pgellert self-assigned this Aug 20, 2024
@pgellert pgellert requested review from michael-redpanda, BenPope and oleiman and removed request for a team August 20, 2024 11:06
Copy link
Member

@oleiman oleiman left a comment

Choose a reason for hiding this comment

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

looks good. As noted, wrt avro aliases ahead of upstream support: I think we should err on the side of permissiveness, but I don't feel very strongly about it.

@pgellert
Copy link
Contributor Author

Force-push: minor cleanup after code review

@pgellert pgellert requested a review from oleiman August 23, 2024 08:46
@vbotbuildovich
Copy link
Collaborator

@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Aug 23, 2024

new failures in https://buildkite.com/redpanda/redpanda/builds/53437#01917eae-8e35-4702-8ad0-06f37c1427a4:

"rptest.tests.rpk_registry_test.RpkRegistryTest.test_produce_consume_json"

new failures in https://buildkite.com/redpanda/redpanda/builds/53645#0191963a-9a6a-49ee-a8fd-012d2f6efd59:

"rptest.tests.scaling_up_test.ScalingUpTest.test_fast_node_addition"

Copy link
Member

@BenPope BenPope left a comment

Choose a reason for hiding this comment

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

Looks great. Just a few minor things.

In general I find it easier to review code when it has tests, and tests when it has code, so I'd reorder and squash some commits.

Also, verbose out should be in the response of POST /subjects/<subject>/versions, which is roughly along the lines of:

index b882f9e003..01c79f85c9 100644
--- a/src/v/pandaproxy/schema_registry/sharded_store.cc
+++ b/src/v/pandaproxy/schema_registry/sharded_store.cc
@@ -201,14 +201,15 @@ sharded_store::get_schema_version(subject_schema schema) {
     // Check compatibility of the schema
     if (!v_id.has_value() && !versions.empty()) {
         auto compat = co_await is_compatible(
-          versions.back().version, schema.schema.share());
-        if (!compat) {
+          versions.back().version, schema.schema.share(), verbose::yes);
+        if (!compat.is_compat) {
             throw exception(
               error_code::schema_incompatible,
               fmt::format(
                 "Schema being registered is incompatible with an earlier "
-                "schema for subject \"{}\"",
-                sub));
+                "schema for subject \"{}\", details: {}",
+                sub,
+                compat.messages));
         }
     }
     co_return has_schema_result{s_id, v_id};

But the messages are rendered inside of "{}" instead of "[]"

src/v/pandaproxy/schema_registry/avro.cc Show resolved Hide resolved
src/v/pandaproxy/schema_registry/protobuf.cc Outdated Show resolved Hide resolved
compat_result.emplace<proto_incompatibility>(
p / w->name(), proto_incompatibility::Type::message_removed);
} else {
compat_result.merge(check_compatible(r, w, p / w->name()));
Copy link
Member

Choose a reason for hiding this comment

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

nit: Missing test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot! reader->FindNestedTypeByName above actually takes a relative name and not a fully qualified name

oleiman and others added 4 commits August 27, 2024 23:28
Common test code for working with detailed compatibility info about
protobuf and avro schemas.
When an incompatible schema is posted, include the verbose compatibility
messages in the error message.

This helps users understand the reason for the incompatibility and it
matches the reference implementation.

Includes a minor fix to the way the compatibility level message is
formatted.
@pgellert
Copy link
Contributor Author

Force-push:

  • First: address code review feedback
  • Second: noop, reshuffling and squashing commits based on feedback

@pgellert pgellert requested a review from BenPope August 27, 2024 22:33
Copy link
Member

@oleiman oleiman left a comment

Choose a reason for hiding this comment

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

latest round lgtm

Comment on lines +566 to +569
BOOST_REQUIRE_MESSAGE(
errs == expected,
fmt::format("{} != {}", format_set(errs), format_set(expected)));
}
Copy link
Member

Choose a reason for hiding this comment

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

nice!

Copy link
Member

@BenPope BenPope left a comment

Choose a reason for hiding this comment

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

LGTM

@pgellert pgellert merged commit 2bd3b0d into redpanda-data:dev Aug 28, 2024
18 checks passed
@vbotbuildovich
Copy link
Collaborator

/backport v24.2.x

@vbotbuildovich
Copy link
Collaborator

/backport v24.1.x

@vbotbuildovich
Copy link
Collaborator

/backport v23.3.x

@vbotbuildovich
Copy link
Collaborator

Failed to create a backport PR to v24.2.x branch. I tried:

git remote add upstream https://github.com/redpanda-data/redpanda.git
git fetch --all
git checkout -b backport-pr-22958-v24.2.x-709 remotes/upstream/v24.2.x
git cherry-pick -x 11a87c3578ad396514bb8299bebeb5024ae37d1c ffecdd1a3f71256d08f5984d7590780cbfb95227 4c87c5ed21416d98f6d05a1c6c06ec0ab4949336 cda768b4a3da734f52ab04b5220c4d93b7e5fd97

Workflow run logs.

@vbotbuildovich
Copy link
Collaborator

Failed to create a backport PR to v23.3.x branch. I tried:

git remote add upstream https://github.com/redpanda-data/redpanda.git
git fetch --all
git checkout -b backport-pr-22958-v23.3.x-412 remotes/upstream/v23.3.x
git cherry-pick -x 11a87c3578ad396514bb8299bebeb5024ae37d1c ffecdd1a3f71256d08f5984d7590780cbfb95227 4c87c5ed21416d98f6d05a1c6c06ec0ab4949336 cda768b4a3da734f52ab04b5220c4d93b7e5fd97

Workflow run logs.

@vbotbuildovich
Copy link
Collaborator

Failed to create a backport PR to v24.1.x branch. I tried:

git remote add upstream https://github.com/redpanda-data/redpanda.git
git fetch --all
git checkout -b backport-pr-22958-v24.1.x-905 remotes/upstream/v24.1.x
git cherry-pick -x 11a87c3578ad396514bb8299bebeb5024ae37d1c ffecdd1a3f71256d08f5984d7590780cbfb95227 4c87c5ed21416d98f6d05a1c6c06ec0ab4949336 cda768b4a3da734f52ab04b5220c4d93b7e5fd97

Workflow run logs.

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

Successfully merging this pull request may close these issues.

4 participants