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

Refactoring of topic handling in preparation of #22 #27

Merged
merged 18 commits into from
Aug 18, 2019

Conversation

MrTrustworthy
Copy link
Contributor

@MrTrustworthy MrTrustworthy commented Jul 7, 2019

Fixes absolutely Nothing #26

@MrTrustworthy MrTrustworthy changed the title WIP: Kafka topic creation in terraform style Refactoring of topic handling in preparation of #22 Jul 7, 2019
Copy link
Contributor

@swenzel swenzel left a comment

Choose a reason for hiding this comment

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

Since its all over the place, I'll comment it here. I'd keep the TopicController in the Cluster object. It's best to have one single object (i.e. cluster) that you can use as interface.
The TopicController should exist only once per cluster anyway and who is better to ensure this if not the cluster object itself?
The cluster object could serve as a factory for all Kafka resources so you don't have to repeat yourself.
Then you can create a cluster with some bootstrap servers (and later also credentials) and everything else can (and should) be handled from there.

self.port = port

@classmethod
def from_id(cls, cluster, broker_id) -> "Broker":
Copy link
Contributor

Choose a reason for hiding this comment

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

The constructor supports the exact same signature, so what's the benefit of this method?

return cls(cluster=cluster, broker_id=broker_id)

@classmethod
def from_attributes(cls, cluster, broker_id: int, host: str, port: int) -> "Broker":
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

@@ -233,7 +227,7 @@ def get_offsets(state, topic_name):
@click.argument("broker-id", required=True)
@pass_state
def describe_broker(state, broker_id):
broker = Broker(state.cluster, broker_id).describe()
broker = Broker.from_id(state.cluster, broker_id).describe()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd actually prefer state.cluster.get_broker(broker_id).describe()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the approach I'm working on, I'd use this as preparation to move this stuff to a BrokerController. See my comment at the bottom

@@ -258,9 +252,9 @@ def describe_consumergroup(state, consumer_id, verbose):
@get.command("brokers")
@pass_state
def get_brokers(state):
brokers = state.cluster.brokers
brokers = Broker.get_all(state.cluster)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to above: state.cluster.get_all_brokers() would be nicer.
By the way, brokers can have multiple endpoints. Guess by default we should use the one that esque is using. But would be good to have the possibility to list all endpoints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

s.A.

@MrTrustworthy
Copy link
Contributor Author

Since its all over the place, I'll comment it here. I'd keep the TopicController in the Cluster object. It's best to have one single object (i.e. cluster) that you can use as interface.
The TopicController should exist only once per cluster anyway and who is better to ensure this if not the cluster object itself?
The cluster object could serve as a factory for all Kafka resources so you don't have to repeat yourself.
Then you can create a cluster with some bootstrap servers (and later also credentials) and everything else can (and should) be handled from there.

I've also considered that, but decided against it in favour of the current approach. My thoughts behind that: I'd like to treat the Cluster as a "dumb" resource object similar to how the Topic should behave after this PR. The resource objects should only wrap the different clients and provide some basic utility functions. The TopicController just get's the Cluster as input, and can then create/change resources of that cluster as output. That's also how I'd structure further Controllers ex. for ConsumerGroups or Partitions.

I think this approach makes the View (the CLI) a little more verbose, but should make the separation between resources and controllers more explicit and hopefully testing/mocking easier as well.

But having the Cluster as god-object that manages all resources could also work, and I'm open to changing it to that approach if you think it would be better. We'll just have to agree on one architectural approach going forward.

@pytest.fixture()
def avro_producer(test_config: Config):
producer_config = test_config.create_confluent_config()
producer_config.update({"schema.registry.url": Config().schema_registry})
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be that you want test_config.schema_registry instead of Config().schema_registry ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's just in here because i merged in master :D

@swenzel
Copy link
Contributor

swenzel commented Aug 18, 2019

For the moment I'm okay with separating it. But personally I'd prefer a "god" object as you call it. It could be just a proxy. Imho its easier to have one object around where I can check the API using my IDE than to keep several where I first have to find and figure out how to create the one that does what I want. Looking from a usability perspective here.

@MrTrustworthy
Copy link
Contributor Author

Some of the newer changes also close #28 by simply not showing non-editable properties in esque edit topic. Still need a way to detect & abort/fail for esque apply

@MrTrustworthy
Copy link
Contributor Author

@swenzel If you want to do a follow-up PR to change it, go for it :)

@MrTrustworthy MrTrustworthy merged commit 4e44be2 into master Aug 18, 2019
@MrTrustworthy MrTrustworthy deleted the 22-kafka-topic-terraform-style branch August 18, 2019 17:07
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.

2 participants