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

fix: align transitive compatibility checks #953

Merged
merged 3 commits into from
Oct 10, 2024

Conversation

davide-armand
Copy link
Contributor

@davide-armand davide-armand commented Sep 18, 2024

About this change - What it does

Make so that the transitive compatibility checks that are done in the
schema creation endpoint are also done in the schema validation
endpoint.

In the creation endpoint (/subjects/<subject-key>/versions), if the
compatibility mode is transient then the new schema is checked against
all schemas.

In the validation endpoint (/compatibility/subjects/<subject-key>/versions/<schema-version>):

  • Before this fix, only the latest schema is checked against (even in
    case of transitive mode)
  • After this fix, in case of transitive mode then all schema are
    checked against.
    Note that in this case the version provided in the POST request
    (<schema-version>) is ignored.

Also includes some preparation refactorings and some additional tests in separate commits.

Why this way

The refactorings are needed to avoid code duplication.

An alternative solution would be to allow querying the validation endpoint with no version (/compatibility/subjects/<subject-key>), and apply the fix only in that case.

@davide-armand davide-armand force-pushed the davide-armand/EC-289-fix-transitive-validation branch 5 times, most recently from c32cfaf to 9f1c54b Compare September 18, 2024 13:13
@davide-armand davide-armand marked this pull request as ready for review September 18, 2024 13:15
@davide-armand davide-armand requested review from a team as code owners September 18, 2024 13:15
@davide-armand davide-armand force-pushed the davide-armand/EC-289-fix-transitive-validation branch from 9f1c54b to 3cce148 Compare September 19, 2024 13:05
Copy link

github-actions bot commented Sep 19, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/karapace
  schema_registry.py
  schema_registry_apis.py
  src/karapace/compatibility
  __init__.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Contributor

@eliax1996 eliax1996 left a comment

Choose a reason for hiding this comment

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

I think the code its nice, the feature its well tested.
I'm still not fully convinced by the use of mocks, I think they can couple the way of a certain result its computed.
I would much more like a test where you give the input and the real implementation does the logic and you check the outcome, its a type of testing that makes the refactor much less painful since you don't need to change the assertions not being coupled by the names of the functions and the order in which they are called

karapace/schema_registry.py Outdated Show resolved Hide resolved
karapace/schema_registry.py Outdated Show resolved Hide resolved
karapace/schema_registry_apis.py Outdated Show resolved Hide resolved
tests/unit/test_schema_registry.py Outdated Show resolved Hide resolved
tests/unit/test_schema_registry.py Outdated Show resolved Hide resolved
tests/unit/test_schema_registry.py Outdated Show resolved Hide resolved
@davide-armand davide-armand force-pushed the davide-armand/EC-289-fix-transitive-validation branch from 3cce148 to d4b7cc0 Compare September 23, 2024 13:52
karapace/schema_registry.py Outdated Show resolved Hide resolved
karapace/schema_registry_apis.py Outdated Show resolved Hide resolved
tests/unit/test_schema_registry.py Outdated Show resolved Hide resolved
@davide-armand davide-armand force-pushed the davide-armand/EC-289-fix-transitive-validation branch 6 times, most recently from bec59e5 to d98176e Compare October 3, 2024 10:23
@davide-armand davide-armand force-pushed the davide-armand/EC-289-fix-transitive-validation branch 2 times, most recently from bd499aa to 2a7a250 Compare October 10, 2024 07:36
@davide-armand
Copy link
Contributor Author

Rebased and fixed conflicts

Copy link
Contributor

@eliax1996 eliax1996 left a comment

Choose a reason for hiding this comment

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

Almost there, except for a couple of changes great great job!
I like much more those tests, I can read them and understand them really well, thanks for the hard work 🚀

@davide-armand davide-armand force-pushed the davide-armand/EC-289-fix-transitive-validation branch from 2a7a250 to ae427bf Compare October 10, 2024 13:40
This in preparation for the fix for [EC-289].

 - Move schema compatibility related code from __init__.py to its own
   module (schema_compatibility.py)
 - Refactor logic in:
   - Schema registering endpoint (`/subjects/<subject-key>/versions`)
   - Schema compatibility endpoint (`/compatibility/subjects/<subject-key>/versions/latest`)
Make so that the transitive compatibility checks that are done in the
schema creation endpoint are also done in the schema validation
endpoint.

In the creation endpoint (`/subjects/<subject-key>/versions`), if the
compatibility mode is transient then the new schema is checked against
all schemas.

In the validation endpoint (`/compatibility/subjects/<subject-key>/versions/<schema-version>`):
 - Before this fix, only the latest schema is checked against (even in
   case of transitive mode)
 - After this fix, in case of transitive mode then all schema are
   checked against.
   Note that in this case the version provided in the POST request
   (`<schema-version>`) is ignored.
@davide-armand davide-armand force-pushed the davide-armand/EC-289-fix-transitive-validation branch from ae427bf to 5d58f68 Compare October 10, 2024 14:02
@davide-armand
Copy link
Contributor Author

@eliax1996 I should I have address all comments, thanks for your detailed review!

@davide-armand davide-armand force-pushed the davide-armand/EC-289-fix-transitive-validation branch from 5d58f68 to e208a39 Compare October 10, 2024 15:23
@davide-armand davide-armand force-pushed the davide-armand/EC-289-fix-transitive-validation branch from e208a39 to 429e18c Compare October 10, 2024 20:30
@eliax1996 eliax1996 merged commit f9f5fe7 into main Oct 10, 2024
8 checks passed
@eliax1996 eliax1996 deleted the davide-armand/EC-289-fix-transitive-validation branch October 10, 2024 20:49
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