Skip to content

Commit

Permalink
fix: Revert changes to nodes.ex (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecabaco authored Oct 30, 2024
1 parent b06741d commit c069edb
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 58 deletions.
2 changes: 1 addition & 1 deletion lib/realtime/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Realtime.Application do
@moduledoc false

use Application
require Logger, warn: false
require Logger
alias Realtime.Repo.Replica
defmodule JwtSecretError, do: defexception([:message])
defmodule JwtClaimValidatorsError, do: defexception([:message])
Expand Down
137 changes: 82 additions & 55 deletions lib/realtime/nodes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,6 @@ defmodule Realtime.Nodes do
require Logger
alias Realtime.Api.Tenant

@mapping_realtime_region_to_tenant_region_aws %{
"ap-southeast-1" => [
"ap-east-1",
"ap-northeast-1",
"ap-northeast-2",
"ap-south-1",
"ap-southeast-1"
],
"ap-southeast-2" => ["ap-southeast-2"],
"eu-west-2" => [
"eu-central-1",
"eu-central-2",
"eu-north-1",
"eu-west-1",
"eu-west-2",
"eu-west-3"
],
"us-east-1" => [
"ca-central-1",
"sa-east-1",
"us-east-1",
"us-east-2"
],
"us-west-1" => ["us-west-1", "us-west-2"]
}

@mapping_realtime_region_to_tenant_region_fly %{
"iad" => ["ca-central-1", "sa-east-1", "us-east-1"],
"lhr" => ["eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3"],
"sea" => ["us-west-1"],
"syd" => [
"ap-east-1",
"ap-northeast-1",
"ap-northeast-2",
"ap-south-1",
"ap-southeast-1",
"ap-southeast-2"
]
}

@doc """
Gets the node to launch the Postgres connection on for a tenant.
"""
Expand Down Expand Up @@ -75,24 +35,52 @@ defmodule Realtime.Nodes do
region_mapping(platform, tenant_region)
end

defp region_mapping(nil, tenant_region), do: tenant_region

defp region_mapping(platform, tenant_region) do
mappings =
case platform do
:aws -> @mapping_realtime_region_to_tenant_region_aws
:fly -> @mapping_realtime_region_to_tenant_region_fly
_ -> []
end
defp region_mapping(:aws, tenant_region) do
case tenant_region do
"ap-east-1" -> "ap-southeast-1"
"ap-northeast-1" -> "ap-southeast-1"
"ap-northeast-2" -> "ap-southeast-1"
"ap-south-1" -> "ap-southeast-1"
"ap-southeast-1" -> "ap-southeast-1"
"ap-southeast-2" -> "ap-southeast-2"
"ca-central-1" -> "us-east-1"
"eu-central-1" -> "eu-west-2"
"eu-central-2" -> "eu-west-2"
"eu-north-1" -> "eu-west-2"
"eu-west-1" -> "eu-west-2"
"eu-west-2" -> "eu-west-2"
"eu-west-3" -> "eu-west-2"
"sa-east-1" -> "us-east-1"
"us-east-1" -> "us-east-1"
"us-east-2" -> "us-east-1"
"us-west-1" -> "us-west-1"
"us-west-2" -> "us-west-1"
_ -> nil
end
end

mappings
|> Enum.flat_map(fn {realtime_region, tenant_regions} ->
Enum.map(tenant_regions, fn tenant_region -> {tenant_region, realtime_region} end)
end)
|> Map.new()
|> Map.get(tenant_region)
defp region_mapping(:fly, tenant_region) do
case tenant_region do
"us-east-1" -> "iad"
"us-west-1" -> "sea"
"sa-east-1" -> "iad"
"ca-central-1" -> "iad"
"ap-southeast-1" -> "syd"
"ap-northeast-1" -> "syd"
"ap-northeast-2" -> "syd"
"ap-southeast-2" -> "syd"
"ap-east-1" -> "syd"
"ap-south-1" -> "syd"
"eu-west-1" -> "lhr"
"eu-west-2" -> "lhr"
"eu-west-3" -> "lhr"
"eu-central-1" -> "lhr"
_ -> nil
end
end

defp region_mapping(_, tenant_region), do: tenant_region

@doc """
Lists the nodes in a region. Sorts by node name in case the list order
is unstable.
Expand Down Expand Up @@ -174,6 +162,45 @@ defmodule Realtime.Nodes do
end
end

@mapping_realtime_region_to_tenant_region_aws %{
"ap-southeast-1" => [
"ap-east-1",
"ap-northeast-1",
"ap-northeast-2",
"ap-south-1",
"ap-southeast-1"
],
"ap-southeast-2" => ["ap-southeast-2"],
"eu-west-2" => [
"eu-central-1",
"eu-central-2",
"eu-north-1",
"eu-west-1",
"eu-west-2",
"eu-west-3"
],
"us-east-1" => [
"ca-central-1",
"sa-east-1",
"us-east-1",
"us-east-2"
],
"us-west-1" => ["us-west-1", "us-west-2"]
}
@mapping_realtime_region_to_tenant_region_fly %{
"iad" => ["ca-central-1", "sa-east-1", "us-east-1"],
"lhr" => ["eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3"],
"sea" => ["us-west-1"],
"syd" => [
"ap-east-1",
"ap-northeast-1",
"ap-northeast-2",
"ap-south-1",
"ap-southeast-1",
"ap-southeast-2"
]
}

@doc """
Fetches the tenant regions for a given realtime reagion
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
</div>
<div class="mb-4">
<%= label(f, :log_level, class: "block text-gray-700 text-sm font-bold mb-2") %>
<%= select(f, :log_level, ["debug", "info", "warn", "error"], selected: "info", class: "
<%= select(f, :log_level, ["debug", "info", "warning", "error"], selected: "info", class: "
my-1
block
w-full
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.33.15",
version: "2.33.16",
elixir: "~> 1.16.0",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit c069edb

Please sign in to comment.