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

Basic support of references Karapace API calls. #21

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

Conversation

libretto
Copy link
Collaborator

@libretto libretto commented Apr 19, 2022

We add basic support of references to following API calls:

POST /subjects/(string: subject)/versions
POST /subjects/(string: subject)
GET /subjects/(string: subject)/versions/{versionId: version}/referencedby
DELETE /subjects/subject:path/versions/version:path
DELETE /subjects/subject:path

Support of references is limited to PROTOBUF schema type, but this code will be reused with minimal changes in the future implementation of references to other schemas.

@libretto libretto changed the title add basic support of references to POST/GET subjects Basic support of references Karapace API calls. May 16, 2022
@sujayinstaclustr
Copy link

@libretto I merged the latest changes from avien/karapace upstream in to instaclustr/karapace. It had merge conflict and they removed ujson dependency. Please update your branches accordingly if you have any. I have made the changes to the deps branches and PR is now updated with upstream.

Copy link

@jjaakola-aiven jjaakola-aiven left a comment

Choose a reason for hiding this comment

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

Sorry for the delay on reviewing this.
I've done first pass and some comments. I have not looked the testing coverage yet.

Compatibility check API does not support references, /compatibility/subjects/<subject:path>/versions/<version:path>. I am not sure how CSR uses it, but worth checking.

karapace/schema_models.py Show resolved Hide resolved
karapace/schema_models.py Outdated Show resolved Hide resolved
karapace/schema_models.py Outdated Show resolved Hide resolved


class References:
def __init__(self, schema_type: SchemaType, references: JsonData):

Choose a reason for hiding this comment

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

I would propose to type the references to specific type instead of JsonData.

Copy link
Collaborator Author

@libretto libretto Jul 13, 2022

Choose a reason for hiding this comment

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

@jjaakola-aiven Which reason to add some more types there when the specific type is "References" and data for this type is stored in Kafka in JSON?

Choose a reason for hiding this comment

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

Probably just an error from me on review, not sure after vacation. Possibly I've been thinking on modeling the data directly in the controller layer from JSON to objects.

karapace/schema_reader.py Outdated Show resolved Hide resolved
karapace/schema_reader.py Outdated Show resolved Hide resolved
karapace/schema_registry_apis.py Outdated Show resolved Hide resolved
new_schema_references = None
references = body.get("references")
if references:
if schema_type != SchemaType.PROTOBUF:

Choose a reason for hiding this comment

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

This should be validated before calling write_new_schema_local.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jjaakola-aiven Functionality of references validation must be released in next PR. Now we add basic functionality only

tests/integration/test_client.py Outdated Show resolved Hide resolved
tests/integration/test_client_protobuf.py Outdated Show resolved Hide resolved
@sujayinstaclustr
Copy link

sujayinstaclustr commented Jun 29, 2022

@jjaakola-aiven We addressed some of the feedback and waiting for to discuss few open comments (the ones showing pending)

@libretto
Copy link
Collaborator Author

@jjaakola-aiven We addressed some of the feedback and waiting for to discuss few open comments (the ones showing pending)
Pending was finished. I missed committing the review.

@sujayinstaclustr
Copy link

@libretto there are conflicts in the code pushed. Can you resolve the conflicts?

@sujayinstaclustr
Copy link

@jjaakola-aiven If this PR is all good to merge and we can raise a PR to upstream

ref_str = reference_key(ref["subject"], ref["version"])
referents = self.referenced_by.get(ref_str, None)
if referents:
LOG.info("Adding entry subject referenced_by : %r", ref_str)

Choose a reason for hiding this comment

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

Debug log.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Must we remove it?

Choose a reason for hiding this comment

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

If deemed valuable for debugging no need to remove, but change it to LOG.debug.

LOG.info("Adding entry subject referenced_by : %r", ref_str)
referents.append(schema_id)
else:
LOG.info("Adding entry subject referenced_by : %r", ref_str)

Choose a reason for hiding this comment

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

Debug log.

karapace/schema_registry_apis.py Outdated Show resolved Hide resolved
karapace/schema_reader.py Outdated Show resolved Hide resolved
Copy link

@jjaakola-aiven jjaakola-aiven left a comment

Choose a reason for hiding this comment

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

The compatibility check API does not support references, for completeness it should be added.


res = await registry_async_client.delete("subjects/customer/versions/1")
assert res.status_code == 404
match_msg = "Subject 'customer' Version 1 was not deleted because it is referenced by schemas with ids:[2]"

Choose a reason for hiding this comment

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

The lifecycle of schema and references would be nice to test:

  1. create schema A
  2. create schema B referencing A
  3. try to delete A
  4. delete B
  5. delete A

Steps 1-3 are covered, steps 4 and 5 would be needed.

@@ -55,6 +60,7 @@ class SchemaErrorMessages(Enum):
"forward, full, backward_transitive, forward_transitive, and "
"full_transitive"
)
REFERENCES_SUPPORT_NOT_IMPLEMENTED = "Schema references are not supported for '{schema_type}' schema type yet"

Choose a reason for hiding this comment

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

The yet is not needed and the request could contain arbitrary string as schema type resulting Schema references are not supported for '<ARBITRARY>' schema type yet

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The request always contains JSON with the exact schema type definition from the set of AVRO, JSON, and PROTOBUF in other case we raise an error.

Choose a reason for hiding this comment

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

I meant that yet points to future support. I would just state in the error that not supported without hinting on possible future support.

if referenced_by and len(referenced_by) > 0:
self.r(
body={
"error_code": SchemaErrorCodes.SCHEMAVERSION_HAS_REFERENCES.value,

Choose a reason for hiding this comment

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

@@ -67,6 +68,10 @@ class InvalidSchema(Exception):
pass


class InvalidReferences(Exception):

Choose a reason for hiding this comment

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

Seems that this is not raised.

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