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

feat: remove confluent-kafka as a hard dependency #26

Merged
merged 17 commits into from
Aug 19, 2022

Conversation

rgraber
Copy link
Contributor

@rgraber rgraber commented Aug 17, 2022

Description:
Remove confluent-kafka as a dependency in base.in. Instead, wrap all imports in a try...catch and log error messages if the library is not found.

Issue:
openedx/openedx-events#88

Installation instructions:
As of this PR, any service that uses event-bus-kafka will need to independently install confluent-kafka.

Testing instructions:

Follow the instructions in manual_testing.rst EXCEPT for the bit about installing confluent-kafka.
You should get Library confluent-kafka not available. Cannot create event producer. (or consumer).

In the cms shell, pip install confluent-kafka
You should then be able to go through manual_testing again and get the correct results.

make test in the event-bus-kafka repo itself should always work (without having to install confluent-kafka separately) since confluent-kafka is in the test dependencies.

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

Post merge:

  • Create a tag
  • Check new version is pushed to PyPI after tag-triggered build is
    finished.
  • Delete working branch (if not needed anymore)

Author concerns:
Deviated a bit from @robrap 's example of newrelic, where everything is in an if newrelic block. Instead, I used more early returns since I find that easier to read (rather than indenting entire methods). This does have the downside of making coverage.py upset since I have not been able to unit test those blocks. I'm not yet certain whether it's possible or whether we should just pragma: no-cover it or whether we should ignore it because the coverage check isn't mandatory.

Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

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

Generally looks good. Thanks.

from confluent_kafka import DeserializingConsumer, KafkaError
from confluent_kafka.schema_registry.avro import AvroDeserializer
except:
DeserializingConsumer = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider:

confluent_kafka = None

Would the code read better if everything just checked:

if confluent_kafka:

That's what we do for New Relic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Will go with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@robrap do you know of any ADRs or OEPs detailing how the decision was made to use this pattern for New Relic? Github code search is not forthcoming with any, but it'd be a useful reference if it exists.

Copy link
Contributor

Choose a reason for hiding this comment

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

No ADR. I think the code just reads cleanly. See example: https://github.com/openedx/edx-django-utils/blob/master/edx_django_utils/monitoring/internal/middleware.py#L160-L161. I think it would be reasonable to note in this ADR the pattern of code that we'd follow.

@rgraber rgraber force-pushed the rsgraber/conditional-imports branch from 8d5347e to 0b482fa Compare August 17, 2022 20:12
@rgraber rgraber marked this pull request as ready for review August 18, 2022 16:03
Then, later on, before any usage of `DeserializingConsumer`::

if not confluent_kafka:
warn("Confluent_kafka not installed")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we warn during import, if at all? Having lots of repeated warnings would be annoying for those that have no intent on using the feature. Or, is this only run by code that is clearly meant to be using the feature?

Copy link
Contributor

Choose a reason for hiding this comment

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

I do like the idea that this only warns on import, but the examples below use this pattern where the warning shows up when we try to use confluent_kafka. I'll leave things the way it is now, and then make a decision about this a bit later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only run by code that tries to use the feature. My worry is that, depending on usage, the import warning might be far away from the failure that will happen when someone tries to actually use the code.

requirements/test.in Outdated Show resolved Hide resolved
Co-authored-by: Tim McCormack <tmccormack@edx.org>
@rgraber rgraber added the event-bus Work related to the Event Bus. label Aug 18, 2022
@rgraber rgraber merged commit 701098b into main Aug 19, 2022
@rgraber rgraber deleted the rsgraber/conditional-imports branch August 19, 2022 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event-bus Work related to the Event Bus.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants