-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
This guide covers all configuration options for Flux Gate components.
The backend server uses a TOML configuration file located at feature-toggle-backend/config.toml:
# Feature Toggle Backend configuration
# Default values match the previously hardcoded ones
# CORS allowed origin for the frontend
allowed_origin = "http://localhost:5173"
# Address that the Actix-Web HTTP server binds to
http_addr = "127.0.0.1:8080"
# Address that the gRPC server binds to
grpc_addr = "0.0.0.0:50051"
The backend server supports the following environment variables:
| Variable | Description | Default | Required |
|---|---|---|---|
DATABASE_URL |
PostgreSQL connection string | - | Yes |
CONFIG_PATH |
Path to config.toml file | config.toml |
No |
RUST_LOG |
Logging level | info |
No |
Example:
export DATABASE_URL="postgres://postgres:local123@localhost:5432/feature_toggle"
export RUST_LOG="debug"The Edge Server is configured via environment variables:
| Variable | Description | Default | Required |
|---|---|---|---|
EDGE_BACKEND_GRPC |
Backend gRPC endpoint | - | Yes |
EDGE_HTTP_ADDR |
Edge server bind address | 0.0.0.0:8081 |
No |
EDGE_CLIENT_ID |
Client ID for backend auth | - | Yes |
EDGE_CLIENT_SECRET |
Client secret for backend auth | - | Yes |
RUST_LOG |
Logging level | info |
No |
Example:
export EDGE_BACKEND_GRPC="http://localhost:50051"
export EDGE_HTTP_ADDR="0.0.0.0:8081"
export EDGE_CLIENT_ID="a1b2c3d4-0000-4000-8000-000000000001"
export EDGE_CLIENT_SECRET="TEST_WEB_KEY_1"The complete docker-compose setup:
services:
postgres_server:
hostname: postgres_server
image: postgres:latest
environment:
- POSTGRES_PASSWORD=local123
- POSTGRES_DB=feature_toggle
ports:
- "5433:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
feature_toggle_backend:
build:
context: .
dockerfile: feature-toggle-backend/Dockerfile
environment:
- DATABASE_URL=postgres://postgres:local123@postgres_server:5432/feature_toggle
depends_on:
- postgres_server
ports:
- "8080:8080"
- "50051:50051"
restart: unless-stopped
feature_edge_server:
build:
context: .
dockerfile: feature-edge-server/Dockerfile
environment:
- EDGE_BACKEND_GRPC=http://feature_toggle_backend:50051
- EDGE_HTTP_ADDR=0.0.0.0:8081
- EDGE_CLIENT_ID=a1b2c3d4-0000-4000-8000-000000000001
- EDGE_CLIENT_SECRET=TEST_WEB_KEY_1
depends_on:
- feature_toggle_backend
ports:
- "8081:8081"
restart: unless-stopped
volumes:
postgres_data:For production deployment, create a separate docker-compose.prod.yml:
services:
postgres_server:
image: postgres:13
environment:
- POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
- POSTGRES_DB=feature_toggle
- POSTGRES_USER=feature_toggle_user
volumes:
- postgres_data:/var/lib/postgresql/data
- ./pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf
secrets:
- postgres_password
networks:
- internal
feature_toggle_backend:
image: your-registry/feature-toggle-backend:latest
environment:
- DATABASE_URL_FILE=/run/secrets/database_url
- CONFIG_PATH=/app/config/prod.toml
volumes:
- ./config/prod.toml:/app/config/prod.toml:ro
secrets:
- database_url
networks:
- internal
- web
deploy:
replicas: 3
update_config:
parallelism: 1
delay: 10s
secrets:
postgres_password:
external: true
database_url:
external: true
networks:
internal:
driver: overlay
web:
external: trueDevelopment:
DATABASE_URL=postgres://postgres:local123@localhost:5432/feature_toggle
Production:
DATABASE_URL=postgres://username:password@host:port/database?sslmode=require
The application uses SQLx with default connection pooling. You can configure pool settings via environment variables:
| Variable | Description | Default |
|---|---|---|
SQLX_MAX_CONNECTIONS |
Maximum connections | 10 |
SQLX_MIN_CONNECTIONS |
Minimum connections | 0 |
SQLX_CONNECT_TIMEOUT |
Connection timeout (seconds) | 30 |
SQLX_IDLE_TIMEOUT |
Idle timeout (seconds) | 600 |
For production, always use SSL:
DATABASE_URL=postgres://user:pass@host:5432/db?sslmode=require&sslcert=client-cert.pem&sslkey=client-key.pem&sslrootcert=ca-cert.pem
Configure logging using the RUST_LOG environment variable:
# Show only errors and warnings
export RUST_LOG="warn"
# Show info level and above (recommended for production)
export RUST_LOG="info"
# Show debug information (development)
export RUST_LOG="debug"
# Fine-grained logging
export RUST_LOG="feature_toggle_backend=debug,sqlx=info,actix_web=info"Create a log4rs.yaml file for advanced logging configuration:
refresh_rate: 30 seconds
appenders:
stdout:
kind: console
encoder:
pattern: "{d} {l} {t} - {m}{n}"
file:
kind: file
path: "logs/app.log"
encoder:
pattern: "{d} {l} {f}:{L} - {m}{n}"
rolling_file:
kind: rolling_file
path: "logs/app.log"
policy:
kind: compound
trigger:
kind: size
limit: 100mb
roller:
kind: fixed_window
pattern: "logs/app.{}.log"
count: 5
root:
level: info
appenders:
- stdout
- rolling_file
loggers:
sqlx:
level: warn
actix_web:
level: info
feature_toggle_backend:
level: debugConfigure CORS in config.toml:
# Single origin
allowed_origin = "https://your-frontend.com"
# Multiple origins (comma-separated)
allowed_origin = "https://app.com,https://admin.com,http://localhost:3000"Configure rate limiting for the edge server:
# In edge server config
rate_limit:
requests_per_second: 1000
burst_size: 100
enable_per_client_limits: true# config.toml
[server]
worker_threads = 4
max_connections = 1000
keep_alive_timeout = 75
client_timeout = 5000
[database]
max_connections = 20
min_connections = 5
acquire_timeout = 30# Environment variables
export TOKIO_WORKER_THREADS=4
export MAX_CONCURRENT_STREAMS=1000
export GRPC_KEEPALIVE_TIME=30
export GRPC_KEEPALIVE_TIMEOUT=10The application validates configuration on startup. Common validation errors:
- Invalid JWT secret: Must be at least 32 characters
- Invalid database URL: Check connection string format
- Invalid bind addresses: Ensure ports are not in use
- Missing required environment variables: Check all required vars are set
# config.toml
allowed_origin = "http://localhost:5173"
http_addr = "127.0.0.1:8080"
grpc_addr = "0.0.0.0:50051"
[logging]
level = "debug"
[database]
max_connections = 5# config.prod.toml
allowed_origin = "https://your-app.com"
http_addr = "0.0.0.0:8080"
grpc_addr = "0.0.0.0:50051"
[logging]
level = "info"
format = "json"
[database]
max_connections = 20
ssl_mode = "require"
[security]
rate_limit_enabled = true
max_requests_per_minute = 1000
[metrics]
enabled = true
bind_addr = "0.0.0.0:9090"- Never commit secrets to version control
- Always use SSL in production
- Rotate JWT secrets regularly
- Monitor database connection pool usage
- Set up proper log rotation
- Configure appropriate resource limits