Configuration
The proxy is configured through environment variables, all optional. A .env file is loaded if present.
| Variable | Value | Default |
|---|---|---|
LOG_LEVEL | panic, fatal, error, warn, info, debug, trace | info |
PORT | number | 8080 |
METRICS_PORT | number | 9000 |
ENABLE_METRICS | boolean | true |
ENABLE_PPROF | boolean | false |
BUFFER_SIZE | number | 50 |
OUTBOUND_IP | IP address | empty |
BIND_IP | IP address | 0.0.0.0 |
DISCORD_URL | URL with no path | https://discord.com |
REQUEST_TIMEOUT | number (milliseconds) | 5000 |
CLUSTER_PORT | number | 7946 |
CLUSTER_MEMBERS | comma separated list | empty |
CLUSTER_ADVERTISE_ADDR | address, host name or auto | empty |
CLUSTER_DNS | domain name | empty |
MAX_BEARER_COUNT | number | 1024 |
DISABLE_HTTP_2 | boolean | true |
BOT_RATELIMIT_OVERRIDES | comma separated list | empty |
DISABLE_GLOBAL_RATELIMIT_DETECTION | boolean | true |
Server
LOG_LEVEL
Log level, passed as is to logrus.
PORT and METRICS_PORT
Ports the proxy listens on for requests and for its metrics.
ENABLE_METRICS and ENABLE_PPROF
Enables metrics (turning them off saves a little) and profiling.
BIND_IP
Address the HTTP server listens on, for requests and metrics alike. 127.0.0.1 only accepts local connections, 10.0.0.42 only those from the LAN.
BUFFER_SIZE
Size of the Go channels that order requests. Lowering it saves memory, but once a channel is full, requests fight for the next free spot: under heavy load, part of them are no longer sent in order.
Discord
DISCORD_URL
Where requests go, as a scheme and a host with no path. Used to put the proxy in front of a Discord simulator or a recording proxy.
OUTBOUND_IP
Local address requests to Discord leave from, for example 120.121.122.123.
REQUEST_TIMEOUT
How long to wait for Discord's answer, not counting time spent waiting on rate limits. Past it, the proxy answers 408.
DISABLE_HTTP_2
Disables HTTP/2 for requests to Discord, because of a few issues in Go's HTTP/2 support. Does not affect the proxy's own server.
MAX_BEARER_COUNT
Maximum number of Bearer token queues, kept in an LRU cache. A request is never interrupted when its queue is evicted, but a size too low can raise 429s if a token has many requests queued.
Global limit
BOT_RATELIMIT_OVERRIDES
Global requests per second limit, for bots whose limit Discord raised. Without it, every bot is limited to 50, the value Discord documents.
Format: the bot's user ID (not its application ID) and its limit, separated by :, with no spaces:
BOT_RATELIMIT_OVERRIDES=392827169497284619:100,227115752396685313:80
DISABLE_GLOBAL_RATELIMIT_DETECTION
Set to false, the proxy infers the global limit from /gateway/bot (50 for a concurrency of 1, 500 for 16, and a formula above). Discord does not document that relation, and /gateway/bot is limited to 2 requests every 5 seconds, which the bot's shards need when they start: detection is therefore off by default in our fork. Prefer BOT_RATELIMIT_OVERRIDES.
Cluster
See High availability for how it works.
CLUSTER_PORT
Port used to talk to the other cluster members.
CLUSTER_MEMBERS
Known cluster members, comma separated, with an optional port (CLUSTER_PORT otherwise). No need to list them all: the others are discovered through a gossip protocol. Takes precedence over CLUSTER_DNS.
CLUSTER_MEMBERS=10.0.0.2,10.0.0.3:7244
CLUSTER_DNS
Domain name that resolves to several cluster members, the recommended method on Kubernetes (with a headless service, for example nirn-headless.default.svc.cluster.local). DNS carries no port: every node must then use the same CLUSTER_PORT.
CLUSTER_ADVERTISE_ADDR
Address this node advertises to the others. Empty, memberlist picks it alone, which inside a container can give an unreachable address. Set an IP address, a host name, or auto to take the first non-loopback IPv4 address.
Unstable variables
DISABLE_401_LOCK
The proxy locks a queue for good after a 401 during normal operation. This variable disables the lock, but not its logging. It may be removed at any time.