Skip to content

Commit 7c47207

Browse files
committed
chore: add otel support to e2e tests (#1756)
now we can setup otel to track performance of each test and have properly defined spans per test
1 parent 3b0156b commit 7c47207

10 files changed

Lines changed: 711 additions & 43 deletions

File tree

test/e2e/README.md

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,43 @@
1111
| `--port` | | Override URL port (useful for local) |
1212
| `--test` | | Comma-separated list of test categories to run (runs all if omitted) |
1313
| `--json` | | Output results as JSON to stdout (all other output goes to stderr) |
14+
| `--url` | | Override project URL (e.g. `http://127.0.0.1:54321`) |
15+
| `--db-url` | | Override database URL (e.g. `postgresql://postgres:postgres@127.0.0.1:54322/postgres`) |
16+
| `--otel` | `OTEL_EXPORTER_OTLP_ENDPOINT` | OTLP HTTP endpoint for tracing (e.g. `http://localhost:4318`) |
17+
| | `OTEL_API_TOKEN` | Bearer token for authenticated OTLP endpoints |
1418

1519
Sensitive credentials (`--secret-key`, `SUPABASE_DB_PASSWORD`) should be set as environment variables to avoid them appearing in shell history.
1620

1721
A random test user is created at the start of each run and deleted automatically when it finishes.
1822

1923
## Test categories
2024

21-
Pass any combination to `--test` as a comma-separated list:
25+
Pass any combination to `--test` as a comma-separated list. Use `functional` to run all non-load suites, or `load` to run all load suites.
2226

23-
| Category | Description |
24-
|---|---|
25-
| `connection` | WebSocket connect latency and broadcast throughput |
26-
| `load` | Postgres changes and presence throughput (INSERT / UPDATE / DELETE) |
27-
| `broadcast` | Self-broadcast and REST broadcast API |
28-
| `presence` | Presence join on public and private channels |
29-
| `authorization` | Private channel allow/deny checks |
30-
| `postgres-changes` | Filtered INSERT, UPDATE, DELETE events and concurrent changes |
31-
| `broadcast-changes` | Database-triggered broadcast INSERT, UPDATE, DELETE events |
27+
| Category | Suites | Tests |
28+
|---|---|---|
29+
| `connection` | connection | First connect latency; broadcast message throughput |
30+
| `load` | load-postgres-changes | Postgres system message latency; INSERT / UPDATE / DELETE throughput via postgres changes |
31+
| | load-presence | Presence join throughput |
32+
| | load-broadcast-from-db | Broadcast-from-database throughput |
33+
| | load-broadcast | Self-broadcast throughput; REST broadcast API throughput |
34+
| | load-broadcast-replay | Broadcast replay throughput on channel join |
35+
| `broadcast` | broadcast extension | Self-broadcast receive; REST broadcast API send-and-receive |
36+
| `presence` | presence extension | Presence join on public channels; presence join on private channels |
37+
| `authorization` | authorization check | Private channel denied without permissions; private channel allowed with permissions |
38+
| `postgres-changes` | postgres changes extension | Filtered INSERT, UPDATE, DELETE events; concurrent INSERT + UPDATE + DELETE |
39+
| `broadcast-changes` | broadcast changes | DB-triggered broadcast for INSERT, UPDATE, DELETE |
40+
| `broadcast-replay` | broadcast replay | Replayed messages delivered on join; `meta.replayed` flag set; messages before `since` not replayed |
3241

3342
```bash
3443
# Run only connection and broadcast tests
3544
./realtime-check --env local --publishable-key <key> --secret-key <key> --test connection,broadcast
45+
46+
# Run all load tests
47+
./realtime-check --env local --publishable-key <key> --secret-key <key> --test load
48+
49+
# Run all functional (non-load) tests
50+
./realtime-check --env local --publishable-key <key> --secret-key <key> --test functional
3651
```
3752

3853
## JSON output
@@ -51,12 +66,31 @@ The pre-built binary requires no runtime — just run it directly.
5166

5267
### Local project
5368

69+
A `supabase/config.toml` is included, so `supabase start` works out of the box.
70+
5471
```bash
5572
supabase start
5673
SUPABASE_SERVICE_ROLE_KEY=<service-role-key> \
5774
./realtime-check --env local --publishable-key <anon-key>
5875
```
5976

77+
### Local project with tracing
78+
79+
```bash
80+
supabase start
81+
docker compose up -d # starts Jaeger at http://localhost:16686
82+
SUPABASE_SERVICE_ROLE_KEY=<service-role-key> \
83+
./realtime-check --env local --publishable-key <anon-key> --otel http://localhost:4318
84+
```
85+
86+
For authenticated OTLP endpoints, set `OTEL_API_TOKEN` and it will be sent as a `Bearer` token:
87+
88+
```bash
89+
SUPABASE_SERVICE_ROLE_KEY=<service-role-key> \
90+
OTEL_API_TOKEN=<token> \
91+
./realtime-check --env local --publishable-key <anon-key> --otel https://otlp.example.com
92+
```
93+
6094
### Remote project
6195

6296
```bash
@@ -102,7 +136,7 @@ SUPABASE_SERVICE_ROLE_KEY=<key> SUPABASE_DB_PASSWORD=<pw> \
102136
./result/bin/realtime-check --project <ref> --publishable-key <key>
103137
```
104138

105-
> **Note:** The nix build locks the dependency hash in `flake.nix`. If you update `package.json` or `bun.lock`, run `nix build` once — it will fail with the new hash in the error output — then update `outputHash` in `flake.nix` accordingly.
139+
`bun run nix` calls `nix-build.sh`, which automatically updates the `outputHash` in `flake.nix` when `package.json` or `bun.lock` change — no manual hash update needed.
106140

107141
---
108142

test/e2e/bun.lock

Lines changed: 73 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# E2e testing infrastructure. Requires `supabase start` to be running first.
2+
# Run from test/e2e:
3+
# docker compose up -d
4+
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 bun run realtime-check.ts --env local
5+
services:
6+
jaeger:
7+
image: jaegertracing/jaeger:2.5.0
8+
container_name: e2e-jaeger
9+
ports:
10+
- "16686:16686"
11+
- "4318:4318"

test/e2e/flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
installPhase = "cp -r node_modules $out";
3131
outputHashMode = "recursive";
3232
outputHashAlgo = "sha256";
33-
outputHash = "sha256-MK55AYy2z5nY7B30o8vt34+wk+86Zruz/q2ZDmA951c=";
33+
outputHash = "sha256-I7ZNZkyK83Lk+Ut3j6FngvWNfIl8JaW2cF4bfyVf5TQ=";
3434
};
3535
in {
3636
packages.default = pkgs.stdenv.mkDerivation {

test/e2e/nix-build.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
FLAKE="flake.nix"
5+
FAKE_HASH="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
6+
7+
# Replace current hash with fake to force nix to reveal the correct one
8+
sed -i.bak "s|outputHash = \"sha256-.*\";|outputHash = \"${FAKE_HASH}\";|" "$FLAKE"
9+
rm -f "${FLAKE}.bak"
10+
11+
echo "Probing for correct node_modules hash..."
12+
NIX_OUT=$(nix build 2>&1 || true)
13+
14+
REAL_HASH=$(echo "$NIX_OUT" | grep "got:" | awk '{print $2}')
15+
16+
if [[ -z "$REAL_HASH" ]]; then
17+
# No hash mismatch error — either build succeeded or failed for another reason
18+
if echo "$NIX_OUT" | grep -q "error:"; then
19+
echo "Build failed:"
20+
echo "$NIX_OUT"
21+
git checkout -- "$FLAKE" 2>/dev/null || true
22+
exit 1
23+
else
24+
echo "Hash was already correct. Build succeeded."
25+
echo "Done. Binary available at ./result/bin/realtime-check"
26+
exit 0
27+
fi
28+
fi
29+
30+
echo "Updating hash to: $REAL_HASH"
31+
sed -i.bak "s|outputHash = \"${FAKE_HASH}\";|outputHash = \"${REAL_HASH}\";|" "$FLAKE"
32+
rm -f "${FLAKE}.bak"
33+
34+
echo "Building with correct hash..."
35+
nix build
36+
echo "Done. Binary available at ./result/bin/realtime-check"

0 commit comments

Comments
 (0)