diff --git a/VERSION b/VERSION index 5d11b147..f806549d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.15 +0.9.16 diff --git a/lib/supavisor/application.ex b/lib/supavisor/application.ex index b6cebd69..4b25aa53 100644 --- a/lib/supavisor/application.ex +++ b/lib/supavisor/application.ex @@ -74,12 +74,19 @@ defmodule Supavisor.Application do child_spec: DynamicSupervisor, strategy: :one_for_one, name: Supavisor.DynamicSupervisor }, Supavisor.Vault, - {Cachex, name: Supavisor.Cache}, Supavisor.TenantsMetrics, # Start the Endpoint (http/https) SupavisorWeb.Endpoint ] + # start Cachex only if the node uses names, this is necessary for test setup + children = + if node() != :nonode@nohost do + [{Cachex, name: Supavisor.Cache} | children] + else + children + end + # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options opts = [strategy: :one_for_one, name: Supavisor.Supervisor] diff --git a/lib/supavisor/client_handler.ex b/lib/supavisor/client_handler.ex index c7593b54..6d330124 100644 --- a/lib/supavisor/client_handler.ex +++ b/lib/supavisor/client_handler.ex @@ -279,7 +279,7 @@ defmodule Supavisor.ClientHandler do :keep_state_and_data {:buffering, size} -> - Logger.warn("DB call buffering #{size}}") + Logger.debug("DB call buffering #{size}") if size > 1_000_000 do msg = "Db buffer size is too big: #{size}" diff --git a/lib/supavisor/handler_helpers.ex b/lib/supavisor/handler_helpers.ex index 16530eef..226c2510 100644 --- a/lib/supavisor/handler_helpers.ex +++ b/lib/supavisor/handler_helpers.ex @@ -38,14 +38,9 @@ defmodule Supavisor.HandlerHelpers do @spec ssl_recv(S.tcp_sock()) :: {:ok, S.ssl_sock()} | {:error, term} def ssl_recv({:gen_tcp, sock} = s) do case :gen_tcp.recv(sock, 1, 15_000) do - {:ok, <>} -> - ssl_connect(s) - - {:ok, <>} -> - {:ok, s} - - {:error, _} = error -> - error + {:ok, <>} -> ssl_connect(s) + {:ok, <>} -> {:ok, s} + {:error, _} = error -> error end end @@ -55,11 +50,8 @@ defmodule Supavisor.HandlerHelpers do opts = [verify: :verify_none] case :ssl.connect(sock, opts, timeout) do - {:ok, ssl_sock} -> - {:ok, {:ssl, ssl_sock}} - - {:error, reason} -> - {:error, reason} + {:ok, ssl_sock} -> {:ok, {:ssl, ssl_sock}} + {:error, reason} -> {:error, reason} end end diff --git a/lib/supavisor/monitoring/prom_ex.ex b/lib/supavisor/monitoring/prom_ex.ex index d8b977e3..d52d7af4 100644 --- a/lib/supavisor/monitoring/prom_ex.ex +++ b/lib/supavisor/monitoring/prom_ex.ex @@ -91,15 +91,16 @@ defmodule Supavisor.Monitoring.PromEx do Registry.select(Supavisor.Registry.TenantClients, [{{:"$1", :_, :_}, [], [:"$1"]}]) |> Enum.uniq() - Enum.reduce(pools, metrics, fn {tenant, _, _}, acc -> - {matched, rest} = Enum.split_with(acc, &String.contains?(&1, "tenant=\"#{tenant}\"")) + _ = + Enum.reduce(pools, metrics, fn {tenant, _, _}, acc -> + {matched, rest} = Enum.split_with(acc, &String.contains?(&1, "tenant=\"#{tenant}\"")) - if matched != [] do - Cachex.put(Supavisor.Cache, {:metrics, tenant}, Enum.join(matched, "\n")) - end + if matched != [] do + Cachex.put(Supavisor.Cache, {:metrics, tenant}, Enum.join(matched, "\n")) + end - rest - end) + rest + end) pools end diff --git a/lib/supavisor_web/open_api_schemas.ex b/lib/supavisor_web/open_api_schemas.ex index b7c73d1e..065dac4a 100644 --- a/lib/supavisor_web/open_api_schemas.ex +++ b/lib/supavisor_web/open_api_schemas.ex @@ -43,7 +43,7 @@ defmodule SupavisorWeb.OpenApiSchemas do db_password: "postgres", pool_size: 10, is_manager: false, - max_clients: 25000, + max_clients: 25_000, mode_type: "transaction", inserted_at: "2023-03-27T12:00:00Z", updated_at: "2023-03-27T12:00:00Z" @@ -101,7 +101,7 @@ defmodule SupavisorWeb.OpenApiSchemas do db_user: "postgres", db_password: "postgres", pool_size: 10, - max_clients: 25000, + max_clients: 25_000, pool_checkout_timeout: 1000, is_manager: false, mode_type: "transaction", @@ -172,7 +172,7 @@ defmodule SupavisorWeb.OpenApiSchemas do db_password: "postgres", pool_size: 10, mode_type: "transaction", - max_clients: 25000, + max_clients: 25_000, pool_checkout_timeout: 1000 } ] diff --git a/test/supavisor/client_handler_test.exs b/test/supavisor/client_handler_test.exs index a076b79b..206f3ed9 100644 --- a/test/supavisor/client_handler_test.exs +++ b/test/supavisor/client_handler_test.exs @@ -1,12 +1,12 @@ defmodule Supavisor.ClientHandlerTest do use ExUnit.Case, async: true - alias Supavisor.ClientHandler + alias Supavisor.HandlerHelpers, as: HH describe "parse_user_info/1" do test "extracts the external_id from the username" do payload = %{"user" => "test.user.external_id"} - {name, external_id} = ClientHandler.parse_user_info(payload) + {name, external_id} = HH.parse_user_info(payload) assert name == "test.user" assert external_id == "external_id" end @@ -14,7 +14,7 @@ defmodule Supavisor.ClientHandlerTest do test "username consists only of username" do username = "username" payload = %{"user" => username} - {user, nil} = ClientHandler.parse_user_info(payload) + {user, nil} = HH.parse_user_info(payload) assert username == user end @@ -22,14 +22,14 @@ defmodule Supavisor.ClientHandlerTest do user = "test.user" external_id = "external_id" payload = %{"options" => %{"reference" => external_id}, "user" => user} - {user1, external_id1} = ClientHandler.parse_user_info(payload) + {user1, external_id1} = HH.parse_user_info(payload) assert user1 == user assert external_id1 == external_id end test "unicode in username" do payload = %{"user" => "тестовe.імʼя.external_id"} - {name, external_id} = ClientHandler.parse_user_info(payload) + {name, external_id} = HH.parse_user_info(payload) assert name == "тестовe.імʼя" assert external_id == "external_id" end diff --git a/test/test_helper.exs b/test/test_helper.exs index 5ee4e48c..a3a81c8b 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -7,5 +7,7 @@ Supavisor.Support.Cluster.apply_config(node2) {:ok, _} = :erpc.call(node2, :application, :ensure_all_started, [:supavisor]) +Cachex.start_link(name: Supavisor.Cache) + ExUnit.start() Ecto.Adapters.SQL.Sandbox.mode(Supavisor.Repo, :auto)