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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predetermine supported API versions before making requests #50

Closed
peter-evans opened this issue Jul 21, 2021 · 6 comments
Closed

Predetermine supported API versions before making requests #50

peter-evans opened this issue Jul 21, 2021 · 6 comments

Comments

@peter-evans
Copy link

Thank you for this excellent library 馃

I'm working on a small client to handle some admin requests and I'm trying to get my head around how to handle different Kafka API versions for the features I would like to support. Take for example the command you have to alter config in kcl here. I notice it requires the user to opt-in with --inc for use of the incremental method introduced in Kafka 2.3.0.

My question is, is there a way to predetermine what API version the broker(s) support and in a client automatically chose to issue a IncrementalAlterConfigsRequest or AlterConfigsRequest?

@twmb
Copy link
Owner

twmb commented Jul 21, 2021

There is, but it's a pretty big risk to have any fallback to the old AlterConfigsRequest.

What you could do is to send ApiVersionsRequest, pass the response to kversion.FromApiVersionsResponse, and then check HasKey(<request key>).

If the response does not have the incremental key, then you could fallback to non-incremental.

The big risk is that AlterConfigs does not preserve any prior configuration, and even if you DescribeConfigs beforehand to try to preserve configuration, DescribeConfigs does not return secrets. Secrets cannot be preserved with AlterConfigs -- you may have seen this in the kcl repo where I have a prompt for configuration that will be lost.

@peter-evans
Copy link
Author

Thank you! I'll take a look at using ApiVersionsRequest as you suggested.

I understand your explanation of the risk and I'll make sure it's clear to the user if my client is going to do something that might be destructive. 馃憤

@twmb
Copy link
Owner

twmb commented Jul 22, 2021

One other small risk is if your ApiVersions request goes to a new broker in a cluster that supports incremental update, while old brokers that do not are still in the cluster. This gets really tricky to solve correctly and IMO it's not worth it; Kafka authors have seen the problem here and are actually introducing a new "supported features" bit in MetadataResponse, but that's very new and they return nothing in it yet.

Happy to have helped, and happy you're checking out this library!

@peter-evans
Copy link
Author

One other small risk is if your ApiVersions request goes to a new broker in a cluster that supports incremental update, while old brokers that do not are still in the cluster.

In this situation, if the client chose to use incremental update and the request went to a broker that didn't support the feature, do you know off-hand what would happen? Would it return one of these errors, perhaps INVALID_REQUEST?

@twmb
Copy link
Owner

twmb commented Jul 22, 2021

Kafka actually closes the connection, and the client has no knowledge of why. The client will retry, if it retries enough it should hit the broker that supported the request anyway. But, if you're trying to modify configs on the broker that doesn't support the request, the connection will be closed a bunch and then the client will hit the request retry limit.

@peter-evans
Copy link
Author

Um, sounds complicated. I can see why you think it's not worth it!

Thanks for the info. Very helpful.

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

No branches or pull requests

2 participants