Skip to content

Commit

Permalink
Merge pull request #1824 from Logflare/chore/remove-staging.exs
Browse files Browse the repository at this point in the history
chore: consolidate config files, adjust Logflare.Cluster.Utils.cluster_size/0
  • Loading branch information
Ziinc authored Nov 15, 2023
2 parents 30738f6 + 5b00081 commit c6cb031
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 69 deletions.
2 changes: 0 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 0 additions & 2 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,3 @@ config :logger,
config :logflare_logger_backend,
flush_interval: 2_000,
max_batch_size: 250

import_config "telemetry.exs"
1 change: 0 additions & 1 deletion config/release.exs

This file was deleted.

6 changes: 6 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
53 changes: 0 additions & 53 deletions config/staging.exs

This file was deleted.

5 changes: 0 additions & 5 deletions config/telemetry.exs

This file was deleted.

Binary file removed config/test.secret.exs.enc
Binary file not shown.
16 changes: 10 additions & 6 deletions lib/logflare/cluster/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions test/logflare/cluster_test.exs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c6cb031

Please sign in to comment.