From 0553fa041bd5c4aaab9b475521919acc1a5748b2 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 7 Jul 2022 11:38:18 +0300 Subject: [PATCH] Parse geolix pool config as integers --- config/runtime.exs | 6 +++--- lib/plausible/helpers/config.ex | 15 +++++++++++++++ mix.lock | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index e94bf1f36..3defb7292 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -228,7 +228,7 @@ config :sentry, tags: %{app_version: app_version}, enable_source_code_context: true, root_source_code_path: [File.cwd!()], - hackney_pool_max_connections: get_var_from_path_or_env(config_dir, "SENTRY_POOL_SIZE") || 50 + hackney_pool_max_connections: get_int_from_path_or_env(config_dir, "SENTRY_POOL_SIZE", 50) config :logger, Sentry.LoggerBackend, capture_log_messages: true, @@ -405,8 +405,8 @@ config :kaffy, if config_env() != :test do config :geolix, pool: [ - size: get_var_from_path_or_env(config_dir, "GEOLIX_POOL_SIZE") || 5, - max_overflow: get_var_from_path_or_env(config_dir, "GEOLIX_POOL_MAX_OVERLFOW") || 10 + size: get_int_from_path_or_env(config_dir, "GEOLIX_POOL_SIZE", 5), + max_overflow: get_int_from_path_or_env(config_dir, "GEOLIX_POOL_MAX_OVERFLOW", 10) ], databases: [ %{ diff --git a/lib/plausible/helpers/config.ex b/lib/plausible/helpers/config.ex index 9fb9a9973..4640869ff 100644 --- a/lib/plausible/helpers/config.ex +++ b/lib/plausible/helpers/config.ex @@ -8,4 +8,19 @@ defmodule Plausible.ConfigHelpers do System.get_env(var_name, default) end end + + def get_int_from_path_or_env(config_dir, var_name, default \\ nil) do + var = get_var_from_path_or_env(config_dir, var_name) + + case var do + nil -> + default + + var -> + case Integer.parse(var) do + {int, ""} -> int + _ -> raise "Config variable #{var_name} must be an integer. Got #{var}" + end + end + end end diff --git a/mix.lock b/mix.lock index f287adb14..0d0a5305f 100644 --- a/mix.lock +++ b/mix.lock @@ -10,7 +10,7 @@ "certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"}, "chatterbox": {:hex, :ts_chatterbox, "0.11.0", "b8f372c706023eb0de5bf2976764edb27c70fe67052c88c1f6a66b3a5626847f", [:rebar3], [{:hpack, "~>0.2.3", [hex: :hpack_erl, repo: "hexpm", optional: false]}], "hexpm", "722fe2bad52913ab7e87d849fc6370375f0c961ffb2f0b5e6d647c9170c382a6"}, "clickhouse_ecto": {:git, "https://github.com/plausible/clickhouse_ecto.git", "43126c020f07b097c55a81f68a906019fd061f29", []}, - "clickhousex": {:git, "https://github.com/plausible/clickhousex", "17c8ad5031e8dd27c176e2f828d3cafa8c52a5f5", []}, + "clickhousex": {:git, "https://github.com/plausible/clickhousex", "490e9b2b3227abad4e68175f9dba114f83520837", []}, "combination": {:hex, :combination, "0.0.3", "746aedca63d833293ec6e835aa1f34974868829b1486b1e1cb0685f0b2ae1f41", [:mix], [], "hexpm", "72b099f463df42ef7dc6371d250c7070b57b6c5902853f69deb894f79eda18ca"}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, "comeonin": {:hex, :comeonin, "5.3.3", "2c564dac95a35650e9b6acfe6d2952083d8a08e4a89b93a481acb552b325892e", [:mix], [], "hexpm", "3e38c9c2cb080828116597ca8807bb482618a315bfafd98c90bc22a821cc84df"},