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: latency region #670

Merged
merged 2 commits into from
Sep 13, 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
16 changes: 8 additions & 8 deletions lib/realtime/monitoring/latency.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ defmodule Realtime.Latency do

Emulate a healthy remote node:

iex> [{%Task{}, {:ok, %{response: {:ok, {:pong, "iad"}}}}}] = Realtime.Latency.ping()
iex> [{%Task{}, {:ok, %{response: {:ok, {:pong, "not_set"}}}}}] = Realtime.Latency.ping()

Emulate a slow but healthy remote node:

iex> [{%Task{}, {:ok, %{response: {:ok, {:pong, "iad"}}}}}] = Realtime.Latency.ping(5_000, 10_000, 30_000)
iex> [{%Task{}, {:ok, %{response: {:ok, {:pong, "not_set"}}}}}] = Realtime.Latency.ping(5_000, 10_000, 30_000)

Emulate an unhealthy remote node:

Expand All @@ -97,19 +97,19 @@ defmodule Realtime.Latency do
:timer.tc(fn -> :rpc.call(n, __MODULE__, :pong, [pong_timeout], timer_timeout) end)

latency_ms = latency / 1_000
fly_region = Application.get_env(:realtime, :fly_region, "iad")
region = Application.get_env(:realtime, :region, "not_set")
short_name = Helpers.short_node_id_from_name(n)
from_node = Helpers.short_node_id_from_name(Node.self())

case response do
{:badrpc, reason} ->
Logger.error(
"Network error: can't connect to node #{short_name} from #{fly_region} - #{inspect(reason)}"
"Network error: can't connect to node #{short_name} from #{region} - #{inspect(reason)}"
)

payload = %Payload{
from_node: from_node,
from_region: fly_region,
from_region: region,
node: short_name,
region: nil,
latency: latency_ms,
Expand All @@ -125,12 +125,12 @@ defmodule Realtime.Latency do
if latency_ms > 1_000,
do:
Logger.warn(
"Network warning: latency to #{remote_region} (#{short_name}) from #{fly_region} (#{from_node}) is #{latency_ms} ms"
"Network warning: latency to #{remote_region} (#{short_name}) from #{region} (#{from_node}) is #{latency_ms} ms"
)

payload = %Payload{
from_node: from_node,
from_region: fly_region,
from_region: region,
node: short_name,
region: remote_region,
latency: latency_ms,
Expand Down Expand Up @@ -159,7 +159,7 @@ defmodule Realtime.Latency do

@spec pong :: {:ok, {:pong, String.t()}}
def pong() do
region = Application.get_env(:realtime, :fly_region, "iad")
region = Application.get_env(:realtime, :region, "not_set")
{:ok, {:pong, region}}
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.22.12",
version: "2.22.13",
elixir: "~> 1.14.0",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down