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

Support unchanged status on schemas #344

Merged
merged 10 commits into from
Jan 21, 2024
Merged

Conversation

AlexisSouquiere
Copy link
Collaborator

No description provided.

@AlexisSouquiere AlexisSouquiere changed the title Feat/unchanged schema Support unchanged status on schema Nov 28, 2023
schema.getMetadata().setCluster(ns.getMetadata().getCluster());
schema.getMetadata().setNamespace(ns.getMetadata().getName());

if (dryrun) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this:

if (dryrun) {
  return Mono.just(formatHttpResponse(schema,
          latestSubjectOptional.isPresent()
                  ? ApplyStatus.changed : ApplyStatus.created));
}
  
return schemaService
      .register(ns, schema)
      .map(id -> {
          ApplyStatus status;
  
          if (latestSubjectOptional.isEmpty()) {
              status = ApplyStatus.created;
              sendEventLog(schema.getKind(), schema.getMetadata(), status, null,
                  schema.getSpec());
          } else if (id > latestSubjectOptional.get().getSpec().getId()) {
              status = ApplyStatus.changed;
              sendEventLog(schema.getKind(), schema.getMetadata(), status,
                  latestSubjectOptional.get().getSpec(),
                  schema.getSpec());
          } else {
              status = ApplyStatus.unchanged;
          }
  
          return formatHttpResponse(schema, status);
      });
});

could be now simplified to this:

ApplyStatus status = latestSubjectOptional.isPresent() ? ApplyStatus.changed : ApplyStatus.created;
if (dryrun) {
    return Mono.just(formatHttpResponse(schema, status);
}

return schemaService
    .register(ns, schema)
    .map(id -> formatHttpResponse(schema, status));

Since we now use the canonical string to compute the status, we do not need the schema registry response for the final HTTP response, what do you think ? I'm gonna try this out

Copy link
Collaborator

Choose a reason for hiding this comment

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

In case of reapplying a schema v1 that already has been deployed, the schema registry will return the ID of the schema v1 without any change (unchanged status). In this case, Ns4Kafka will return "changed"

The previous implementation will return "unchanged" as expected, except in dry-run mode that will return "changed" 😅

The "newSchema" parameter needs to be different from all schemas version to be considered "changed", not only the latest one

.defaultIfEmpty(Optional.empty())
.flatMap(latestSubjectOptional -> {
if (latestSubjectOptional.isPresent()) {
var newSchema = new AvroSchema(schema.getSpec().getSchema());
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a constructor for AvroSchema that takes schema references, here you take a risk to compare without references later in canonicalString().
It was done automatically on the registry side before

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point @twobeeb. Doing the comparison without the potential references is incorrect.

Copy link

Copy link

@loicgreffier loicgreffier marked this pull request as ready for review January 21, 2024 18:22
@loicgreffier loicgreffier changed the title Support unchanged status on schema Support unchanged status on schemas Jan 21, 2024
@loicgreffier loicgreffier merged commit 0e369c5 into master Jan 21, 2024
3 checks passed
@loicgreffier loicgreffier deleted the feat/unchanged-schema branch January 21, 2024 18:23
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