analytics icon indicating copy to clipboard operation
analytics copied to clipboard

Migrate HTTPoison to Finch

Open manusajith opened this issue 3 years ago • 4 comments
trafficstars

manusajith avatar Jul 25 '22 15:07 manusajith

BundleMon

Unchanged files (7)
Status Path Size Limits
:white_check_mark: static/css/app.css
515.1KB -
:white_check_mark: static/js/dashboard.js
287.69KB -
:white_check_mark: static/js/app.js
12.13KB -
:white_check_mark: static/js/embed.host.js
5.58KB -
:white_check_mark: static/js/embed.content.js
5.06KB -
:white_check_mark: tracker/js/plausible.js
748B -
:white_check_mark: static/js/applyTheme.js
314B -

No change in files bundle size

Final result: :white_check_mark:

View report in BundleMon website ➡️


Current branch size history | Target branch size history

bundlemon[bot] avatar Jul 25 '22 15:07 bundlemon[bot]

I was talking to @ukutaht about this change, and I think that https://github.com/elixir-tesla/tesla would be a better replacement for HTTPoison. Tesla supports multiple adapters, meaning that we could use Tesla + Finch. It ships with built-in support for test mocks without having to do dependency injection, and most importantly a request retrying feature that can be really useful for us. The con is having another layer of abstraction, but I see more pros than cons.

What are your thoughts?

vinibrsl avatar Jul 27 '22 17:07 vinibrsl

I was talking to @ukutaht about this change, and I think that https://github.com/elixir-tesla/tesla would be a better replacement for HTTPoison. Tesla supports multiple adapters, meaning that we could use Tesla + Finch. It ships with built-in support for test mocks without having to do dependency injection, and most importantly a request retrying feature that can be really useful for us. The con is having another layer of abstraction, but I see more pros than cons.

What are your thoughts?

I had considered Tesla and also Req

Req is still in early phases of development, so it could introduce breaking changes.

Tesla has too many abstractions imho, and the community is also somewhat shifting towards using Finch(for at least the newer code/libraries etc).

re: request retying, I am not sure some of the places where we use http libraries would benefit from retries.

re: tests/mocks - I was considering to use bypass, but did not add it to this PR, as I wanted to keep the changes specific to the adapter.

manusajith avatar Jul 27 '22 18:07 manusajith

Tesla has too many abstractions imho

In general I'm quite averse to introducing new libraries and layers of indirection as well. I liked the Tesla suggestion because it would simplify testing and retries (which I think would be useful in many cases).

@manusajith Bypass seems to send stuff over an actual TCP connection? I really like that because it also exercises the client library itself as opposed to mocking it out. I have way more confidence in tests like that. The only thing we'd need to inject is the URL of the server to talk to which is a good idea to parameterize in any case.

It's a cool suggestion, even if we use Tesla I would prefer to use something like Bypass to get more of the system under test. Then Tesla starts losing some of its value.

I suggested retries as a way to reduce timeout errors:

https://sentry.plausible.io/organizations/sentry/issues/640 https://sentry.plausible.io/organizations/sentry/issues/295 https://sentry.plausible.io/organizations/sentry/issues/1799

etc.

Network requests can never be expected to be 100% reliable. If we're updating someone's subscription for example, I think it's a better experience for the customer if we retry the request automatically instead of them seeing an error and having to retry manually. It would also fall under the umbrella of 'reducing sentry errors'. I don't think every single HTTP request should be retried, we need to decide case-by-case.

I've found that for the GA imports we already do 5 retries before giving up. Even if we don't change any behaviour, it would be nice to encapsulate that logic in the Plausible.HTTPClient so we can reuse it elsewhere.

So in the end, if we use Bypass, then the only thing we would get by using Tesla is retry logic which we already have implemented in ~5 lines of code. I don't think it's worth it.

ukutaht avatar Jul 28 '22 10:07 ukutaht

@ukutaht this is ready for another review now.

manusajith avatar Aug 11 '22 11:08 manusajith

Thanks @manusajith

ukutaht avatar Aug 15 '22 07:08 ukutaht