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

Correctly handle errors during initialization + code refactor #9626

Merged
merged 4 commits into from
Jul 23, 2021

Conversation

FlorianVeaux
Copy link
Member

No description provided.

@FlorianVeaux FlorianVeaux requested a review from a team as a code owner June 30, 2021 13:56
@codecov
Copy link

codecov bot commented Jun 30, 2021

Codecov Report

Merging #9626 (e8dd3cc) into master (fbedc42) will decrease coverage by 0.00%.
The diff coverage is 76.49%.

Flag Coverage Δ
kafka_consumer 80.95% <76.49%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@FlorianVeaux FlorianVeaux changed the title Refactor kafka_consumer Correctly handle errors during initialization + code refactor Jun 30, 2021


class LegacyKafkaCheck_0_10_2(AgentCheck):
class LegacyKafkaCheck_0_10_2(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not convinced this is a better approach for this case; can you explain your rationale for composition over inheritance?

Copy link
Member Author

Choose a reason for hiding this comment

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

  • Option 1 is to make LegacyKafkaCheck and NewKafkaCheck both inherit from KafkaConsumerCheck. This can't be done as the agent refuses to load KafkaConsumerCheck if it's subclassed anywhere.
  • Option 2 is to keep a class KafkaCheck and override the __new__ method to return a LegacyKafkaCheck instance in case a certain condition is found after connecting to Kafka. This is the current situation and it needs to be removed with the refactor. Indeed we can't retry checking that version condition by setting the check as a check_initialization, once the class is initialized we can't change it.
  • Option 3 is to make a KafkaConsumer main class that inherit from AgentCheck and this is the only class that can inherit from it. We then need a NewKafkaConsumer implementation and a LegacyKafkaCheck implementation. The common code can now live in KafkaConsumer.

With option 3 there are a few design possibilities, I decided to override the __getattr__ method because of the large number of calls to self.gauge, self.submit_metadata etc. that are happening in many places.

@FlorianVeaux FlorianVeaux merged commit 60ac6ae into master Jul 23, 2021
@FlorianVeaux FlorianVeaux deleted the flo/improve_kafka_c_init branch July 23, 2021 14:43
github-actions bot pushed a commit that referenced this pull request Jul 23, 2021
* Refactor kafka_consumer

* fixup

* fixup

* Address review 60ac6ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants