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: add support for google-cloud-pubsub closes #25 #30

Merged

Conversation

Mohsin-Ul-Islam
Copy link
Contributor

No description provided.

@Mohsin-Ul-Islam Mohsin-Ul-Islam changed the title feat: add support for google-cloud-pubsub feat: add support for google-cloud-pubsub closes #25 Aug 10, 2022
@melvinkcx
Copy link
Owner

melvinkcx commented Aug 16, 2022

@Mohsin-Ul-Islam Hi, thank you for your contribution =) Would you please also include test cases to cover the usage of the handler?

@melvinkcx melvinkcx added the missing test cases Test cases are needed label Aug 16, 2022
@Mohsin-Ul-Islam
Copy link
Contributor Author

@melvinkcx Hi, I have added a test for GCP pubsub handler. I couldn't find a mock library for google cloud pubsub python client, so I am testing it with google cloud pubsub emulator. More information on emulator can be found here: https://cloud.google.com/pubsub/docs/emulator

In order to spin up and tear down docker container I am using testcontainers library to spin up our pubsub emulator. I am a beginner in open source, so any guidance would be appreciated. Thanks a lot!

@melvinkcx
Copy link
Owner

@Mohsin-Ul-Islam I took a look at your test cases. The approach you take (integration tests) will significantly inflate the dependencies required to run the tests and for development (Docker, etc). I would suggest you mock the google clients yourself, and verify that the methods (self._client.publish(self._topic_path, self.format_message(event)), etc) are invoked correctly instead.

@melvinkcx
Copy link
Owner

The tests are failing, you might need to update the "Install dependencies" step of the github workflow .github/workflows/tests.yml as well

@Mohsin-Ul-Islam
Copy link
Contributor Author

Sure, I will mock the google cloud pubsub client.

Signed-off-by: Mohsin-Ul-Islam <mohsinulislam180@gmail.com>
@melvinkcx
Copy link
Owner

melvinkcx commented Aug 28, 2022

Hi, @Mohsin-Ul-Islam, it seems like the test is now fixed. Would you please confirm if the PR is ready for review? =)

@Mohsin-Ul-Islam
Copy link
Contributor Author

@melvinkcx yes the PR is ready for review. Thanks!

Copy link
Owner

@melvinkcx melvinkcx left a comment

Choose a reason for hiding this comment

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

Hi @Mohsin-Ul-Islam, thanks for contributing. Please check the comments I added. Also, please update the README to document the usage of your handler =)

return json.dumps(event, default=str)


class GoogleCloudPubSubHandler(BaseEventHandler):
Copy link
Owner

Choose a reason for hiding this comment

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

@Mohsin-Ul-Islam I believe there will be needs to forward events to multiple topics depending on the event name, as some folks using AWS SNS (the pub/sub offering by AWS) have indicated.

What about renaming GoogleCloudPubSubHandler to GoogleCloudSimplePubSubHandler to allow room in the future to implement a GCP pub/sub handler with more advanced routing capabilities?

I think it'd be better if we rename it to something such as GoogleCloudSimplePubSubHandler to indicate that the proces

# Publish messages as soon as there are max_messages
# or 1 second is passed
self._batch_settings = pubsub_v1.types.BatchSettings(
max_messages=self._max_batch_size, max_latency=1
Copy link
Owner

Choose a reason for hiding this comment

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

We should allow the users to customise their BatchSettings:

This is a suggestion:


    def __init__(
        self,
        project_id: str,
        topic_id: str,
        max_batch_size: int = 1000,
        batch_settings_kwargs: Dict[str, Any] = None,
        serializer: Callable[[Event], str] = None,
    ) -> None:
        ...
        self._batch_settings = pubsub_v1.types.BatchSettings(
            max_messages=self._max_batch_size, **batch_settings_kwargs
        )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, @melvinkcx, thank you so much for the review. The changes requested makes perfect sense. I will update the PR.

@melvinkcx melvinkcx removed the missing test cases Test cases are needed label Aug 28, 2022
Copy link
Owner

@melvinkcx melvinkcx left a comment

Choose a reason for hiding this comment

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

Thank you for your patience. LGTM, approved!

@melvinkcx melvinkcx merged commit 5d8cf86 into melvinkcx:dev Sep 6, 2022
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.

None yet

2 participants