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

refactor: Add a little testability, abstract a bit over broker kinds #74

Merged
merged 16 commits into from
Jan 20, 2022

Conversation

carols10cents
Copy link
Contributor

Connects to #49, in that it adds a tiny bit of testing around getting a new arbitrary broker connection to cache.

This also adds a bit of type info around different sources of broker connection, and fixes a subtle bug where broker id was being logged as None even though we had a broker ID from the topology.

Again recommended to review commit-by-commit.

I feel less confident about the value of these extractions and the new test. If the new test fails, it's likely to be a flaky failure too because of the randomness.

Looking at other code like the controller and partition leader caching, I think perhaps the broker caching trait could be reused, and then perhaps the maybe_retry functions could be shared more and tested more? Not sure yet though.

src/connection.rs Show resolved Hide resolved
src/connection.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@crepererum crepererum left a comment

Choose a reason for hiding this comment

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

The interface / abstraction point is good, I'm a bit confused about naming things (which IIRC is the 2nd hard problem of computer science).

This conflicts a bit w/ #72 but it shouldn't be too hard of either of us to rebase (depending on who goes first) since it's effectively only affecting the arguments that Connct::connection is going to pass through to Transport.

src/connection.rs Show resolved Hide resolved
src/connection.rs Outdated Show resolved Hide resolved
Comment on lines 573 to 589
struct FakeBrokerConn {
conn: Box<dyn Fn() -> Result<Arc<FakeConn>> + Send + Sync>,
}

#[derive(Debug, PartialEq)]
struct FakeConn;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The names confuse me a bit. What's the difference between a "fake broker conn(ection)" and a "fake conn(ection)"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeaaahhh I didn't put a whole lot of thought into the names 😅 I renamed FakeBrokerConn to FakeBrokerRepresentation, is that better?

@@ -37,14 +37,79 @@ pub enum Error {

pub type Result<T, E = Error> = std::result::Result<T, E>;

/// How to connect to a `Transport`
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you connect to a "transport", then why is async fn connection returning R: Request? Is this a bit of a naming clash because Transport was already taken by crate::connection::transport::Transport? Maybe we can call Request a RequestHandler. I think nouns are better for traits and structs and verbs rather for functions. Same goes for Connect::connection which I would rather call ConnectionHandler::connect, esp. since the method actually establishes a new connection rather than using a cached one (we currently don't cache connections at this specific layer and I think we don't want to because Kafka doesn't really multiplex TCP connection requests but only allows in-order pipelining).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, these names were not great. I've taken your suggestions here, how does it look now?

@carols10cents carols10cents force-pushed the cn/explore branch 2 times, most recently from a88db1f to 71a6007 Compare January 20, 2022 17:36
@carols10cents
Copy link
Contributor Author

Because you approved, I'm going to merge this. If we need to adjust names more, I'm happy to do so in a future PR!

@carols10cents carols10cents added the automerge Instruct kodiak to merge the PR label Jan 20, 2022
@kodiakhq kodiakhq bot merged commit e100572 into main Jan 20, 2022
@carols10cents carols10cents deleted the cn/explore branch January 20, 2022 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Instruct kodiak to merge the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants