From 71f3cc11965a80029458c8a0b6368b5f32cbabba Mon Sep 17 00:00:00 2001 From: unnawut Date: Fri, 7 Aug 2020 19:46:22 +0700 Subject: [PATCH 1/7] feat: configurable DB pool size, queue target and queue interval --- .../release_tasks/set_db_pool.ex | 67 +++++++++++++ .../release_tasks/set_db_pool_test.exs | 93 +++++++++++++++++++ config/config.exs | 10 +- 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_db_pool.ex create mode 100644 apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs diff --git a/apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_db_pool.ex b/apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_db_pool.ex new file mode 100644 index 0000000000..cff4942ed9 --- /dev/null +++ b/apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_db_pool.ex @@ -0,0 +1,67 @@ +# Copyright 2019-2019 OmiseGO Pte Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +defmodule OMG.WatcherInfo.ReleaseTasks.SetDbPool do + @moduledoc false + @behaviour Config.Provider + require Logger + + @app :omg_watcher_info + @config_key OMG.WatcherInfo.DB.Repo + + # Note that we're setting these configs directly into Ecto.Repo's implementation, + # so the config naming deviates with the env var names in order to align with Ecto.Repo. + # See: https://hexdocs.pm/db_connection/DBConnection.html#start_link/2-queue-config + @mapping [ + # {env_var, config_name} + {"WATCHER_INFO_DB_POOL_SIZE", :pool_size}, + {"WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS", :queue_target}, + {"WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS", :queue_interval} + ] + + def init(args) do + args + end + + def load(config, _args) do + _ = on_load() + configs = [{@config_key, load_repo_configs(@app, @mapping)}] + + Config.Reader.merge(config, [{@app, configs}]) + end + + # Returns: + # [ + # pool_size: 10, + # queue_target: 50, + # queue_interval: 1000 + # ] + defp load_repo_configs(app, mapping) do + Enum.map(mapping, fn {env_var, config_name} -> + default = Application.get_env(app, config_name) + value = env_var |> System.get_env() |> validate_integer(default) + _ = Logger.info("CONFIGURATION: App: #{@app} Key: #{config_name} Value: #{inspect(value)}.") + + {config_name, value} + end) + end + + defp validate_integer(nil, default), do: default + defp validate_integer(value, _default) when is_binary(value), do: String.to_integer(value) + + defp on_load() do + _ = Application.ensure_all_started(:logger) + _ = Application.load(@app) + end +end diff --git a/apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs b/apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs new file mode 100644 index 0000000000..8f6899bfe4 --- /dev/null +++ b/apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs @@ -0,0 +1,93 @@ +# Copyright 2019-2020 OmiseGO Pte Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +defmodule OMG.WatcherInfo.ReleaseTasks.SetDbPoolTest do + use ExUnit.Case, async: true + alias OMG.WatcherInfo.ReleaseTasks.SetDbPool + + @app :omg_watcher_info + @config_key OMG.WatcherInfo.DB.Repo + + describe "WATCHER_INFO_DB_POOL_SIZE" do + test "sets the repo's pool_size to WATCHER_INFO_DB_POOL_SIZE" do + assert load_and_fetch("WATCHER_INFO_DB_POOL_SIZE", "123", :pool_size) == 123 + :ok = System.delete_env("WATCHER_INFO_DB_POOL_SIZE") + end + + test "uses the default pool_size value if WATCHER_INFO_DB_POOL_SIZE is not defined" do + default_value = Application.get_env(@app, :pool_size) + assert load_and_fetch("WATCHER_INFO_DB_POOL_SIZE", nil, :pool_size) == default_value + :ok = System.delete_env("WATCHER_INFO_DB_POOL_SIZE") + end + + test "fails if WATCHER_INFO_DB_POOL_SIZE is not a valid stringified integer" do + assert catch_error(load_and_fetch("WATCHER_INFO_DB_POOL_SIZE", "not integer", :pool_size)) == :badarg + :ok = System.delete_env("WATCHER_INFO_DB_POOL_SIZE") + end + end + + describe "WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS" do + test "sets the repo's queue_target to WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS" do + assert load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS", "123", :queue_target) == 123 + :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS") + end + + test "uses the default queue_target value if WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS is not defined" do + default_value = Application.get_env(@app, :queue_target) + assert load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS", nil, :queue_target) == default_value + :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS") + end + + test "fails if WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS is not a valid stringified integer" do + assert catch_error(load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS", "not integer", :queue_target)) == :badarg + :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS") + end + end + + describe "WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS" do + test "sets the repo's queue_interval to WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS" do + assert load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS", "123", :queue_interval) == 123 + :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS") + end + + test "uses the default queue_interval value if WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS is not defined" do + default_value = Application.get_env(@app, :queue_interval) + assert load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS", nil, :queue_interval) == default_value + :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS") + end + + test "fails if WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS is not a valid stringified integer" do + assert catch_error(load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS", "not integer", :queue_interval)) == :badarg + :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS") + end + end + + defp load_and_fetch(env_name, nil, config_name) do + :ok = System.delete_env(env_name) + config = SetDbPool.load([], []) + + fetch(config, config_name) + end + + defp load_and_fetch(env_name, env_value, config_name) do + :ok = System.put_env(env_name, env_value) + config = SetDbPool.load([], []) + + fetch(config, config_name) + end + + defp fetch(config, config_name) do + config |> Keyword.fetch!(@app) |> Keyword.fetch!(@config_key) |> Keyword.fetch!(config_name) + end +end diff --git a/config/config.exs b/config/config.exs index 25030c6cd1..fa9db39443 100644 --- a/config/config.exs +++ b/config/config.exs @@ -187,7 +187,15 @@ config :omg_watcher_info, OMG.WatcherInfo.DB.Repo, connect_timeout: 180_000, url: "postgres://omisego_dev:omisego_dev@localhost/omisego_dev", migration_timestamps: [type: :timestamptz], - telemetry_prefix: [:omg, :watcher_info, :db, :repo] + telemetry_prefix: [:omg, :watcher_info, :db, :repo], + # Establish a maximum of `:pool_size` DB connections. Wait at most `:queue_target` for a connection. + # If all connections checked out during a `:queue_interval` takes more than `:queue_target`, + # then we double the `:queue_target`. If checking out connections take longer than the new target, + # then we start dropping messages. + # See: https://hexdocs.pm/db_connection/DBConnection.html#start_link/2-queue-config + pool_size: 10, + queue_target: 50, + queue_interval: 1000 config :omg_watcher_info, OMG.WatcherInfo.Tracer, service: :ecto, From cce83367f68cff405702d40765178a0cd6031b65 Mon Sep 17 00:00:00 2001 From: unnawut Date: Mon, 10 Aug 2020 14:35:40 +0700 Subject: [PATCH 2/7] fix: add release task to release config --- mix.exs | 1 + 1 file changed, 1 insertion(+) diff --git a/mix.exs b/mix.exs index 52312419c2..df7a049f0d 100644 --- a/mix.exs +++ b/mix.exs @@ -94,6 +94,7 @@ defmodule OMG.Umbrella.MixProject do {OMG.Watcher.ReleaseTasks.SetTracer, []}, {OMG.Watcher.ReleaseTasks.SetApplication, [release: :watcher_info, current_version: current_version()]}, {OMG.WatcherInfo.ReleaseTasks.SetDB, []}, + {OMG.WatcherInfo.ReleaseTasks.SetDbPool, []}, {OMG.WatcherInfo.ReleaseTasks.SetTracer, []} ] ], From 4a0cca41732bd5ed666e2f7aa5a0c99886b9862a Mon Sep 17 00:00:00 2001 From: unnawut Date: Mon, 10 Aug 2020 14:35:52 +0700 Subject: [PATCH 3/7] style: mix format --- .../omg_watcher_info/release_tasks/set_db_pool_test.exs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs b/apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs index 8f6899bfe4..2bed7cf246 100644 --- a/apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs +++ b/apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs @@ -50,7 +50,9 @@ defmodule OMG.WatcherInfo.ReleaseTasks.SetDbPoolTest do end test "fails if WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS is not a valid stringified integer" do - assert catch_error(load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS", "not integer", :queue_target)) == :badarg + assert catch_error(load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS", "not integer", :queue_target)) == + :badarg + :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS") end end @@ -68,7 +70,9 @@ defmodule OMG.WatcherInfo.ReleaseTasks.SetDbPoolTest do end test "fails if WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS is not a valid stringified integer" do - assert catch_error(load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS", "not integer", :queue_interval)) == :badarg + assert catch_error(load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS", "not integer", :queue_interval)) == + :badarg + :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS") end end From f0c7de17f0a42d538e7b2c18fadf6b0259ea3444 Mon Sep 17 00:00:00 2001 From: unnawut Date: Mon, 10 Aug 2020 14:57:45 +0700 Subject: [PATCH 4/7] feat: configure runtime env vars through releases.exs --- config/config.exs | 10 +--------- config/releases.exs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 config/releases.exs diff --git a/config/config.exs b/config/config.exs index fa9db39443..25030c6cd1 100644 --- a/config/config.exs +++ b/config/config.exs @@ -187,15 +187,7 @@ config :omg_watcher_info, OMG.WatcherInfo.DB.Repo, connect_timeout: 180_000, url: "postgres://omisego_dev:omisego_dev@localhost/omisego_dev", migration_timestamps: [type: :timestamptz], - telemetry_prefix: [:omg, :watcher_info, :db, :repo], - # Establish a maximum of `:pool_size` DB connections. Wait at most `:queue_target` for a connection. - # If all connections checked out during a `:queue_interval` takes more than `:queue_target`, - # then we double the `:queue_target`. If checking out connections take longer than the new target, - # then we start dropping messages. - # See: https://hexdocs.pm/db_connection/DBConnection.html#start_link/2-queue-config - pool_size: 10, - queue_target: 50, - queue_interval: 1000 + telemetry_prefix: [:omg, :watcher_info, :db, :repo] config :omg_watcher_info, OMG.WatcherInfo.Tracer, service: :ecto, diff --git a/config/releases.exs b/config/releases.exs new file mode 100644 index 0000000000..aa08ef88b3 --- /dev/null +++ b/config/releases.exs @@ -0,0 +1,16 @@ +import Config + +# This `releases.exs` config file gets evaluated at RUNTIME, unlike other config files that are +# evaluated at compile-time. +# +# See https://hexdocs.pm/mix/1.9.0/Mix.Tasks.Release.html#module-runtime-configuration + +config :omg_watcher_info, OMG.WatcherInfo.DB.Repo, + # Have at most `:pool_size` DB connections on standby and serving DB queries. + pool_size: String.to_integer(System.get_env("WATCHER_INFO_DB_POOL_SIZE") || "10"), + # Wait at most `:queue_target` for a connection. If all connections checked out during + # a `:queue_interval` takes more than `:queue_target`, then we double the `:queue_target`. + # If checking out connections take longer than the new target, a DBConnection.ConnectionError is raised. + # See: https://hexdocs.pm/db_connection/DBConnection.html#start_link/2-queue-config + queue_target: String.to_integer(System.get_env("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS") || "50"), + queue_interval: String.to_integer(System.get_env("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS") || "1000"), From dbb84c8fc99b0af023639710cd65b012c66e1398 Mon Sep 17 00:00:00 2001 From: unnawut Date: Mon, 10 Aug 2020 14:59:24 +0700 Subject: [PATCH 5/7] fix: remove release tasks --- .../release_tasks/set_db_pool.ex | 67 ------------- .../release_tasks/set_db_pool_test.exs | 97 ------------------- mix.exs | 1 - 3 files changed, 165 deletions(-) delete mode 100644 apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_db_pool.ex delete mode 100644 apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs diff --git a/apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_db_pool.ex b/apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_db_pool.ex deleted file mode 100644 index cff4942ed9..0000000000 --- a/apps/omg_watcher_info/lib/omg_watcher_info/release_tasks/set_db_pool.ex +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright 2019-2019 OmiseGO Pte Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -defmodule OMG.WatcherInfo.ReleaseTasks.SetDbPool do - @moduledoc false - @behaviour Config.Provider - require Logger - - @app :omg_watcher_info - @config_key OMG.WatcherInfo.DB.Repo - - # Note that we're setting these configs directly into Ecto.Repo's implementation, - # so the config naming deviates with the env var names in order to align with Ecto.Repo. - # See: https://hexdocs.pm/db_connection/DBConnection.html#start_link/2-queue-config - @mapping [ - # {env_var, config_name} - {"WATCHER_INFO_DB_POOL_SIZE", :pool_size}, - {"WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS", :queue_target}, - {"WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS", :queue_interval} - ] - - def init(args) do - args - end - - def load(config, _args) do - _ = on_load() - configs = [{@config_key, load_repo_configs(@app, @mapping)}] - - Config.Reader.merge(config, [{@app, configs}]) - end - - # Returns: - # [ - # pool_size: 10, - # queue_target: 50, - # queue_interval: 1000 - # ] - defp load_repo_configs(app, mapping) do - Enum.map(mapping, fn {env_var, config_name} -> - default = Application.get_env(app, config_name) - value = env_var |> System.get_env() |> validate_integer(default) - _ = Logger.info("CONFIGURATION: App: #{@app} Key: #{config_name} Value: #{inspect(value)}.") - - {config_name, value} - end) - end - - defp validate_integer(nil, default), do: default - defp validate_integer(value, _default) when is_binary(value), do: String.to_integer(value) - - defp on_load() do - _ = Application.ensure_all_started(:logger) - _ = Application.load(@app) - end -end diff --git a/apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs b/apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs deleted file mode 100644 index 2bed7cf246..0000000000 --- a/apps/omg_watcher_info/test/omg_watcher_info/release_tasks/set_db_pool_test.exs +++ /dev/null @@ -1,97 +0,0 @@ -# Copyright 2019-2020 OmiseGO Pte Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -defmodule OMG.WatcherInfo.ReleaseTasks.SetDbPoolTest do - use ExUnit.Case, async: true - alias OMG.WatcherInfo.ReleaseTasks.SetDbPool - - @app :omg_watcher_info - @config_key OMG.WatcherInfo.DB.Repo - - describe "WATCHER_INFO_DB_POOL_SIZE" do - test "sets the repo's pool_size to WATCHER_INFO_DB_POOL_SIZE" do - assert load_and_fetch("WATCHER_INFO_DB_POOL_SIZE", "123", :pool_size) == 123 - :ok = System.delete_env("WATCHER_INFO_DB_POOL_SIZE") - end - - test "uses the default pool_size value if WATCHER_INFO_DB_POOL_SIZE is not defined" do - default_value = Application.get_env(@app, :pool_size) - assert load_and_fetch("WATCHER_INFO_DB_POOL_SIZE", nil, :pool_size) == default_value - :ok = System.delete_env("WATCHER_INFO_DB_POOL_SIZE") - end - - test "fails if WATCHER_INFO_DB_POOL_SIZE is not a valid stringified integer" do - assert catch_error(load_and_fetch("WATCHER_INFO_DB_POOL_SIZE", "not integer", :pool_size)) == :badarg - :ok = System.delete_env("WATCHER_INFO_DB_POOL_SIZE") - end - end - - describe "WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS" do - test "sets the repo's queue_target to WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS" do - assert load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS", "123", :queue_target) == 123 - :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS") - end - - test "uses the default queue_target value if WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS is not defined" do - default_value = Application.get_env(@app, :queue_target) - assert load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS", nil, :queue_target) == default_value - :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS") - end - - test "fails if WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS is not a valid stringified integer" do - assert catch_error(load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS", "not integer", :queue_target)) == - :badarg - - :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS") - end - end - - describe "WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS" do - test "sets the repo's queue_interval to WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS" do - assert load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS", "123", :queue_interval) == 123 - :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS") - end - - test "uses the default queue_interval value if WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS is not defined" do - default_value = Application.get_env(@app, :queue_interval) - assert load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS", nil, :queue_interval) == default_value - :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS") - end - - test "fails if WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS is not a valid stringified integer" do - assert catch_error(load_and_fetch("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS", "not integer", :queue_interval)) == - :badarg - - :ok = System.delete_env("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS") - end - end - - defp load_and_fetch(env_name, nil, config_name) do - :ok = System.delete_env(env_name) - config = SetDbPool.load([], []) - - fetch(config, config_name) - end - - defp load_and_fetch(env_name, env_value, config_name) do - :ok = System.put_env(env_name, env_value) - config = SetDbPool.load([], []) - - fetch(config, config_name) - end - - defp fetch(config, config_name) do - config |> Keyword.fetch!(@app) |> Keyword.fetch!(@config_key) |> Keyword.fetch!(config_name) - end -end diff --git a/mix.exs b/mix.exs index df7a049f0d..52312419c2 100644 --- a/mix.exs +++ b/mix.exs @@ -94,7 +94,6 @@ defmodule OMG.Umbrella.MixProject do {OMG.Watcher.ReleaseTasks.SetTracer, []}, {OMG.Watcher.ReleaseTasks.SetApplication, [release: :watcher_info, current_version: current_version()]}, {OMG.WatcherInfo.ReleaseTasks.SetDB, []}, - {OMG.WatcherInfo.ReleaseTasks.SetDbPool, []}, {OMG.WatcherInfo.ReleaseTasks.SetTracer, []} ] ], From 890ef4de0aba2ae5a854c570023c9d76526020af Mon Sep 17 00:00:00 2001 From: unnawut Date: Mon, 10 Aug 2020 15:39:21 +0700 Subject: [PATCH 6/7] fix: syntax --- config/releases.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/releases.exs b/config/releases.exs index aa08ef88b3..412baea707 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -13,4 +13,4 @@ config :omg_watcher_info, OMG.WatcherInfo.DB.Repo, # If checking out connections take longer than the new target, a DBConnection.ConnectionError is raised. # See: https://hexdocs.pm/db_connection/DBConnection.html#start_link/2-queue-config queue_target: String.to_integer(System.get_env("WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS") || "50"), - queue_interval: String.to_integer(System.get_env("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS") || "1000"), + queue_interval: String.to_integer(System.get_env("WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS") || "1000") From 55febb00704db7bc99aed2fbf2d75b457ae69093 Mon Sep 17 00:00:00 2001 From: unnawut Date: Mon, 10 Aug 2020 16:24:16 +0700 Subject: [PATCH 7/7] docs: add docs for db pool env vars --- docs/deployment_configuration.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/deployment_configuration.md b/docs/deployment_configuration.md index 71b055b0e3..593ca68588 100644 --- a/docs/deployment_configuration.md +++ b/docs/deployment_configuration.md @@ -39,6 +39,9 @@ ***Watcher Info only*** - "DATABASE_URL" - Postgres address *mandatory* +- "WATCHER_INFO_DB_POOL_SIZE" - The size of the database connection pool. Defaults to `10`. +- "WATCHER_INFO_DB_POOL_QUEUE_TARGET_MS" - The maximum time to wait for a DB connection in milliseconds. Defaults to `50`. +- "WATCHER_INFO_DB_POOL_QUEUE_INTERVAL_MS" - The interval in milliseconds to determine whether the queue target period above has been exceeded. Defaults to `1000`. ***Erlang VM configuration***