Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix - Set slot_name_suffix to avoid conflicts on deploys #709

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Config

version = Mix.Project.config()[:version] |> String.replace(".", "_") |> String.downcase()

config :logflare_logger_backend,
url: System.get_env("LOGFLARE_LOGGER_BACKEND_URL", "https://api.logflare.app")

Expand All @@ -9,6 +11,9 @@ username = System.get_env("DB_USER", "postgres")
password = System.get_env("DB_PASSWORD", "postgres")
database = System.get_env("DB_NAME", "postgres")
port = System.get_env("DB_PORT", "5432")
slot_name_suffix = System.get_env("SLOT_NAME_SUFFIX", version)

config :realtime, slot_name_suffix: slot_name_suffix

if config_env() == :prod do
secret_key_base =
Expand Down
10 changes: 2 additions & 8 deletions lib/extensions/postgres_cdc_rls/replication_poller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,8 @@ defmodule Extensions.PostgresCdcRls.ReplicationPoller do
end

def slot_name_suffix() do
case System.get_env("SLOT_NAME_SUFFIX") do
nil ->
""

value ->
Logger.debug("Using slot name suffix: " <> value)
"_" <> value
end
slot_name_suffix = Application.get_env(:realtime, :slot_name_suffix)
"_" <> slot_name_suffix
end

defp convert_errors([_ | _] = errors), do: errors
Expand Down
1 change: 0 additions & 1 deletion lib/extensions/postgres_cdc_rls/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ defmodule Extensions.PostgresCdcRls.Supervisor do
def init(_args) do
load_migrations_modules()

:syn.set_event_handler(Realtime.SynHandler)
:syn.add_node_to_scopes([PostgresCdcRls])

children = [
Expand Down
2 changes: 2 additions & 0 deletions lib/realtime/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
name: Realtime.Registry.Unique
)

:syn.set_event_handler(Realtime.SynHandler)
filipecabaco marked this conversation as resolved.
Show resolved Hide resolved
:ok = :syn.add_node_to_scopes([Realtime.Tenants.Connect])
:ok = :syn.add_node_to_scopes([:users, RegionNodes])

region = Application.get_env(:realtime, :region)
:syn.join(RegionNodes, region, self(), node: node())

Expand Down Expand Up @@ -71,7 +73,7 @@
] ++ extensions_supervisors()

children =
case Realtime.Repo.Replica.replica() do

Check warning on line 76 in lib/realtime/application.ex

View workflow job for this annotation

GitHub Actions / Formatting Checks

Nested modules could be aliased at the top of the invoking module.
Realtime.Repo -> children
replica -> List.insert_at(children, 2, replica)
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Realtime.MixProject do
def project do
[
app: :realtime,
version: "2.25.7",
version: "2.25.8",
elixir: "~> 1.14.0",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
19 changes: 13 additions & 6 deletions test/realtime/extensions/cdc_rls/replication_poller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,21 @@ defmodule ReplicationPollerTest do
end

describe "slot_name_suffix" do
test "when no SLOT_NAME_SUFFIX" do
System.delete_env("SLOT_NAME_SUFFIX")
assert Poller.slot_name_suffix() == ""
setup do
slot_name_suffix = Application.get_env(:realtime, :slot_name_suffix)

on_exit(fn -> Application.put_env(:realtime, :slot_name_suffix, slot_name_suffix) end)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it need to put this key on the exit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resetting the env to be equal to what it was in the start since we're changing application setup

end

test "uses Application.get_env/2 with key :slot_name_suffix" do
slot_name_suffix = Generators.rand_string()
Application.put_env(:realtime, :slot_name_suffix, slot_name_suffix)
assert Poller.slot_name_suffix() == "_" <> slot_name_suffix
end

test "when SLOT_NAME_SUFFIX defined" do
System.put_env("SLOT_NAME_SUFFIX", "some_val")
assert Poller.slot_name_suffix() == "_some_val"
test "defaults to project version" do
version = Mix.Project.config()[:version] |> String.replace(".", "_")
assert Poller.slot_name_suffix() == "_" <> version
end
end
end
Loading