diff --git a/config/dev.exs b/config/dev.exs index 949e47e69..3c5117678 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -91,5 +91,3 @@ config :open_api_spex, :cache_adapter, OpenApiSpex.Plug.NoneCache config :stripity_stripe, api_key: "sk_test_thisisaboguskey", api_base_url: "http://localhost:12111/v1/" - -import_config("telemetry.exs") diff --git a/config/prod.exs b/config/prod.exs index 5a6fe9d9d..7497d72c0 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -35,5 +35,3 @@ config :logger, config :logflare_logger_backend, flush_interval: 2_000, max_batch_size: 250 - -import_config "telemetry.exs" diff --git a/config/release.exs b/config/release.exs deleted file mode 100644 index becde7693..000000000 --- a/config/release.exs +++ /dev/null @@ -1 +0,0 @@ -import Config diff --git a/config/runtime.exs b/config/runtime.exs index 3cddc83a3..be3505a67 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -261,3 +261,9 @@ case System.get_env("LOGFLARE_FEATURE_FLAG_OVERRIDE") do |> Enum.map(&Map.new/1) |> Enum.reduce(&Map.merge/2) end + +if config_env() != :test do + config :telemetry_poller, :default, + vm_measurements: [:memory, :total_run_queue_lengths], + period: 1_000 +end diff --git a/config/staging.exs b/config/staging.exs deleted file mode 100644 index 430000362..000000000 --- a/config/staging.exs +++ /dev/null @@ -1,53 +0,0 @@ -import Config - -config :logflare, env: :staging - -config :logflare, LogflareWeb.Endpoint, - http: [ - port: 4_000, - transport_options: [ - max_connections: 16_384, - num_acceptors: 10, - socket_opts: [{:raw, 1, 15, <<1::32-native>>}] - ], - protocol_options: [ - # https://ninenines.eu/docs/en/cowboy/2.8/manual/cowboy_http/ - request_timeout: 30_000, - # https://cloud.google.com/load-balancing/docs/https/#timeouts_and_retries - # must be greater than 600s - idle_timeout: 650_000, - max_keepalive: :infinity - ], - compress: true - ], - live_view: [ - signing_salt: "2hJsy/zhChcvp8NEvaJyH3nokAbI+UrEQQhxLXmEcTKnNUxbMvVP7BOgrog00V7G" - ], - cache_static_manifest: "priv/static/cache_manifest.json", - server: true, - code_reloader: false, - version: Application.spec(:logflare, :vsn) - -config :logger, :console, metadata: :all - -config :phoenix, :serve_endpoints, true - -config :logflare, Logflare.Repo, - port: 5432, - pool_size: 5, - ssl: true, - prepare: :unnamed, - timeout: 30_000 - -config :logflare_telemetry, - source_id: :"e5d18201-f0e0-459b-b6b3-2d3bc7d16fa4" - -config :libcluster, debug: true - -config :logflare, Logflare.Cluster.Utils, min_cluster_size: 1 - -import_config "telemetry.exs" - -# if File.exists?("config/staging.secret.exs") do -# import_config "staging.secret.exs" -# end diff --git a/config/telemetry.exs b/config/telemetry.exs deleted file mode 100644 index 257ca43f7..000000000 --- a/config/telemetry.exs +++ /dev/null @@ -1,5 +0,0 @@ -import Config - -config :telemetry_poller, :default, - vm_measurements: [:memory, :total_run_queue_lengths], - period: 1_000 diff --git a/config/test.secret.exs.enc b/config/test.secret.exs.enc deleted file mode 100644 index c92604fbc..000000000 Binary files a/config/test.secret.exs.enc and /dev/null differ diff --git a/lib/logflare/cluster/utils.ex b/lib/logflare/cluster/utils.ex index 69ce61b63..bd1d4dbaf 100644 --- a/lib/logflare/cluster/utils.ex +++ b/lib/logflare/cluster/utils.ex @@ -2,27 +2,31 @@ defmodule Logflare.Cluster.Utils do @moduledoc false require Logger - defp env_min_cluster_size, do: Application.get_env(:logflare, __MODULE__)[:min_cluster_size] - + @spec node_list_all() :: [Node.t()] def node_list_all() do [Node.self() | Node.list()] end + @spec cluster_size() :: non_neg_integer() def cluster_size() do - lib_cluster_size = node_list_all() |> Enum.count() + lib_cluster_size = actual_cluster_size() + min_size = env_min_cluster_size() - if lib_cluster_size >= env_min_cluster_size() do + if lib_cluster_size >= min_size do lib_cluster_size else - Logger.error("Cluster size is #{lib_cluster_size} but expected #{env_min_cluster_size()}", + Logger.warning("Cluster size is #{lib_cluster_size} but expected #{min_size}", cluster_size: lib_cluster_size ) - env_min_cluster_size() + min_size end end + @spec actual_cluster_size() :: non_neg_integer() def actual_cluster_size() do Enum.count(node_list_all()) end + + defp env_min_cluster_size, do: Application.get_env(:logflare, __MODULE__)[:min_cluster_size] end diff --git a/test/logflare/cluster_test.exs b/test/logflare/cluster_test.exs new file mode 100644 index 000000000..e18747454 --- /dev/null +++ b/test/logflare/cluster_test.exs @@ -0,0 +1,28 @@ +defmodule Logflare.ClusterTest do + use ExUnit.Case, async: false + alias Logflare.Cluster + + test "Cluster.Utils.node_list_all/0" do + assert [_|_] = Cluster.Utils.node_list_all() + end + + + test "cluster_size/0, actual_cluster_size/0" do + assert Cluster.Utils.cluster_size() == Cluster.Utils.actual_cluster_size() + end + + describe "Cluster.Utils" do + setup do + config = Application.get_env(:logflare, Cluster.Utils) + Application.put_env(:logflare, Cluster.Utils, [min_cluster_size: 12]) + on_exit(fn -> + Application.put_env(:logflare, Cluster.Utils, config) + end) + end + test "cluster_size/0, actual_cluster_size/0" do + assert Cluster.Utils.cluster_size() == 12 + assert Cluster.Utils.actual_cluster_size() == 1 + end + + end +end