feat(BIT-247): consolidate error reporting repo from OTT

Merge ingest-api, collector-worker, admin-ui, database/error_reporting, deploy/lxc,
docker-compose, and deployment docs into the dedicated repository. Paths updated
for repo root (ER_REPO_ROOT, systemd WorkingDirectory). Root README documents layout.

Co-Authored-By: Paperclip <[email protected]>
This commit is contained in:
1sonhadorandPaperclip committed 2026-03-22 18:20:27 +00:00
1 parent eeb5039a3c
commit b0b733d5e1
88 files changed
+19321

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
# Native LXC deploy (no Docker)
Scripts and unit files for running **ingest-api**, **admin-ui**, and **collector-worker** on Debian/Ubuntu LXC with **PostgreSQL** on the same CT or another host.
Authoritative runbook: [`docs/deployment/bitreport-error-reporting-lxc-proxmox.md`](../../docs/deployment/bitreport-error-reporting-lxc-proxmox.md).
| Path | Purpose |
|------|---------|
| `env.example` | Template for `/etc/error-reporting/env` |
| `run-migrate.sh` | Apply migrations + seed (after Postgres is up) |
| `verify.sh` | `curl` ingest `/health` and optional checks |
| `systemd/*.service` | Unit files (adjust `WorkingDirectory` if not `/opt/errors.bitreport.pt`) |
| `nginx/*.conf.example` | TLS reverse proxy sketch |
Docker-based path remains in [`../../docker-compose.yml`](../../docker-compose.yml) and [`../../docs/deployment/bitreport-error-reporting-compose-proxmox.md`](../../docs/deployment/bitreport-error-reporting-compose-proxmox.md).
+32
View File
@@ -0,0 +1,32 @@
# Copy to /etc/error-reporting/env (mode 640, root:root or root:error-reporting).
# systemd parses this as EnvironmentFile= — use KEY=value only, no "export".
# --- Checkout root: this repository (contains database/, ingest-api/, admin-ui/, ...) ---
ER_REPO_ROOT=/opt/errors.bitreport.pt
# Legacy variable name (still read by run-migrate.sh if ER_REPO_ROOT is unset):
# OTT_ROOT=/opt/errors.bitreport.pt
# --- PostgreSQL (single LXC: localhost; split DB LXC: set host accordingly) ---
# URL-encode special characters in user/password per PostgreSQL libpq rules.
DATABASE_URL=postgres://postgres:[email protected]:5432/error_reporting
# --- ingest-api ---
PORT=3041
NODE_ENV=production
INGEST_RATE_LIMIT_MAX=300
INGEST_RATE_LIMIT_WINDOW_MS=60000
# --- collector-worker ---
INGEST_BASE_URL=http://127.0.0.1:3041
TICK_INTERVAL_MS=3000
SOURCE_REFRESH_MS=15000
HTTP_FETCH_TIMEOUT_MS=15000
MAX_BACKOFF_EXPONENT=8
# --- admin-ui (Next.js server-side API calls) ---
ERROR_REPORTING_ADMIN_API_BASE=http://127.0.0.1:3041
# ERROR_REPORTING_UI_DEMO=1
# --- Demo / staging only: token must match seed SQL for project-alpha HTTP fixture ---
# ER_COLLECTOR_PROJECT_ALPHA_TOKEN=er_tst_a_secret_one
# COLLECTOR_DEFAULT_INGEST_TOKEN=
@@ -0,0 +1,37 @@
# Example TLS reverse proxy on the Proxmox host or a dedicated proxy LXC.
# Replace hostnames and upstream ports (3041 = ingest-api, 3040 = admin-ui).
# Install: copy to /etc/nginx/sites-available/ and enable via symlink.
# --- Ingest API (clients, collectors) ---
server {
listen 443 ssl http2;
server_name er-ingest.example.com;
# ssl_certificate ...;
# ssl_certificate_key ...;
location / {
proxy_pass http://127.0.0.1:3041;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
# --- Admin UI (operators) ---
server {
listen 443 ssl http2;
server_name er-admin.example.com;
# ssl_certificate ...;
# ssl_certificate_key ...;
location / {
proxy_pass http://127.0.0.1:3040;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Apply error_reporting SQL migrations and seeds (same order as docker-migrate.sh).
# Prerequisites: psql (postgresql-client), empty or already-migrated DB, DATABASE_URL + ER_REPO_ROOT (or legacy OTT_ROOT).
set -euo pipefail
_ENV_FILE="/etc/error-reporting/env"
if [[ -f "${_ENV_FILE}" ]]; then
set -a
# shellcheck disable=SC1090
source "${_ENV_FILE}"
set +a
fi
_REPO_ROOT="${ER_REPO_ROOT:-${OTT_ROOT:-}}"
: "${_REPO_ROOT:?Set ER_REPO_ROOT to this repository root (contains database/error_reporting/). Legacy OTT_ROOT is accepted.}"
: "${DATABASE_URL:?Set DATABASE_URL (postgres://...) for psql}"
_MIG="${_REPO_ROOT}/database/error_reporting/migrations"
_SEED="${_REPO_ROOT}/database/error_reporting/seed"
if [[ ! -d "${_MIG}" ]]; then
echo "run-migrate: migrations directory not found: ${_MIG}" >&2
exit 1
fi
_run_sql() {
psql "${DATABASE_URL}" -v ON_ERROR_STOP=1 -f "$1"
}
_run_sql "${_MIG}/20260322043000_create_error_reporting_core.up.sql"
_run_sql "${_MIG}/20260322044000_create_error_occurrences_and_states.up.sql"
_run_sql "${_MIG}/20260322044500_add_ingest_idempotency.up.sql"
_run_sql "${_MIG}/20260322045000_create_collectors_retention_and_audit.up.sql"
_run_sql "${_SEED}/dev_two_projects.sql"
_run_sql "${_SEED}/dev_collector_http_fixture.sql"
echo "run-migrate: complete"
@@ -0,0 +1,19 @@
[Unit]
Description=BitReport error reporting admin UI (Next.js)
After=network-online.target bitreport-error-reporting-ingest-api.service
Wants=network-online.target
[Service]
Type=simple
User=error-reporting
Group=error-reporting
EnvironmentFile=-/etc/error-reporting/env
WorkingDirectory=/opt/errors.bitreport.pt/admin-ui
ExecStart=/usr/bin/npm run start
Restart=on-failure
RestartSec=5
NoNewPrivileges=yes
PrivateTmp=yes
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,19 @@
[Unit]
Description=BitReport error reporting collector worker
After=network-online.target bitreport-error-reporting-ingest-api.service postgresql.service
Wants=network-online.target
[Service]
Type=simple
User=error-reporting
Group=error-reporting
EnvironmentFile=-/etc/error-reporting/env
WorkingDirectory=/opt/errors.bitreport.pt/collector-worker
ExecStart=/usr/bin/node dist/main.js
Restart=on-failure
RestartSec=5
NoNewPrivileges=yes
PrivateTmp=yes
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,19 @@
[Unit]
Description=BitReport error reporting ingest API (Fastify)
After=network-online.target postgresql.service
Wants=network-online.target
[Service]
Type=simple
User=error-reporting
Group=error-reporting
EnvironmentFile=-/etc/error-reporting/env
WorkingDirectory=/opt/errors.bitreport.pt/ingest-api
ExecStart=/usr/bin/node dist/server.js
Restart=on-failure
RestartSec=5
NoNewPrivileges=yes
PrivateTmp=yes
[Install]
WantedBy=multi-user.target
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# Smoke checks after install: Postgres reachability (optional) + ingest /health.
set -euo pipefail
_ENV_FILE="/etc/error-reporting/env"
if [[ -f "${_ENV_FILE}" ]]; then
set -a
# shellcheck disable=SC1090
source "${_ENV_FILE}"
set +a
fi
_INGEST_URL="${INGEST_HEALTH_URL:-http://127.0.0.1:${PORT:-3041}/health}"
echo "verify: GET ${_INGEST_URL}"
if ! curl -sf "${_INGEST_URL}" >/dev/null; then
echo "verify: ingest /health failed" >&2
exit 1
fi
echo "verify: ingest OK"
if command -v pg_isready >/dev/null 2>&1 && [[ -n "${DATABASE_URL:-}" ]]; then
# pg_isready does not accept URI; probe TCP only when URL is simple localhost.
if [[ "${DATABASE_URL}" == *"@127.0.0.1:"* ]] || [[ "${DATABASE_URL}" == *"@localhost:"* ]]; then
echo "verify: pg_isready (best-effort, discrete vars may be needed on some hosts)"
_pgport="${PGPORT:-5432}"
pg_isready -h 127.0.0.1 -p "${_pgport}" || true
fi
fi
_ADMIN_PORT="${ADMIN_UI_PORT:-3040}"
if curl -sf "http://127.0.0.1:${_ADMIN_PORT}/" >/dev/null 2>&1; then
echo "verify: admin-ui HTTP on port ${_ADMIN_PORT} OK"
else
echo "verify: admin-ui not responding on ${_ADMIN_PORT} (expected if service stopped or demo mode off)"
fi
echo "verify: done"