Skip to content

Commit

Permalink
Release (#440)
Browse files Browse the repository at this point in the history
* fix: don't update syn meta if the node is mismatched (#433)

* update multiplayer demo MAX_ROOM_USERS to 50

* fix: drop LHR and GRU (#436)

* feat: footer improvements (#429)

* feat: display the count of connected tenants in metrics (#418)

* fix: don't try to stop the not alive pid in the resolver (#417)

* fix: increase read replica pool size

* feat: default realtime-dev JWT secret to API_JWT_SECRET env var value

* chore(deps): bump json5 from 1.0.1 to 1.0.2 in /demo

Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](json5/json5@v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* feat: default Repo with_dynamic_repo name to nil and pool_size to 1 (#423)

* fix: looks for the PR number after # symbol (#425)

* Add defaults to current fields to reflect db schema

* Add max_bytes_per_second and max_channels_per_client fields

* Add max_joins_per_second to schema

* Add db limits to socket

* Use db limits in channel

* fix: tests

* fix: do not block a registration process (#426)

* fix: add http checks

* feat: stop connection to a tenant's db if there are no connected users for 10 minutes. (#428)

* feat: add short_node_id helper

* Use new helper in Realtime.PromEx

* feat: add version to footer and use short node id

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: abc3 <sts@abc3.dev>
Co-authored-by: Wen Bo Xie <wenbo.xie3@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Wen Bo Xie <5532241+w3b6x9@users.noreply.github.com>

* fix: switch to aws roles

* chore: update staging branch to main and prod branch to release

* Add sjc replica (#441)

* fix: load sjc replica from DB_HOST_REPLICA_SJC env var (#443)

* Version is compiled now (#444)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: abc3 <sts@abc3.dev>
Co-authored-by: Chase Granberry <chase@logflare.app>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Inian <inian1234@gmail.com>
  • Loading branch information
5 people committed Jan 18, 2023
1 parent c56c48f commit d8acf69
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 59 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/mirror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ jobs:
permissions:
contents: read
packages: write
id-token: write
steps:
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.PROD_AWS_ROLE }}
aws-region: us-east-1
- uses: docker/login-action@v2
with:
registry: public.ecr.aws
username: ${{ secrets.PROD_ACCESS_KEY_ID }}
password: ${{ secrets.PROD_SECRET_ACCESS_KEY }}
- uses: docker/login-action@v2
with:
registry: ghcr.io
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: MT Deploy Production
on:
push:
branches:
- main
- release

jobs:
release:
Expand Down Expand Up @@ -112,6 +112,7 @@ jobs:
permissions:
contents: read
packages: write
id-token: write
steps:
- uses: docker/setup-buildx-action@v2

Expand All @@ -126,12 +127,16 @@ jobs:
supabase/realtime@${{ needs.docker_x86_release.outputs.image_digest }} \
supabase/realtime@${{ needs.docker_arm_release.outputs.image_digest }}
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.PROD_AWS_ROLE }}
aws-region: us-east-1

- name: Login to ECR
uses: docker/login-action@v2
with:
registry: public.ecr.aws
username: ${{ secrets.PROD_ACCESS_KEY_ID }}
password: ${{ secrets.PROD_SECRET_ACCESS_KEY }}

- name: Login to GHCR
uses: docker/login-action@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prod_linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: MT Production Formatting Checks
on:
pull_request:
branches:
- main
- release
jobs:
format:
name: Formatting Checks
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: MT Deploy Staging
on:
push:
branches:
- develop
- main
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/staging_linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: MT Staging Formatting Checks
on:
pull_request:
branches:
- develop
- main
jobs:
format:
name: Formatting Checks
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/staging_supabench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: MT Supabench
on:
push:
branches:
- develop
- main
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
Expand All @@ -28,4 +28,4 @@ jobs:
curl --request POST \
--url https://supabench.fly.dev/api/runs \
--header 'Authorization: User ${{ secrets.BENCHMARK_JWT }}' \
--data '{"benchmark_id":"SyMKxU3TOiWcAvU","name":"PR ${{ env.PR_NUM }}","comment": "https://github.com/supabase/realtime/pull/${{ env.PR_NUM }}", "origin":"develop"}'
--data '{"benchmark_id":"SyMKxU3TOiWcAvU","name":"PR ${{ env.PR_NUM }}","comment": "https://github.com/supabase/realtime/pull/${{ env.PR_NUM }}", "origin":"main"}'
2 changes: 1 addition & 1 deletion .releaserc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"branches": [
"main"
"release"
],
"plugins": [
"@semantic-release/commit-analyzer",
Expand Down
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import Config

config :realtime,
ecto_repos: [Realtime.Repo]
ecto_repos: [Realtime.Repo],
version: Mix.Project.config()[:version]

# Configures the endpoint
config :realtime, RealtimeWeb.Endpoint,
Expand Down
3 changes: 2 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ if config_env() != :test do
replica_repos = %{
Realtime.Repo.Replica.FRA => System.get_env("DB_HOST_REPLICA_FRA", default_db_host),
Realtime.Repo.Replica.IAD => System.get_env("DB_HOST_REPLICA_IAD", default_db_host),
Realtime.Repo.Replica.SIN => System.get_env("DB_HOST_REPLICA_SIN", default_db_host)
Realtime.Repo.Replica.SIN => System.get_env("DB_HOST_REPLICA_SIN", default_db_host),
Realtime.Repo.Replica.SJC => System.get_env("DB_HOST_REPLICA_SJC", default_db_host)
}

# username, password, database, and port must match primary credentials
Expand Down
3 changes: 2 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ for repo <- [
Realtime.Repo,
Realtime.Repo.Replica.FRA,
Realtime.Repo.Replica.IAD,
Realtime.Repo.Replica.SIN
Realtime.Repo.Replica.SIN,
Realtime.Repo.Replica.SJC
] do
config :realtime, repo,
username: "postgres",
Expand Down
2 changes: 1 addition & 1 deletion demo/pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import WaitlistPopover from '../components/WaitlistPopover'
import DarkModeToggle from '../components/DarkModeToggle'

const LATENCY_THRESHOLD = 400
const MAX_ROOM_USERS = 5
const MAX_ROOM_USERS = 50
const MAX_DISPLAY_MESSAGES = 50
const MAX_EVENTS_PER_SECOND = 10
const X_THRESHOLD = 25
Expand Down
12 changes: 10 additions & 2 deletions lib/extensions/postgres_cdc_rls/cdc_rls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,16 @@ defmodule Extensions.PostgresCdcRls do

@spec update_meta(String.t(), pid(), pid()) :: {:ok, {pid(), term()}} | {:error, term()}
def update_meta(tenant, manager_pid, subs_pool) do
:syn.update_registry(__MODULE__, tenant, fn _, meta ->
%{meta | manager: manager_pid, subs_pool: subs_pool}
:syn.update_registry(__MODULE__, tenant, fn pid, meta ->
if node(pid) == node(manager_pid) do
%{meta | manager: manager_pid, subs_pool: subs_pool}
else
Logger.error(
"Node mismatch for tenant #{tenant} #{inspect(node(pid))} #{inspect(node(manager_pid))}"
)

meta
end
end)
end
end
17 changes: 7 additions & 10 deletions lib/extensions/postgres_cdc_rls/syn_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ defmodule Extensions.PostgresCdcRls.SynHandler do
alias RealtimeWeb.Endpoint

def on_process_unregistered(Extensions.PostgresCdcRls, name, _pid, _meta, reason) do
Logger.info("PostgresCdcRls terminated: #{inspect(name)} #{node()}")
Logger.warn("PostgresCdcRls terminated: #{inspect(name)} #{node()}")

broadcast_method =
if reason == :syn_conflict_resolution do
:broadcast
else
:local_broadcast
end

apply(Endpoint, broadcast_method, ["postgres_cdc:" <> name, "postgres_cdc_down", nil])
if reason != :syn_conflict_resolution do
Endpoint.local_broadcast("postgres_cdc:" <> name, "postgres_cdc_down", nil)
end
end

def resolve_registry_conflict(
Expand Down Expand Up @@ -51,14 +46,16 @@ defmodule Extensions.PostgresCdcRls.SynHandler do
resp =
if Process.alive?(stop) do
try do
DynamicSupervisor.stop(stop, :shutdown, 15_000)
DynamicSupervisor.stop(stop, :shutdown, 30_000)
catch
error, reason -> {:error, {error, reason}}
end
else
:not_alive
end

Endpoint.broadcast("postgres_cdc:" <> name, "postgres_cdc_down", nil)

Logger.warn(
"Resolving #{name} conflict, stop local pid: #{inspect(stop)}, response: #{inspect(resp)}"
)
Expand Down
29 changes: 19 additions & 10 deletions lib/realtime/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ defmodule Realtime.Helpers do
end
end

defp pad(data) do
to_add = 16 - rem(byte_size(data), 16)
data <> :binary.copy(<<to_add>>, to_add)
end

defp unpad(data) do
to_remove = :binary.last(data)
:binary.part(data, 0, byte_size(data) - to_remove)
end

def decrypt_creds(host, port, name, user, pass) do
secure_key = Application.get_env(:realtime, :db_enc_key)

Expand All @@ -103,4 +93,23 @@ defmodule Realtime.Helpers do
decrypt!(pass, secure_key)
}
end

def short_node_id() do
fly_alloc_id = Application.get_env(:realtime, :fly_alloc_id)

case String.split(fly_alloc_id, "-", parts: 2) do
[short_alloc_id, _] -> short_alloc_id
_ -> fly_alloc_id
end
end

defp pad(data) do
to_add = 16 - rem(byte_size(data), 16)
data <> :binary.copy(<<to_add>>, to_add)
end

defp unpad(data) do
to_remove = :binary.last(data)
:binary.part(data, 0, byte_size(data) - to_remove)
end
end
12 changes: 3 additions & 9 deletions lib/realtime/monitoring/prom_ex.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule Realtime.PromEx do
alias Realtime.PromEx.Plugins.{OsMon, Phoenix, Tenants}

import Realtime.Helpers, only: [short_node_id: 0]

@moduledoc """
Be sure to add the following to finish setting up PromEx:
Expand Down Expand Up @@ -137,18 +139,10 @@ defmodule Realtime.PromEx do
def set_metrics_tags() do
[_, node_host] = node() |> Atom.to_string() |> String.split("@")

fly_alloc_id = Application.get_env(:realtime, :fly_alloc_id)

short_alloc_id =
case String.split(fly_alloc_id, "-", parts: 2) do
[short_alloc_id, _] -> short_alloc_id
_ -> fly_alloc_id
end

metrics_tags = %{
region: Application.get_env(:realtime, :fly_region),
node_host: node_host,
short_alloc_id: short_alloc_id
short_alloc_id: short_node_id()
}

Application.put_env(:realtime, :metrics_tags, metrics_tags)
Expand Down
8 changes: 4 additions & 4 deletions lib/realtime/postgres_cdc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ defmodule Realtime.PostgresCdc do
case aws_region do
"us-east-1" -> "iad"
"us-west-1" -> "sjc"
"sa-east-1" -> "gru"
"sa-east-1" -> "iad"
"ca-central-1" -> "iad"
"ap-southeast-1" -> "sin"
"ap-northeast-1" -> "sin"
"ap-northeast-2" -> "sin"
"ap-southeast-2" -> "sin"
"ap-south-1" -> "sin"
"eu-west-1" -> "lhr"
"eu-west-2" -> "lhr"
"eu-west-3" -> "lhr"
"eu-west-1" -> "fra"
"eu-west-2" -> "fra"
"eu-west-3" -> "fra"
"eu-central-1" -> "fra"
_ -> nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/realtime/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Realtime.Repo do
adapter: Ecto.Adapters.Postgres

@replicas %{
"sjc" => Realtime.Repo.Replica.IAD,
"sjc" => Realtime.Repo.Replica.SJC,
"gru" => Realtime.Repo.Replica.IAD,
"iad" => Realtime.Repo.Replica.IAD,
"sin" => Realtime.Repo.Replica.SIN,
Expand Down
3 changes: 2 additions & 1 deletion lib/realtime_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ defmodule RealtimeWeb.Router do
Realtime.Repo,
Realtime.Repo.Replica.FRA,
Realtime.Repo.Replica.IAD,
Realtime.Repo.Replica.SIN
Realtime.Repo.Replica.SIN,
Realtime.Repo.Replica.SJC
],
ecto_psql_extras_options: [long_running_queries: [threshold: "200 milliseconds"]],
metrics: RealtimeWeb.Telemetry
Expand Down
16 changes: 9 additions & 7 deletions lib/realtime_web/templates/layout/live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@
</div>
</main>
<footer class="fixed bottom-0 left-0 z-20 p-4 w-full bg-white border-t border-zinc-100 md:flex md:items-center md:justify-between md:p-6">
<span class="text-sm text-gray-900 sm:text-center">© <a href="https://supabase.com/" class="hover:underline">Supabase Inc</a>
</span>
<ul class="flex flex-wrap items-center mt-3 text-sm text-gray-900 sm:mt-0">
<li><span class="mr-4 md:mr-6">Apache 2.0 License</span></li>
<li><span class="font-mono mr-4 md:mr-6"><%= Node.self() %></span></li>
<li><span class="font-mono mr-4 md:mr-6"><%= System.get_env("FLY_REGION") %></span></li>
<div>
<span class="font-mono mr-4 text-sm text-gray-900 sm:text-center">v<%= Application.get_env(:realtime, :version) %></span>
<span class="text-sm text-gray-900 sm:text-center">© <a href="https://supabase.com/" class="hover:underline">Supabase Inc</a></span>
</div>
<ul class="flex flex-wrap items-center mt-3 text-sm text-gray-900">
<li><span class="mr-4">Apache 2.0 License</span></li>
<li><span class="font-mono mr-4"><%= Realtime.Helpers.short_node_id() %></span></li>
<li><span class="font-mono mr-4"><%= System.get_env("FLY_REGION") %></span></li>
<li><%= live_render(@socket, RealtimeWeb.PingLive, id: "ping") %></li>
</ul>
</footer>
</footer>

1 comment on commit d8acf69

@vercel
Copy link

@vercel vercel bot commented on d8acf69 Jan 20, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.