Repository navigation
Conversation
| indoc = "2.0" | ||
| kafka-protocol = { version = "0.18", default-features = false, features = ["broker", "client"] } | ||
| rstest = "0.26" | ||
| rustls = { version = "0.23", default-features = false, features = ["logging", "ring", "std", "tls12"] } |
There was a problem hiding this comment.
Note to self, check if we enable the LogTracer (to get the logs). In 0.24, rustls will enable tracing so we won't need a log bridge for that.
| if self.host.contains(':') { | ||
| write!(f, "[{}]:{}", self.host, self.port) | ||
| } else { | ||
| write!(f, "{}:{}", self.host, self.port) | ||
| } |
There was a problem hiding this comment.
nit: We should avoid positional (unnamed) interpolations.
Something like this reads nicer:
| if self.host.contains(':') { | |
| write!(f, "[{}]:{}", self.host, self.port) | |
| } else { | |
| write!(f, "{}:{}", self.host, self.port) | |
| } | |
| let Self { host, port } = self; | |
| if self.host.contains(':') { | |
| write!(f, "[{host}]:{port}") | |
| } else { | |
| write!(f, "{host}:{port}") | |
| } |
There was a problem hiding this comment.
To be even more sure, we could check by parsing the ipv6 address instead of looking for :.
| client_id: &str, | ||
| ) -> Result<Self> { | ||
| let tcp_stream = connect_tcp(address).await?; | ||
| let stream = match tls::client_config(security).context(TlsSnafu)? { |
There was a problem hiding this comment.
If tls::client_config is resolved once in KafkaAdminClient::connect, before the loop over the bootstrap servers, then a bad CA path fails there instead of surfacing as a Connect error for each server, and the PEM files are only read once per reconnect.
| const_format = "0.2" | ||
| futures = "0.3" | ||
| indoc = "2.0" | ||
| kafka-protocol = { version = "0.18", default-features = false, features = ["broker", "client"] } |
There was a problem hiding this comment.
Move the broker feature to dev-dependencies if/as it is only used for testing.
| } | ||
| _ => self.connect().await?, | ||
| }; | ||
| let response = connection.send(request, version).await.context(SendSnafu)?; |
There was a problem hiding this comment.
check_version could be exposed as a pub(crate) method on Connection and called in KafkaAdminClient::send before Connection::send (dropping the check inside Connection::send), so that a failed version check does not throw away a healthy connection. e.g.
// client.rs
async fn send<R: Request>(&mut self, request: R, version: i16) -> Result<R::Response> {
// return both here so that last_used can be used when putting the connection back into the pool
let (mut connection, last_used) = match self.connection.take() {
Some((connection, last_used)) if last_used.elapsed() < CONNECTION_MAX_IDLE => {
(connection, last_used)
}
_ => (self.connect().await?, Instant::now()),
};
// The check doesn't do any I/O, so the connection stays usable and can go back in the pool.
if let Err(source) = connection.check_version(R::KEY, version) {
self.connection = Some((connection, last_used));
return Err(Error::Send { source });
}
let response = connection.send(request, version).await.context(SendSnafu)?;
self.connection = Some((connection, Instant::now()));
Ok(response)
}
Description
Add a local
kafka-admincrate providing a Kafka client based onkafka-protocol,tokioandrustlsthat will be used by the Kafka agent.Supported functions by the client:
Definition of Done Checklist
Author
Reviewer
Acceptance
type/deprecationlabel & add to the deprecation scheduletype/experimentallabel & add to the experimental features tracker