Skip to content

storage/sink/kafka: Allow configuring compatibility levels for schema registry subjects#27641

Merged
rjobanp merged 5 commits intoMaterializeInc:mainfrom
rjobanp:new-csr-options
Jun 17, 2024
Merged

storage/sink/kafka: Allow configuring compatibility levels for schema registry subjects#27641
rjobanp merged 5 commits intoMaterializeInc:mainfrom
rjobanp:new-csr-options

Conversation

@rjobanp
Copy link
Copy Markdown
Contributor

@rjobanp rjobanp commented Jun 13, 2024

Motivation

This implements the 2nd part of the linked issue, allowing users to specify new options as part of the CSR CONNECTION in a CREATE SINK statement:

KEY COMPATIBILITY LEVEL
VALUE COMPATIBILITY LEVEL

which uses the CSR config api to set these values: https://docs.confluent.io/platform/7.6/schema-registry/develop/api.html#config

Tips for reviewer

Checklist

@rjobanp rjobanp requested review from a team and benesch as code owners June 13, 2024 18:34
@rjobanp rjobanp requested a review from jkosh44 June 13, 2024 18:34
Copy link
Copy Markdown
Contributor

@jkosh44 jkosh44 left a comment

Choose a reason for hiding this comment

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

Adapter code LGTM (I didn't take the time to actually understand the feature though).

Comment thread src/sql/src/plan/statement/ddl.rs
Comment thread src/ccsr/src/client.rs Outdated
Comment thread src/ccsr/src/client.rs Outdated
Comment thread src/ccsr/tests/client.rs
Comment thread src/ccsr/src/client.rs Outdated
Comment on lines +422 to +426
if err.status() == Some(reqwest::StatusCode::NOT_FOUND) {
GetSubjectConfigError::SubjectNotFound
} else {
GetSubjectConfigError::Transport(err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you sure about this? I don't think 4xx errors come through as transport errors. I would expect this to look more like the other From<UnhandledError> implementations where you need to match on UnhandledError::Api.code.

Also note that the error I'm seeing when a subject does not exist has code 40408 and message "Subject does not have subject-level compatibility configured". I think the CSR doesn't distinguish between "subject does not exist" and "subject does not have compatibility configured".

Copy link
Copy Markdown
Contributor Author

@rjobanp rjobanp Jun 17, 2024

Choose a reason for hiding this comment

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

For this one it appears this does come through as a 404 http status code, at least according to their docs: https://docs.confluent.io/platform/7.6/schema-registry/develop/api.html#get--config-(string-%20subject)

Also note that the error I'm seeing when a subject does not exist has code 40408 and message "Subject does not have subject-level compatibility configured".

Where do you see this? Is this on this same GET /subject/<subject> API?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are totally right - this returns a 40408 when the subject level is not yet set. Adding the tests caught this. Undocumented behavior!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, it's not undocumented, it's that reqwest by default won't throw an error on a 4xx or 5xx error code. You need to call raise_for_status() if you want that behavior. In this case, the code is structured so that we don't want that behavior, because send_request is already doing all the right things and pulling out the more specific error code (40408) from the response body, vs the less specific 404 status code of the HTTP response itself.

Copy link
Copy Markdown
Contributor Author

@rjobanp rjobanp Jun 17, 2024

Choose a reason for hiding this comment

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

It's undocumented in the linked confluent API docs! All the other APIs describe the internal codes used for specific error types, but the Get Config docs just show this:
image

despite it actually returning the 40408 error when the subject isnt set

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh sorry I see, I misunderstood! Yes, huh, that does seem to be undocumented.

It looks like you've still got the 404 check in the branch above—I think we should just remove that since we'll never create a transport error with status 404!

Comment thread src/storage-client/src/sink.rs
Comment thread src/testdrive/src/action/schema_registry.rs
@benesch
Copy link
Copy Markdown
Contributor

benesch commented Jun 14, 2024

Dropped in some substantive feedback in line comments. Can you add docs for this one too?

I'm also cc'ing @MaterializeInc/testing in case they have ideas for additional tests to add. Never mind. You'd already done that!

@rjobanp rjobanp requested a review from morsapaes as a code owner June 17, 2024 16:59
Copy link
Copy Markdown
Contributor

@benesch benesch left a comment

Choose a reason for hiding this comment

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

LGTM modulo last two comments!

Comment thread src/ccsr/src/client.rs Outdated
Comment thread src/ccsr/src/client.rs Outdated
Comment on lines +422 to +426
if err.status() == Some(reqwest::StatusCode::NOT_FOUND) {
GetSubjectConfigError::SubjectNotFound
} else {
GetSubjectConfigError::Transport(err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh sorry I see, I misunderstood! Yes, huh, that does seem to be undocumented.

It looks like you've still got the 404 check in the branch above—I think we should just remove that since we'll never create a transport error with status 404!

Comment thread src/storage-client/src/sink.rs Outdated
}
Ok(())
}
Err(GetSubjectConfigError::SubjectLevelCompatibilityNotSet) => ccsr
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we might also want to set the subject compatibility level if we see a SubjectNotFound error? In my testing the CSR would never actually return "subject not found" rather than "subject compatibility level not set", but probably not ideal to rely on that behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sounds good, will set on both

Comment thread src/ccsr/src/client.rs Outdated
/// The requested subject does not exist.
SubjectNotFound,
/// The compatibility level for the subject has not been set.
SubjectLevelCompatibilityNotSet,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just realized this probably wants to be SubjectCompatibilityLevelNotSet! 😀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ah good catch!

Copy link
Copy Markdown
Contributor

@benesch benesch 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 just noticing one last thing in the docs. 🙈)

Comment thread doc/user/content/releases/v0.105.md Outdated
Comment thread src/storage-client/src/sink.rs Outdated
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