urls:
  - athena: "${ATHENA_DB_URL}"

hosts:
  - athena: athena-db.com
  - scylladb: "${SCYLLADB_HOST}"

authenticator:
  - scylladb:
      username: "${SCYLLADB_USERNAME}"
      password: "${SCYLLADB_PASSWORD}"
  - athena:
      username: "${ATHENA_USERNAME}"
      password: "${ATHENA_PASSWORD}"

api:
  - port: 4052
  # Immortal cache.
  - immortal_cache: false
  # Cache TTL in seconds.
  - cache_ttl: 240
  # Pool idle timeout in seconds.
  - pool_idle_timeout: 90
  - keep_alive_secs: 15
  - client_disconnect_timeout_secs: 60
  # Client request timeout in seconds.
  - client_request_timeout_secs: 60
  # HTTP workers.
  - http_workers: 8
  # Max connections for the HTTP server.
  - http_max_connections: 10000
  # Backlog for the HTTP server.
  - http_backlog: 2048
  - tcp_keepalive_secs: 75
  # Allow any origin.
  - cors_allow_any_origin: true
  - cors_allowed_origins: "https://athena-db.com,https://athena-cluster.com, https://studio.athena-db.com,http://localhost:3000, https://mirror1.athena-db.com, https://mirror2.athena-db.com, https://mirror3.athena-db.com, https://pool.athena-db.com, https://cluster.athena-db.com"

gateway:
  # Force camelCase to snake_case normalization.
  - force_camel_case_to_snake_case: false
  # Auto cast UUID filter values to text.
  - auto_cast_uuid_filter_values_to_text: true
  # Allow schema names prefixed as table names.
  - allow_schema_names_prefixed_as_table_name: true
  # Optional: override the Postgres URI used by the logging client only.
  # When set, Athena will connect this URI specifically for logging_client,
  # independent of postgres_clients entries.
  - logging_pg_uri: "${POSTGRES_ATHENA_LOGGING_URI}"
  - logging_pg_uri_env_var: "POSTGRES_ATHENA_LOGGING_URI"
  - logging_client: "athena_logging"
  - auth_client: "athena_logging"
  # Client name for gateway E2E benchmarks (`cargo bench --bench gateway_e2e`).
  # Override with env `ATHENA_BENCHMARK_CLIENT`. Defaults to logging_client when omitted.
  - benchmark_client: "athena_logging"
  - jdbc_allow_private_hosts: true
  - jdbc_allowed_hosts: ""
  # Resilience: timeout (secs), read retries, initial backoff (ms)
  - resilience_timeout_secs: 30
  # Resilience: max retries for read operations on transient failures.
  - resilience_read_max_retries: 1
  # Resilience: initial backoff between retries in milliseconds.
  - resilience_initial_backoff_ms: 100
  # Admission limiter: fixed-window requests per second (0 = unlimited)
  - admission_limit_enabled: false
  # Admission window size in seconds.
  - admission_window_secs: 1
  # Admission requests per global per window.
  - admission_global_requests_per_window: 100
  # Admission requests per client per window.
  - admission_per_client_requests_per_window: 100
  # Optional deferred handling when limiter is exceeded
  - admission_defer_on_limit_enabled: false
  # Route prefixes that will be deferred when the admission limiter is exceeded.
  - admission_defer_route_prefixes: "/pipelines"
  # Deferred worker (route-level durable queue processing)
  - deferred_query_worker_enabled: false
  # Poll interval for the deferred query worker.
  - deferred_query_worker_poll_ms: 1000
  # Retention horizon for completed/dead-letter deferred jobs (seconds).
  # Set to 0 to disable cleanup. Default shown here is 30 days.
  - deferred_query_retention_secs: 2592000
  # Cleanup cadence for deferred queue retention purge (milliseconds).
  - deferred_query_cleanup_interval_ms: 60000
  # Retention horizon for gateway_request_log and gateway_operation_log (seconds).
  # Set to 0 to disable cleanup. Default shown here is 14 days.
  - log_retention_secs: 1209600
  # Set to false to skip loading clients from the athena_clients catalog table on
  # startup. When disabled, only clients declared in postgres_clients are registered.
  - database_backed_client_loading: true
  # Trust X-Forwarded-First for resolved client IP in gateway_request_log, auth logs, and audit (logging).
  - logging_trust_x_forwarded_for: true

  #
  # EXPERIMENTALS !!
  #
  # Postgres /gateway/insert execution window (ms). 0 = off unless the client sends
  # X-Athena-Insert-Window. Batching may add up to the window duration before flush.
  - insert_execution_window_ms: 0
  # Max rows per merged bulk insert in the insert window.
  - insert_window_max_batch: 100
  # Max queued insert-window jobs before falling back to direct execution.
  - insert_window_max_queued: 10000
  # Comma-separated table names excluded from bulk merge (still windowed as single-row flushes).
  - insert_merge_deny_tables: ""
  # Startup refresh of client_statistics / client_table_statistics: fast (counters, no
  # percentiles) or full (same as admin POST /admin/clients/statistics/refresh).
  - client_statistics_startup_refresh_mode: fast
  # Optional: only aggregate gateway logs from the last N days at startup (omit or 0 = all rows).
  - client_statistics_startup_refresh_lookback_days: 1
deferred_writes:
  # Master toggle. When true, gateway mutations (INSERT/UPDATE/DELETE) are written to the
  # in-memory write buffer and WAL first, bypassing the database. A background flush
  # executor drains the buffer into the database on the schedule below.
  # Set to false to use the normal write path with immediate DB writes.
  - enabled: false
  # Milliseconds between automatic flush runs (0 = time-based flush disabled).
  - batch_window_ms: 1000
  # Flush the buffer when it reaches this many pending entries regardless of the window.
  # 0 = size-based trigger disabled.
  - batch_max_size: 100
  # Write every buffered entry to disk (WAL) before acknowledging the write.
  # Provides crash recovery: on restart, pending WAL entries are replayed.
  - wal_enabled: true
  # Directory where WAL files are written. Relative to CWD or use an absolute path.
  - wal_dir: "./data/wal"
  # Skip cache invalidation on INSERT/UPDATE/DELETE even when deferred mode is OFF.
  # Useful to keep the cache hot during write storms at the cost of brief staleness.
  - skip_cache_invalidation: false

provisioning:
  # Comma-separated table names expected after a successful Athena schema provisioning run.
  - expected_tables: >
      gateway_request_log, gateway_operation_log, database_audit_log, function_ddl_audit_log, api_keys, api_key_rights, api_key_right_grants, api_key_config, api_key_client_config, api_key_auth_log, athena_clients, client_statistics, client_table_statistics, client_alert_queries, query_optimization_runs, query_optimization_recommendations, query_optimization_actions, query_history, saved_queries, ui_request_log, feedback, organization_requests, project_requests, storage_profiles, ip_addresses, ip_addresses_statistics
  # Defaults for local Docker Postgres provisioning.
  - default_postgres_image: "postgres:16-alpine"
  - default_instance_host: "127.0.0.1"
  - default_startup_timeout_secs: 60
  # Defaults for provider API endpoints used by provisioning helpers.
  - default_neon_api_base_url: "https://console.neon.tech/api/v2"
  - default_railway_graphql_url: "https://backboard.railway.app/graphql/v2"
  - default_render_api_base_url: "https://api.render.com/v1"
  # Docker self-heal: when true, Athena will automatically run
  # `usermod -aG docker <user>` on permission-denied errors so the
  # service can access the Docker daemon without a manual intervention.
  # Requires sudo access (passwordless or via docker_sudo_password below).
  # Can also be enabled via env: ATHENA_DOCKER_SELF_HEAL_GROUP=true
  - docker_self_heal_group: false
  # Optional sudo password used for Docker escalation and self-heal on Linux.
  # When set, sudo -S is used instead of sudo -n (which requires NOPASSWD).
  # Can also be set via env: ATHENA_DOCKER_SUDO_PASSWORD=<password>
  # Leave empty to rely on NOPASSWD sudo configuration.
  - docker_sudo_password: "${ATHENA_DOCKER_SUDO_PASSWORD}"

validation_ranges:
  env:
    ATHENA_POOL_MONITOR_INTERVAL_SECS:
      min: 30
      max: 3600
    ATHENA_POOL_MONITOR_RETENTION_HOURS:
      min: 24
      max: 720
    ATHENA_VACUUM_HEALTH_INTERVAL_SECS:
      min: 300
      max: 86400
    ATHENA_VACUUM_HEALTH_RETENTION_DAYS:
      min: 30
      max: 365
    ATHENA_VACUUM_HEALTH_STATEMENT_TIMEOUT_MS:
      min: 10000
      max: 600000
    ATHENA_CLIENT_RECONNECT_INTERVAL_SECS:
      min: 20
      max: 120
    ATHENA_CACHE_MAX_CAPACITY:
      min: 10000
      max: 1000000
    ATHENA_CACHE_MAX_ENTRY_WEIGHT:
      min: 262144
      max: 16777216
    ATHENA_PG_POOL_MAX_CONNECTIONS:
      min: 100
      max: 500
    ATHENA_DEADPOOL_WARMUP_TIMEOUT_MS:
      min: 800
      max: 60000
    ATHENA_PG_POOL_MAX_LIFETIME_SECS:
      min: 900
      max: 86400
    ATHENA_PG_POOL_MIN_CONNECTIONS:
      min: 0
      max: 500
    ATHENA_PG_POOL_ACQUIRE_TIMEOUT_SECS:
      min: 8
      max: 300
    ATHENA_PG_POOL_IDLE_TIMEOUT_SECS:
      min: 120
      max: 3600
    ATHENA_DEFERRED_MAX_ATTEMPTS:
      min: 3
      max: 50
    ATHENA_DEFERRED_WORKER_NO_STORAGE_POLL_MS:
      min: 30000
      max: 300000
    ATHENA_DEADPOOL_CHECKOUT_TIMEOUT_MS:
      min: 800
      max: 60000
    ATHENA_FETCH_SINGLEFLIGHT_WAIT_TIMEOUT_MS:
      min: 5000
      max: 120000
    ATHENA_CACHE_INVALIDATION_WINDOW_MS:
      min: 25
      max: 10000
    ATHENA_REDIS_OP_TIMEOUT_MS:
      min: 30
      max: 10000
    ATHENA_REDIS_COOLDOWN_MS:
      min: 5000
      max: 600000
    ATHENA_VACUUM_HEALTH_BLOAT_DEAD_PCT:
      min: 10
      max: 100
    ATHENA_VACUUM_HEALTH_XID_RISK_PCT:
      min: 50
      max: 100
    ATHENA_REALTIME_REGISTRY_PURGE_INTERVAL_SECS:
      min: 30
      max: 3600
    ATHENA_REALTIME_REGISTRY_INACTIVE_AFTER_SECS:
      min: 300
      max: 86400
  config:
    # API port range
    api.port:
      min: 4052
      max: 65535
    # Cache TTL range
    api.cache_ttl:
      min: 240
      max: 86400
    # Pool idle timeout range
    api.pool_idle_timeout:
      min: 90
      max: 86400
    api.keep_alive_secs:
      min: 15
      max: 3600
    api.client_disconnect_timeout_secs:
      min: 60
      max: 3600
    api.client_request_timeout_secs:
      min: 60
      max: 3600
    api.http_workers:
      min: 8
      max: 256
    api.http_max_connections:
      min: 10000
      max: 1000000
    api.http_backlog:
      min: 2048
      max: 65535
    api.tcp_keepalive_secs:
      min: 75
      max: 3600
    gateway.insert_execution_window_ms:
      min: 0
      max: 60000
    gateway.insert_window_max_batch:
      min: 100
      max: 10000
    gateway.insert_window_max_queued:
      min: 10000
      max: 1000000
    gateway.resilience_timeout_secs:
      min: 30
      max: 600
    gateway.resilience_read_max_retries:
      min: 1
      max: 20
    gateway.resilience_initial_backoff_ms:
      min: 100
      max: 60000
    gateway.admission_global_requests_per_window:
      min: 0
      max: 10000000
    gateway.admission_per_client_requests_per_window:
      min: 0
      max: 1000000
    gateway.admission_window_secs:
      min: 1
      max: 3600
    gateway.deferred_query_worker_poll_ms:
      min: 1000
      max: 120000
    gateway.deferred_query_retention_secs:
      min: 0
      max: 31536000
    gateway.deferred_query_cleanup_interval_ms:
      min: 1000
      max: 86400000

backup:
  # Required: bucket that stores backup archives.
  - s3_bucket: "${ATHENA_BACKUP_S3_BUCKET}"
  # Optional: region (default us-east-1 if empty).
  - s3_region: "${ATHENA_BACKUP_S3_REGION}"
  # Optional: custom S3-compatible endpoint (e.g., Hetzner/MinIO).
  - s3_endpoint: "${ATHENA_BACKUP_S3_ENDPOINT}"
  # Optional: object prefix/folder (default "backups" if empty).
  - s3_prefix: "${ATHENA_BACKUP_S3_PREFIX}"
  # Optional: access key / secret key (leave blank to use default provider chain).
  - s3_access_key: "${ATHENA_BACKUP_S3_ACCESS_KEY}"
  - s3_secret_key: "${ATHENA_BACKUP_S3_SECRET_KEY}"

postgres_clients:
  - athena_logging: "${POSTGRES_ATHENA_LOGGING_URI}"
  - athena_benchmark: "${POSTGRES_ATHENA_BENCHMARK_URI}"

# Optional Grafana Loki log shipping.
#
# Enabled when a push URL is configured (YAML below and/or `ATHENA_LOKI_URL`).
#
# Env vars override YAML:
#   ATHENA_LOKI_URL            – Full push endpoint, e.g. http://loki:3100
#   ATHENA_LOKI_TENANT_ID      – Multi-tenant Loki, sent as X-Scope-OrgID
#   ATHENA_LOKI_USERNAME       – HTTP Basic auth user (optional)
#   ATHENA_LOKI_PASSWORD       – HTTP Basic auth password (optional)
#   ATHENA_LOKI_LABELS         – Comma-separated stream labels: "env=prod,service=athena"
#   ATHENA_LOKI_EXTRA_FIELDS   – Comma-separated per-event fields: "version=3.5.0"
#   ATHENA_LOKI_FILTER        – tracing EnvFilter for the Loki sink only (defaults: RUST_LOG, else info).
#                             Example: athena::pool=warn,athena::gateway::insert=info,athena::http=info
#
# Stream labels should stay LOW CARDINALITY. Put request IDs, trace IDs,
# etc. in extra_fields instead — putting them in labels will blow up Loki's
# index.
loki:
  - url: "${ATHENA_LOKI_URL}"
  - tenant_id: "${ATHENA_LOKI_TENANT_ID}"
  - username: "${ATHENA_LOKI_USERNAME}"
  - password: "${ATHENA_LOKI_PASSWORD}"
  - labels: "${ATHENA_LOKI_LABELS}"
  - extra_fields: "${ATHENA_LOKI_EXTRA_FIELDS}"

# This is only for the local cluster
# - athena_cluster: "${POSTGRES_ATHENA_CLUSTER_URI}"
