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

Consider supporting PUBSUB_EMULATOR_HOST #45

Open
mcrumm opened this issue Jan 25, 2020 · 10 comments
Open

Consider supporting PUBSUB_EMULATOR_HOST #45

mcrumm opened this issue Jan 25, 2020 · 10 comments

Comments

@mcrumm
Copy link
Collaborator

mcrumm commented Jan 25, 2020

There's a lot of prior art for overriding authentication in the presence of an PUBSUB_EMULATOR_HOST environment variable. I'm opening this issue to get feedback on supporting it for the default GoogleApiClient implementation.

Basically we'd look for the var at runtime, and when present, use its value as the base url and set a fake token generator.

This will need to be per-implementation, but we have prepare_to_connect on the Client behaviour for that.

The only thing I'm not wild about is that the GoogleApiClient implementation would need to reach into the :google_api_pub_sub app config to override the base_url.

Still, personally I'd like to see this implemented, as the required configuration steps are non-trivial, especially if you're coming from somewhere like the Python PubSub client, where you can just set an env var to use the emulator.

Original comment:
peburrows/goth#56 (comment)

/cc @matehat

@josevalim
Copy link
Member

Is this something we could push to be supported upstream?

@mcrumm
Copy link
Collaborator Author

mcrumm commented Jan 25, 2020

It's worth a shot! Upstream I'd like to see more runtime config for the Tesla client. That's probably 90% of the difficulty right now.

@josevalim
Copy link
Member

I opened up an issue a long time ago on Tesla exactly about the compile time config issues in Google APIs. Those issues have been addressed, so it may be a matter of updating Tesla and moving away from the compile time API.

@mcrumm
Copy link
Collaborator Author

mcrumm commented Jan 25, 2020

Ah, yes - and the Google API issue is still open: googleapis/elixir-google-api#98 :-)

The Tesla version in latest is relatively up-to-date (v1.2); the problem right now is clients use GoogleApi.Gax.Connection, which only generates new/0 and new/1.

A function on the Connection (maybe new/2?) that exposes more Tesla.client/2 options would allow us to override the HTTP adapter in the proper way, and possibly inject additional middleware (like Telemetry).

For emulator support directly in the client, perhaps the new/* functions need to be overridable when you use Connection so that clients in general, but PubSub specifically, could override the base_url at runtime using the env var. Thoughts?

(Edited to clarify needing to override base_url at runtime)

@josevalim
Copy link
Member

Yeah, something along those lines. Maybe we should not make all new/* but rather have then build on top of a single build_client overridable one.

FWIW, we can always force them to be overridable By calling defoverridable ourselves, but having both scenarios supported upstream would be nicer. :)

@michaelst
Copy link
Contributor

michaelst commented Dec 2, 2020

This will at least allow you to use the emulator by configuring it in dev.exs, you could use this to pull from the env var.

config :google_api_pub_sub, base_url: System.get_env("PUBSUB_EMULATOR_HOST", "http://localhost:8085")

@christopherdbull
Copy link

Is there any progress on this? I've tried @michaelst's suggestion but it's not working for me - I can't see anywhere in the code that the base_url is read from Config

@rockneurotiko
Copy link
Contributor

I think that config workaround should work:

The google_api_pub_sub connection setups the default base_url here: https://github.com/googleapis/elixir-google-api/blob/master/clients/pub_sub/lib/google_api/pub_sub/v1/connection.ex#L34

And Gax.Connection allow to override it with the configuration:
https://github.com/googleapis/elixir-google-api/blob/master/clients/gax/lib/google_api/gax/connection.ex#L27

@christopherdbull
Copy link

Ok, more digging and looks like this is it: peburrows/goth#56 Goth still tried to get the token, but the config actually worked. Thanks for your help, but would be good if broadway could support this automatically.

@lessless
Copy link

lessless commented Oct 4, 2022

I'd love to see PUBSUB_EMULATOR_HOST supported out of the box.
Right now it's my second hour digging into connecting Broadway to the emulator and I'm still somewhere half-way there.

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

No branches or pull requests

6 participants