Athena RS 2.8.1
current version: 2.12.1
Table of Contents
- Overview
- Quickstart
- Architecture
- API Reference
- CLI Tools
- SDK
- Supported Drivers
- Configuration
- Realtime Connection Registry
- WebSocket Gateway
- Web Explorer
- Docker
- Testing & Linting
- Contributing
Overview
Athena is a lightweight database gateway that proxies and executes queries across Athena/ScyllaDB, PostgreSQL, and Supabase backends. The Actix-powered API normalizes headers, shapes JSON payloads, and exposes helper utilities so API consumers, dashboards, and embedded tooling all speak the same surface.
Key features:
- Gateway surface:
/gateway/fetch,/gateway/update,/gateway/insert,/gateway/delete, and/gateway/queryaccept structured payloads, route viaX-Athena-Client, and normalize camelCase / snake_case when configured. - Online client catalog:
x-athena-clientresolution now supports both legacyconfig.yamlentries and database-backed client rows stored in theathena_loggingdatabase, with a local in-memory registry for hot-path performance. - Post-processing: Fetch/update responses honor optional
group_by,time_granularity,aggregation_column,aggregation_strategy, andaggregation_dedup. When those fields are present, the response includes apost_processing.groupedarray with labels, rows, and aggregation metadata. - SQL executor:
/query/sqlreroutes raw SQL to Athena/Scylla, PostgreSQL pools (SQLx), or Supabase while sharing the sameX-Athena-Clientrouting registry. - Proxy helpers:
proxy_requestforwards arbitrary REST calls with auth header management and caching helpers inapi::cache. - Cache layer: Built on
mokawith optional Redis write-through and TTL management. - Admin control plane:
/admin/clients*manages client creation, editing, freeze/unfreeze, removal, and aggregated client statistics traced from the existing gateway log tables;/admin/provisionand/admin/backups*handle schema bootstrap plus S3-based backups/restores. - Configuration:
config.yamlstill bootstraps the server, logging/auth clients, Redis caching, and the camel-to-snake toggle; download the synced HTTP spec viaGET /openapi.yamland the WebSocket contract viaGET /openapi-wss.yaml(covers/wss/gateway,/wss/info,/health, and/readyfor the Bun proxy) so you can import both into OpenAPI tooling.
Quickstart
Prerequisites
- Rust 1.85+
- Docker (optional, for local Postgres/Redis)
1) Configure
- Update config.yaml
- Set your Postgres URIs with environment variables
Example local logging DB:
- POSTGRES_ATHENA_LOGGING_URI=postgres://athena:athena@localhost:5433/athena_logging
2) Run
3) Use
- Send X-Athena-Client on gateway requests
- Use apikey for protected endpoints
Core Endpoints
Gateway
- POST /gateway/fetch
- PUT /gateway/insert
- POST /gateway/update
- DELETE /gateway/delete
- POST /gateway/query
Deferred Queue
- GET /gateway/deferred/{request_id}
- POST /gateway/deferred/{request_id}/requeue
Health and Specs
- GET /
- GET /ping
- GET /health
- GET /metrics
- GET /openapi.yaml
- GET /openapi-wss.yaml
Minimal Request Examples
Deferred query
POST /gateway/query
X-Athena-Client: reporting
X-Athena-Defer: true
Content-Type: application/json
{
"query": "SELECT now()"
}
Check deferred status
GET /gateway/deferred/REQUEST_ID
Requeue failed or completed job
POST /gateway/deferred/REQUEST_ID/requeue
Config Essentials
In config.yaml, focus on:
- api.port
- postgres_clients
- gateway settings for admission/defer/worker
- logging/auth client names
Useful gateway knobs:
- gateway.admission_limit_enabled
- gateway.admission_global_requests_per_window
- gateway.admission_per_client_requests_per_window
- gateway.admission_window_secs
- gateway.admission_defer_on_limit_enabled
- gateway.admission_defer_route_prefixes
- gateway.deferred_query_worker_enabled
- gateway.deferred_query_worker_poll_ms
Operational Alerts
Use these Prometheus rules as a baseline:
groups:
- name: athena-deferred-queue
rules:
- alert: AthenaDeferredQueueBacklogGrowing
expr: athena_gateway_deferred_queue_requests{status="queued"} > 200
for: 5m
labels:
severity: warning
annotations:
summary: "Athena deferred queue backlog is high"
description: "Queued deferred requests stayed above 200 for 5 minutes."
- alert: AthenaDeferredQueueStuckOldest
expr: athena_gateway_deferred_queue_oldest_age_seconds > 300
for: 10m
labels:
severity: critical
annotations:
summary: "Athena deferred queue appears stuck"
description: "Oldest queued/running deferred request age exceeded 5 minutes."
- alert: AthenaDeferredQueueStorageDown
expr: athena_gateway_deferred_queue_storage_up == 0
for: 2m
labels:
severity: critical
annotations:
summary: "Athena deferred queue storage unavailable"
description: "Logging Postgres is unreachable for deferred queue reads."
- alert: AthenaDeferredQueryFailuresBurst
expr: increase(athena_gateway_deferred_events_total{kind="gateway_query",status="failed"}[10m]) > 10
for: 0m
labels:
severity: warning
annotations:
summary: "Athena deferred query failures are spiking"
description: "More than 10 deferred query jobs failed in the last 10 minutes."
Common Commands
API Keys
Athena persists API keys in the api_keys family of tables. The master record is api_keys, which stores public_id, name, description, an optional client_name, and the salt/hash for the secret. Columns like api_keys_id, created_at, and updated_at are generated in the database, and api_keys_id is the UUID returned to callers while the internal bigint id backs foreign keys. api_key_rights names the allowed capability strings, api_key_right_grants bridges keys to rights, api_key_config keeps global enforcement, api_key_client_config holds per-client overrides, and api_key_auth_log records every authentication attempt (request metadata, presented hash, granted rights, failure reason, etc.).
All of the /admin/* surfaces and the protected /schema/clients + /clients endpoints require the static admin key stored in the ATHENA_KEY_12 environment variable. Provide that key through Authorization: Bearer <key>, apikey, x-api-key, x-athena-key, or the ?api_key= query string when invoking these routes.
When you hit POST /admin/api-keys, Athena generates a public_id, secrets (salt/hash), and returns the plaintext credential as ath_{public}.{secret}. Capture the secret at creation time; it cannot be retrieved later. Rights can be assigned at creation or updated later by supplying the rights array.
Admin API key routes
GET /admin/api-keys– list all API key records plus granted rights.POST /admin/api-keys– create a new API key by providingname, optionaldescription, optionalclient_name, optionalexpires_attimestamp, and optionalrights.PATCH /admin/api-keys/{id}– adjust an existing key (name, description, client, expiry, active flag, rights).DELETE /admin/api-keys/{id}– archive the key.GET /admin/api-key-rights– list every right string that can be granted.POST /admin/api-key-rights– create a new right (name + optional description).PATCH /admin/api-key-rights/{id}– rename/describe a right.DELETE /admin/api-key-rights/{id}– remove a right (cascades viaapi_key_right_grants).GET /admin/api-key-config– read the global enforcement setting plus the client overrides.PUT /admin/api-key-config– flip the globalenforce_api_keysflag.GET /admin/api-key-clients– list the per-client overrides.PUT /admin/api-key-clients/{client_name}– upsert a per-client override.DELETE /admin/api-key-clients/{client_name}– remove a client override and fall back to the global setting.
Client Catalog Admin Routes
Athena stores scalable client definitions in the athena_clients table inside the athena_logging database. Each row can reference either a direct pg_uri or a pg_uri_env_var, and bootstrap will also seed config-only clients into the table so old installs migrate forward without duplicate entries.
GET /admin/clients– list the database catalog plus the current runtime registry snapshot.POST /admin/clients– create a database-managed client by sendingclient_nameand eitherpg_uriorpg_uri_env_var.PATCH /admin/clients/{client_name}– update connection settings, description, or active state.PUT /admin/clients/{client_name}/freeze– freeze or unfreeze a client without deleting its catalog row.DELETE /admin/clients/{client_name}– soft-delete a client from the database catalog and remove it from the runtime registry.GET /admin/clients/statistics– list aggregated request and operation counts per client.POST /admin/clients/statistics/refresh– rebuildclient_statisticsandclient_table_statisticsfrom the existing log tables.GET /admin/clients/{client_name}/statistics– inspect totals plus per-table operation counts for one client.GET /admin/clients/{client_name}/statistics/drilldown– listgateway_operation_logrows for a giventable_nameandoperation(query paramsstatus,limit,offset).
Frozen or deleted database rows are removed from the hot-path registry, so request handlers keep using local memory instead of querying the catalog table for every call.
Every admin response is described in openapi.yaml, so use that spec if you need payload samples, response codes, or schema definitions.
Success example:
Error example:
CLI Tools
Rust CLI
The athena_rs binary exposes CLI helpers alongside the HTTP API. Global flags apply to every subcommand:
--config/--config-path <PATH>overrideconfig.yaml(default:config.yaml). The same path may be set withATHENA_CONFIG_PATH(CLI wins if both are set).--pipelines <PATH>overrides the default pipeline definitions file (config/pipelines.yaml).--port <PORT>overrides the API port when booting the server.--api-onlyboots the server (same asserver).
Configuration load order (searched in this order and logged when missing):
%APPDATA%/athena%LOCALAPPDATA%/athena%USERPROFILE%/.athena$XDG_CONFIG_HOME/athena$HOME/.config/athena$HOME/.athena~/Library/Application Support/athena(macOS)- Current working directory
If no config file is found, Athena copies the bundled config.yaml into the first writable directory before loading it. Errors list every inspected location so you can troubleshoot missing configs.
Commands:
server(or--api-only): start the Actix Web server. Respect--port,--config, and--pipelinesoverrides.pipeline: run an inline pipeline with--client <NAME>,--payload-json,--payload-file, and--pipeline <NAME>to reference prebuilt definitions.clientssubcommands (list,add,remove,set-default): mutateconfig/clients.jsonthat stores reusable Postgres connection names.fetch: proxy a gateway fetch request tohttps://athena-db.com/gateway/fetch(or the URL supplied via--url). Use--clientto pick a saved client and--body-json/--body-fileto supply the payload.diag: print OS, architecture, CPU count, Rust version, hostname, and locale metadata.version: show the build version (cargo run -- --versionworks too).
Systemd: see scripts/athena.service. Set ATHENA_CONFIG_PATH in EnvironmentFile (for example .env) or pass --config <ABSOLUTE_PATH> in ExecStart.
TypeScript CLI
The CLI in cli/ generates SQL/CQL artifacts from Supabase schema metadata.
Installation:
Test
Lint and format
API only server
Web and CLI
- Web explorer: apps/web
- TypeScript CLI: cli
Notes
- If a client is missing or offline, Athena keeps running with available clients.
- For custom Supabase routing, include x-supabase-url and x-supabase-key headers.
- OpenAPI contracts are served directly from the API process.