Make Finch pools lighter for self-hosting (#2250)

* Make Finch pools lighter

* Use standard http1 Finch pools
pull/2259/head
Uku Taht 4 years ago committed by GitHub
parent 5c0a74dc16
commit 3d54b88f0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -372,12 +372,6 @@ config :plausible, :hcaptcha,
sitekey: hcaptcha_sitekey,
secret: hcaptcha_secret
config :plausible, Plausible.Finch,
default_pool_size: get_int_from_path_or_env(config_dir, "DEFAULT_FINCH_POOL_SIZE", 50),
default_pool_count: get_int_from_path_or_env(config_dir, "DEFAULT_FINCH_POOL_COUNT", 1),
sentry_pool_size: get_int_from_path_or_env(config_dir, "SENTRY_FINCH_POOL_SIZE", 50),
sentry_pool_count: get_int_from_path_or_env(config_dir, "SENTRY_FINCH_POOL_COUNT", 1)
config :plausible, Plausible.Sentry.Client,
finch_request_opts: [
pool_timeout: get_int_from_path_or_env(config_dir, "SENTRY_FINCH_POOL_TIMEOUT", 5000),

@ -41,41 +41,53 @@ defmodule Plausible.Application do
end
defp finch_pool_config() do
config = Application.fetch_env!(:plausible, Plausible.Finch)
pool_config = %{
:default => [size: config[:default_pool_size], count: config[:default_pool_count]],
"https://vendors.paddle.com" => [
protocol: :http2,
count: 50,
conn_opts: [transport_opts: [timeout: 15_000]]
],
"https://www.googleapis.com" => [
protocol: :http2,
count: 200,
conn_opts: [transport_opts: [timeout: 15_000]]
],
"https://analyticsreporting.googleapis.com" => [
protocol: :http2,
count: 200,
conn_opts: [transport_opts: [timeout: 15_000]]
],
base_config = %{
"https://icons.duckduckgo.com" => [
protocol: :http2,
count: 100,
conn_opts: [transport_opts: [timeout: 15_000]]
]
}
sentry_dsn = Application.get_env(:sentry, :dsn)
base_config
|> maybe_add_sentry_pool()
|> maybe_add_paddle_pool()
|> maybe_add_google_pools()
end
defp maybe_add_sentry_pool(pool_config) do
case Application.get_env(:sentry, :dsn) do
dsn when is_binary(dsn) ->
Map.put(pool_config, dsn, size: 50)
_ ->
pool_config
end
end
defp maybe_add_paddle_pool(pool_config) do
paddle_conf = Application.get_env(:plausible, :paddle)
cond do
paddle_conf[:vendor_id] && paddle_conf[:vendor_auth_code] ->
Map.put(pool_config, Plausible.Billing.PaddleApi.vendors_domain(),
conn_opts: [transport_opts: [timeout: 15_000]]
)
true ->
pool_config
end
end
defp maybe_add_google_pools(pool_config) do
google_conf = Application.get_env(:plausible, :google)
cond do
google_conf[:client_id] && google_conf[:client_secret] ->
pool_config
|> Map.put(google_conf[:api_url], conn_opts: [transport_opts: [timeout: 15_000]])
|> Map.put(google_conf[:reporting_api_url], conn_opts: [transport_opts: [timeout: 15_000]])
if is_binary(sentry_dsn) do
Map.put(pool_config, sentry_dsn,
size: config[:sentry_pool_size],
count: config[:sentry_pool_count]
)
else
pool_config
true ->
pool_config
end
end

Loading…
Cancel
Save