GithubHelp home page GithubHelp logo

Comments (10)

ananthakumaran avatar ananthakumaran commented on August 15, 2024 3

Any update on this issue?

Tesla seems to have updated the api, so one could pass the adapter options directly now Tesla.client(middleware, adapter). But this is still not exposed by GoogleApi.Gax.Connection.

We are currently working around the issue by configuring the adapter globally. But we really would like to avoid global config, as this means we can't use different adapter configs (like no proxy for internal services) for different client.

config :tesla,
  adapter: {Tesla.Adapter.Hackney, [pool: Client.BigQuery, proxy: {host, port}]}

from elixir-google-api.

chingor13 avatar chingor13 commented on August 15, 2024

Thanks Jose for the great suggestion!

Defining the connection API seems like an easy step to take. We picked Tesla for it's extensibility and multipart request handling but we're not doing a great job of surfacing it. We'd also like to make Tesla an implementation detail of the default connections (but document how to extend it). Currently, Tesla structs bleed out into the developers' code.

from elixir-google-api.

josevalim avatar josevalim commented on August 15, 2024

Great! I have also opened two issues on Tesla, in case you'd rather expose it: elixir-tesla/tesla#218 and elixir-tesla/tesla#219

from elixir-google-api.

teamon avatar teamon commented on August 15, 2024

DISCLAIMER: I'm obviously biased here

The way I've always imagined client libraries build around tesla is that they expose a way to pass a custom %Tesla.Client{} to add/change functionality (like fuse/timeout/retry/headers/adapter/etc).

If you need a dynamic client you could do something like:

# MyApi

def new(token, middleware \\ []) do
  Tesla.build_client([{Tesla.Middleware.Header, "Bearer #{token}"}] ++ middleware)
end

# app code
client = MyApi.new(token, my_custom_middleware)
MyApi.some_function(client)

So, instead of hiding tesla it is actually exposed as first-class citizen and out of the box compatible with 3rd party tesla extensions. For example, need caching? - plug in tesla_cache middleware into your custom client.

I agree tesla docs are not the best currently but we are working on them! ( elixir-tesla/tesla#228 )

from elixir-google-api.

josevalim avatar josevalim commented on August 15, 2024

@teamon this would be a valid approach as long as everything in Tesla can be done at runtime. Middleware are fine. However, you can't configure adapters at runtime, which is the reason why I opened this issue and the ones in Tesla.

The only way to make the adapter customizable with the current Tesla version would be if Google API added a global compile time configuration.

The other limitation is that it is unclear how to customize the adapters in Tesla. So if I need to tune hackney, I need to figure out how to go all the way from Google API -> Tesla -> Hackney, and that's not easy. As long as one of those contracts are well defined (Google API -> HTTP client) or (Tesla -> HTTP client), then we should be good to go.

from elixir-google-api.

teamon avatar teamon commented on August 15, 2024

You can override adapter in runtime, but it's not pretty and it needs to be improved a lot.

iex(1)> Tesla.get("https://httpbin.org/ip")
{:ok, %Tesla.Env{status: 200, ...}}

iex(2)> client = Tesla.build_adapter(fn env -> IO.inspect("Custom adapter") end)

iex(3)> Tesla.get(client, "https://httpbin.org/ip")
"Custom adapter"
# no request has been made

(Adapter is just the last middleware that does not call Tesla.run)

Regarding adapter customization - docs docs docs + best practices/tips & tricks

from elixir-google-api.

josevalim avatar josevalim commented on August 15, 2024

@teamon build_adapter has no documentation. So it is unclear if it is a private function that was accidentally public or something that is meant to be used. build_adapter also does not receive the client as argument, so I still unclear how to change the adapter of an existing client, which is likely what I would expect here.

In any case, the lack of documentation around those customizations are precisely what those issues are about. :) Given Tesla defaults to httpc, which I don't recommend for production usage, I would say replacing and customize adapters should be more prominently featured.

from elixir-google-api.

teamon avatar teamon commented on August 15, 2024

Yes, yes, and yes, all you say is (unfortunately) true.
Thanks for starting the discussion around it! I hope we can get it solved in the near future.

from elixir-google-api.

jmnsf avatar jmnsf commented on August 15, 2024

@ananthakumaran & others, you can specify a particular client for which the config applies. For example, for the DialogFlow client:

config :tesla, GoogleApi.Dialogflow.V2.Connection,
  adapter: {Tesla.Adapter.Hackney, [pool: :dialogflow]}

from elixir-google-api.

tielur avatar tielur commented on August 15, 2024

Currently found this issue when trying to define a new middleware for the Tesla client like adding the Tesla.Middleware.Timeout. Interested to see if that's possible in another way and/or the state of this issue.

from elixir-google-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.