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

feature: add support for GCP pub sub emulator sink #794

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

girishramnani
Copy link
Contributor

@girishramnani girishramnani commented Dec 31, 2024

Closes #791

  • Add the use emulator switch for sink
  • Add the connection url input when selected the use emulator switch
  • Use the connection url in the pub sub client

Overall providing support for the GCP PubSub Emulator in the sink.

@girishramnani girishramnani marked this pull request as draft December 31, 2024 23:19
Copy link
Contributor

@acco acco left a comment

Choose a reason for hiding this comment

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

Great work, @girishramnani! Impressed with the thoroughness here.

See comments in-line. If you can, sign off your PR with make signoff - see instructions in CONTRIBUTING.md

Please test to make sure it works with an emulator GCP. Also, make sure both creates and edits work (and that during edits, you can switch emulator on/off)

Also, might make sense to add a test to test/sequin/gcp_pubsub_test.exs? Ask Claude Sonnet to help :)

assets/svelte/consumers/SinkGcpPubsubForm.svelte Outdated Show resolved Hide resolved
bind:checked={form.sink.use_emulator}
onCheckedChange={toggleEmulator}
/>
<Label for="use-emulator" class="align-text-top">Use Emulator</Label>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<Label for="use-emulator" class="align-text-top">Use Emulator</Label>
<Label for="use-emulator" class="align-text-top">Use emulator</Label>

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add an info popover here that describes what the emulator is? You can see examples of info popovers elsewhere in the codebase. The copy:

The GCP Pub/Sub emulator lets you run Pub/Sub locally for dev and testing purposes. [Learn more](https://cloud.google.com/pubsub/docs/emulator)

Learn more should be a target=_blank link

assets/svelte/consumers/SinkGcpPubsubForm.svelte Outdated Show resolved Hide resolved
assets/svelte/consumers/SinkGcpPubsubForm.svelte Outdated Show resolved Hide resolved
@@ -122,6 +122,8 @@ export type GcpPubsubConsumer = BaseConsumer & {
project_id: string;
topic_id: string;
connection_id: string;
use_emulator: false;
connection_url: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
connection_url: string;
emulator_base_url: string;

Copy link
Contributor

Choose a reason for hiding this comment

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

Please make this change everywhere below

lib/sequin/consumers/gcp_pubsub_sink.ex Outdated Show resolved Hide resolved
<p class="text-destructive text-sm">{errors.sink.emulator_url}</p>
{/if}
</div>
{/if}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we hide credentials field below when the emulator is enabled? If it's unused, we should hide it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good idea

lib/sequin/transforms/transforms.ex Show resolved Hide resolved
{"authorization", "Bearer #{token}"},
{"content-type", "application/json"}
]
pubsub_base_url = get_pubsub_base_url(client)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can do this in-line:

Suggested change
pubsub_base_url = get_pubsub_base_url(client)
base_url = Map.get(client.req_opts, :base_url, @pubsub_base_url)

Comment on lines +205 to +209
defp get_pubsub_headers(%Client{} = client) do
base_url = Map.get(client.req_opts, :base_url)

# if there is no base url then we are using the production gcp
if is_nil(base_url) do
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now, this uses the presence of base_url in req_opts to determine if we should add auth headers.

How about instead we just only add auth headers if Client.credentials is not nil?

Copy link
Contributor

Choose a reason for hiding this comment

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

Below, in authenticated_request, you can do:

headers = [{"content-type", "application/json"}] |> maybe_put_auth_headers(client)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Someone might just keep the credentials.
Imagine a user flow.
They added the pub sub details and that didn’t work - so they selected the emulator but never removed to credentials.

Copy link
Contributor

Choose a reason for hiding this comment

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

@girishramnani That's a good point. In that case, I think we should nilify the credentials - perhaps in the conditional_ changeset function you added?

That way, there aren't credentials "hidden" in the sink. Would be surprising later to edit the sink, turn off the emulator, and see that there were credentials in there the whole time!

Basically, just trying to have as few things know about the emulator/base URL as possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that would be best

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.

Support GCP Pubsub emulator
2 participants