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

Supavisor V2 #408

Open
wants to merge 78 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
b0cf07f
chore: run CI tests when targeting `v2` branch (#376)
hauleth Jul 2, 2024
179912e
chore: add eflambe to dev dependencies (#373)
hauleth Jul 2, 2024
2d5744e
ft: improve some decoding paths (#372)
hauleth Jul 2, 2024
c1d9f9a
chore: use `or/2` over `||/2` (#371)
hauleth Jul 2, 2024
a6b4a0f
ft: do not traverse whole state for actions handling (#377)
hauleth Jul 2, 2024
61b48dd
ft: gather metrics with low priority (#379)
hauleth Jul 2, 2024
b436f9e
chore: fetch PLT cache with relaxed key as well (#380)
hauleth Jul 2, 2024
d7ba466
ft: update Ranch to 2.0 (#382)
hauleth Jul 2, 2024
bf0853b
chore: new pgbench task (#381)
hauleth Jul 4, 2024
bd80abc
feat: remove partisan (#383)
abc3 Jul 8, 2024
9b0ce29
chore: update tests to use peer module instead of ct_slave (#368)
hauleth Jul 8, 2024
ddf8f01
ft: use Peep as a PromEx storage (#384)
hauleth Jul 8, 2024
540bb81
chore: add comments about forks (#388)
hauleth Jul 8, 2024
36c8ac8
fix: do not remove logging in dev environment (#387)
hauleth Jul 8, 2024
aaca1cf
chore: do not call `Access` twice (#370)
hauleth Jul 8, 2024
b1fa449
chore: update dependencies (#389)
hauleth Jul 8, 2024
6952f8b
chore: remove common_test from required applications (#391)
hauleth Jul 8, 2024
699f9ff
ft: remove all HTML-related functionalities (#392)
hauleth Jul 9, 2024
3424615
fix: response type definition (#393)
hauleth Jul 9, 2024
8302e79
chore: dump rustler to 0.34.0 and remove burrito (#395)
abc3 Jul 10, 2024
e0663a5
chore: small style cleanups (#396)
hauleth Jul 10, 2024
95dc53c
chore: fix typing errors (#397)
hauleth Jul 10, 2024
357ca08
chore: move to new deps heads after rebases (#399)
hauleth Jul 12, 2024
b980c11
feat: implement proxy handler (#401)
abc3 Jul 17, 2024
57d2ca2
chore: add Nix Flake to project (#400)
hauleth Jul 18, 2024
c7c9333
fix: correct Peep Git commit hash after force push (#404)
hauleth Jul 23, 2024
4e6ec5f
chore: use mainline Peep (#406)
hauleth Jul 30, 2024
d554320
style(nix): reformat Nix files (#407)
hauleth Jul 30, 2024
52191da
feat: add new transaction handler (#402)
abc3 Jul 31, 2024
6e54020
chore: get rid of short names (#409)
abc3 Aug 1, 2024
503b653
fix: better handle application name (#412)
abc3 Aug 2, 2024
a19ecaf
chore(native/pgparser): refactor code (#410)
hauleth Aug 2, 2024
f8d5f09
chore: update Erlang version in Flake (#414)
hauleth Aug 2, 2024
c1880da
test: reduce amount of error log messages during tests (#415)
hauleth Aug 2, 2024
e081f4d
feat: disable metrics via environment variable (#411)
abc3 Aug 3, 2024
5b5de8d
test: update Postgrex to 0.19.0 (#418)
hauleth Aug 21, 2024
e841d84
feat: directly send to socket (#419)
abc3 Aug 21, 2024
7940761
style: clean Credo warnings (#413)
hauleth Aug 21, 2024
320dfb3
fix: handle prepared statements (#421)
abc3 Aug 22, 2024
3c7d075
fix: cleanup warnings (#420)
hauleth Aug 22, 2024
0d254fc
feat: ability to determine the pool node by aws zone (#422)
abc3 Aug 22, 2024
c54b9c5
chore: rename aws_zone to availability_zone (#423)
abc3 Aug 22, 2024
38982c4
feat: show availability_zone in logs metadata if it is available (#424)
abc3 Aug 23, 2024
8aeee4e
fix: set active false before try_ssl_handshake() (#425)
abc3 Aug 23, 2024
19d5980
fix: canceling statement (#426)
abc3 Aug 23, 2024
b5f37c4
fix: sni_hostname typo (#427)
abc3 Aug 23, 2024
ecafdcf
fix: convert sni to charlsit (#428)
abc3 Aug 23, 2024
da84144
fix: ignore ssl enforcement for proxy (#429)
abc3 Aug 23, 2024
51c0aad
chore: change log level for some pg messages (#430)
abc3 Aug 23, 2024
895ffef
feat: limit the number of pools per tenant (#432)
abc3 Aug 27, 2024
d08824b
feat: disable active socket during long queries (#434)
abc3 Aug 28, 2024
af737a5
feat: add a background metrics cleaner (#435)
abc3 Aug 29, 2024
fd8fe79
feat: change max_pools to 20 (#436)
abc3 Aug 30, 2024
43aeb60
fix: session mode during proxy (#437)
abc3 Aug 30, 2024
02c43f6
feat: forward errors from the database to the client (#439)
abc3 Sep 16, 2024
163e4fa
feat: add search_path support on connection (#440)
abc3 Sep 16, 2024
7971b25
bump 2.0.1 (#441)
abc3 Sep 16, 2024
31aa33c
chore: silence invalid application name error (#444)
abc3 Sep 18, 2024
ccf52fb
fix: search_path in MetricsCleaner (#446)
abc3 Sep 18, 2024
006172f
chore: update mailmap (#447)
hauleth Sep 24, 2024
d579414
chore: only supa folks in mailmap, bump version to 2.0.2 (#448)
abc3 Sep 25, 2024
d4d862a
fix: also notify the client about ready_for_query in session mode (#450)
abc3 Sep 25, 2024
916331f
fix: handling of active_count (#451)
abc3 Sep 30, 2024
24c54e3
chore: set service description filetype to systemd (#454)
hauleth Oct 3, 2024
14d599b
chore: switch to upstream PromEx (#453)
hauleth Oct 3, 2024
8cf032e
chore: add middle name to mailmap (#455)
hauleth Oct 4, 2024
4f6ed06
fix: add local proxy multiplier (#456)
abc3 Oct 4, 2024
ff20689
fix: subscription retries (#461)
abc3 Oct 8, 2024
26abc2c
feat: shorter retry connect timeout for proxy mode
abc3 Oct 8, 2024
5759ec6
cache for the pool conf
abc3 Oct 11, 2024
4b7f7fe
update def value
abc3 Oct 14, 2024
b8da64c
Merge pull request #462 from supabase/feat/retry_timeout
abc3 Oct 25, 2024
de98cd6
feat: periodically check auth_query creds (#464)
abc3 Oct 25, 2024
664fc5c
chore: name validation for user and db_name (#465)
abc3 Oct 28, 2024
a6cb71f
chore: update poolboy to v0.0.3 and enhance error logging and (#466)
abc3 Oct 30, 2024
3893fca
fix: update db_pid structure in terminate function (#467)
abc3 Nov 4, 2024
07b4008
test: add assertion testing if value passes eventually (#470)
hauleth Nov 5, 2024
0f770a9
chore: check if lockfile is up to date (#469)
hauleth Nov 5, 2024
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
121 changes: 35 additions & 86 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- main
- v2

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down Expand Up @@ -35,50 +36,7 @@ jobs:
restore-keys: |
${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get

compile:
name: Compile project in test env
runs-on: u22-arm-runner
needs: [deps]

steps:
- uses: actions/checkout@v4
- name: Setup Elixir
id: beam
uses: erlef/setup-beam@v1
with:
otp-version: '25.3.2.7'
elixir-version: '1.14.5'
- name: Cache Mix
uses: actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-mix-
- name: Cache Build
uses: actions/cache@v4
with:
path: |
_build/${{ env.MIX_ENV }}
key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ env.MIX_ENV }}-
- name: Cache native
uses: actions/cache@v4
id: native-cache
with:
path: |
priv/native
key: ${{ runner.os }}-build-native-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/*')) }}
- name: Set up Rust
uses: dtolnay/rust-toolchain@v1
if: steps.native-cache.outputs.cache-hit != 'true' || steps.elixir-cache.output.cache-hit != 'true'
with:
toolchain: stable
- name: Compile
run: mix compile
run: mix deps.get --check-locked

format:
name: Formatting checks
Expand All @@ -98,15 +56,13 @@ jobs:
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-mix-
- name: Run format check
run: mix format --check-formatted

credo:
name: Code style
runs-on: u22-arm-runner
needs: [compile]
needs: [deps]

steps:
- uses: actions/checkout@v4
Expand All @@ -121,23 +77,15 @@ jobs:
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-mix-
- name: Cache Build
uses: actions/cache@v4
with:
path: |
_build/${{ env.MIX_ENV }}
key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ env.MIX_ENV }}-
- name: Compile deps
run: mix deps.compile
- name: Credo checks
run: mix credo --strict --mute-exit-status
run: mix credo --strict --all --mute-exit-status

tests:
name: Run tests
runs-on: u22-arm-runner
needs: [compile]
needs: [deps]

steps:
- uses: actions/checkout@v4
Expand All @@ -149,30 +97,29 @@ jobs:
elixir-version: '1.14.5'
- name: Set up Rust
uses: dtolnay/rust-toolchain@v1
if: steps.native-cache.outputs.cache-hit != 'true' || steps.elixir-cache.output.cache-hit != 'true'
with:
toolchain: stable
- name: Cache Mix
uses: actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-mix-
- name: Cache Build
uses: actions/cache@v4
with:
path: |
_build/${{ env.MIX_ENV }}
key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ env.MIX_ENV }}-
- name: Cache native
uses: actions/cache@v4
with:
path: |
priv/native
key: ${{ runner.os }}-build-native-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/*')) }}
_build/${{ env.MIX_ENV }}/lib/supavisor/native
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-build-native-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/Cargo.lock')) }}
restore-keys: |
${{ runner.os }}-build-native-
- name: Compile deps
run: mix deps.compile
- name: Compile
run: mix compile
- name: Set up Postgres
run: docker-compose -f ./docker-compose.db.yml up -d
- name: Start epmd
Expand All @@ -183,7 +130,7 @@ jobs:
dialyzer:
name: Dialyze
runs-on: u22-arm-runner
needs: [compile]
needs: [deps]

steps:
- uses: actions/checkout@v4
Expand All @@ -195,36 +142,38 @@ jobs:
elixir-version: '1.14.5'
- name: Set up Rust
uses: dtolnay/rust-toolchain@v1
if: steps.native-cache.outputs.cache-hit != 'true' || steps.elixir-cache.output.cache-hit != 'true'
with:
toolchain: stable
- name: Cache Mix
uses: actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-mix-
- name: Cache Build
uses: actions/cache@v4
with:
path: |
_build/${{ env.MIX_ENV }}
key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ env.MIX_ENV }}-
- name: Cache native
uses: actions/cache@v4
with:
path: |
priv/native
key: ${{ runner.os }}-build-native-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/*')) }}
_build/${{ env.MIX_ENV }}/lib/supavisor/native
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-build-native-${{ hashFiles(format('{0}{1}', github.workspace, '/native/**/Cargo.lock')) }}
restore-keys: |
${{ runner.os }}-build-native-
- name: Compile deps
run: mix deps.compile
- name: Compile
run: mix compile
- name: Retrieve PLT Cache
uses: actions/cache@v4
id: plt-cache
with:
path: _build/${{ env.MIX_ENV }}/*.plt
key: ${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-plts-

- name: Create PLTs
if: steps.plt-cache.outputs.cache-hit != 'true'
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ burrito_out/*
supavisor-*.tar.gz

priv/native/*
*.bggg
/.pre-commit-config.yaml
3 changes: 2 additions & 1 deletion .mailmap
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Stanislav Muzhyk <[email protected]> <[email protected]>

Joel Lee <[email protected]> <[email protected]>
Joel Lee <[email protected]> <[email protected]>

Dimitris Zorbas <[email protected]> <[email protected]>
Łukasz Jan Niemier <[email protected]> <[email protected]>
67 changes: 55 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dev:
SECRET_KEY_BASE="dev" \
CLUSTER_POSTGRES="true" \
DB_POOL_SIZE="5" \
METRICS_DISABLED="false" \
AVAILABILITY_ZONE="ap-southeast-1b" \
ERL_AFLAGS="-kernel shell_history enabled +zdbbl 2097151" \
iex --name [email protected] --cookie cookie -S mix run --no-halt

Expand All @@ -26,7 +28,9 @@ dev.node2:
CLUSTER_POSTGRES="true" \
PROXY_PORT_SESSION="5442" \
PROXY_PORT_TRANSACTION="6553" \
PARTISAN_PEER_PORT="10201" \
PROXY_PORT="5402" \
NODE_IP=localhost \
AVAILABILITY_ZONE="ap-southeast-1c" \
ERL_AFLAGS="-kernel shell_history enabled" \
iex --name [email protected] --cookie cookie -S mix phx.server

Expand All @@ -41,15 +45,8 @@ dev.node3:
CLUSTER_POSTGRES="true" \
PROXY_PORT_SESSION="5443" \
PROXY_PORT_TRANSACTION="6554" \
PARTISAN_PEER_PORT="10202" \
ERL_AFLAGS="-kernel shell_history enabled" \
iex --name [email protected] --cookie cookie -S mix phx.server

dev_bin:
MIX_ENV=dev mix release supavisor_bin && ls -l burrito_out

bin:
MIX_ENV=prod mix release supavisor_bin && ls -l burrito_out
iex --name [email protected] --cookie cookie -S mix phx.server

db_migrate:
mix ecto.migrate --prefix _supavisor --log-migrator-sql
Expand All @@ -65,15 +62,29 @@ db_rebuild:
docker-compose -f ./docker-compose.db.yml build
make db_start

PGBENCH_USER ?= postgres.sys
PGBENCH_PORT ?= 6543
PGBENCH_RATE ?= 5000
PGBENCH_DURATION ?= 60
PGBENCH_CLIENTS ?= 1000

pgbench_init:
PGPASSWORD=postgres pgbench -i -h 127.0.0.1 -p 6432 -U postgres -d postgres

pgbench_short:
PGPASSWORD=postgres pgbench -M extended --transactions 5 --jobs 4 --client 1 -h localhost -p 7654 -U transaction.localhost postgres
PGPASSWORD=postgres pgbench -M extended --transactions 5 --jobs 4 --client 1 -h localhost -p 6543 -U postgres.sys postgres

pgbench_long:
PGPASSWORD=postgres pgbench -M extended --transactions 100 --jobs 10 --client 60 -h localhost -p 7654 -U transaction.localhost postgres

pgbench:
PGPASSWORD="postgres" pgbench \
postgres://${PGBENCH_USER}@localhost:${PGBENCH_PORT}/postgres?sslmode=disable \
-Srn -T ${PGBENCH_DURATION} \
-j 8 -c ${PGBENCH_CLIENTS} \
-P 10 -M extended \
--rate ${PGBENCH_RATE}

clean:
rm -rf _build && rm -rf deps

Expand All @@ -94,5 +105,37 @@ dev_start_rel:
FLY_ALLOC_ID=111e4567-e89b-12d3-a456-426614174000 \
SECRET_KEY_BASE="dev" \
CLUSTER_POSTGRES="true" \
ERL_AFLAGS="-kernel shell_history enabled" \
./_build/dev/rel/supavisor/bin/supavisor start_iex
DB_POOL_SIZE="5" \
_build/prod/rel/supavisor/bin/supavisor start_iex

prod_rel:
MIX_ENV=prod METRICS_DISABLED=true mix compile && \
MIX_ENV=prod METRICS_DISABLED=true mix release supavisor

prod_start_rel:
MIX_ENV=prod \
NODE_NAME="localhost" \
VAULT_ENC_KEY="aHD8DZRdk2emnkdktFZRh3E9RNg4aOY7" \
API_JWT_SECRET=dev \
METRICS_JWT_SECRET=dev \
REGION=eu \
FLY_ALLOC_ID=111e4567-e89b-12d3-a456-426614174000 \
SECRET_KEY_BASE="dev" \
CLUSTER_POSTGRES="true" \
DB_POOL_SIZE="5" \
_build/prod/rel/supavisor/bin/supavisor start_iex

prod_start_rel2:
MIX_ENV=prod \
NODE_NAME=node2 \
PORT=4001 \
VAULT_ENC_KEY="aHD8DZRdk2emnkdktFZRh3E9RNg4aOY7" \
API_JWT_SECRET=dev \
METRICS_JWT_SECRET=dev \
REGION=eu \
SECRET_KEY_BASE="dev" \
CLUSTER_POSTGRES="true" \
PROXY_PORT_SESSION="5442" \
PROXY_PORT_TRANSACTION="6553" \
NODE_IP=localhost \
_build/prod/rel/supavisor/bin/supavisor start_iex
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.67
2.0.5
19 changes: 17 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import Config
config :supavisor,
ecto_repos: [Supavisor.Repo],
version: Mix.Project.config()[:version],
env: Mix.env()
env: Mix.env(),
metrics_disabled: System.get_env("METRICS_DISABLED") == "true",
switch_active_count: System.get_env("SWITCH_ACTIVE_COUNT", "100") |> String.to_integer(),
reconnect_retries: System.get_env("RECONNECT_RETRIES", "5") |> String.to_integer(),
subscribe_retries: System.get_env("SUBSCRIBE_RETRIES", "20") |> String.to_integer()

# Configures the endpoint
config :supavisor, SupavisorWeb.Endpoint,
Expand All @@ -23,7 +27,18 @@ config :supavisor, SupavisorWeb.Endpoint,
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id, :project, :user, :region, :instance_id, :mode, :type]
metadata: [
:request_id,
:project,
:user,
:region,
:instance_id,
:mode,
:type,
:app_name,
:peer_ip,
:local
]

# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason
Expand Down
16 changes: 14 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,20 @@ config :supavisor, SupavisorWeb.Endpoint,
config :logger, :console,
format: "$time [$level] $message $metadata\n",
level: :debug,
# level: :error,
metadata: [:error_code, :file, :line, :pid, :project, :user, :mode, :type]
# level: :notice,
metadata: [
:error_code,
:file,
:line,
:pid,
:project,
:user,
:mode,
:type,
:app_name,
:peer_ip,
:local
]

# Set a higher stacktrace during development. Avoid configuring such
# in production as building large stacktraces may be expensive.
Expand Down
Loading
Loading