# Operations

Enterprise hardening features (build plan Section 8). Everything below is opt-in
via environment variables so a small self-host stays simple.

## Billing & plans

Set `BILLING_ENABLED=true` to enforce plan limits (`legate/billing/plans.py`:
`free` / `pro` / `enterprise`). Limits cover agents, workflows, members, and a
monthly run quota; over-limit requests return **402**. Usage is metered per
period and exposed at `GET /usage` and `GET /billing`.

Stripe: set `STRIPE_API_KEY` (+ `STRIPE_WEBHOOK_SECRET`). `POST /billing/checkout`
starts a subscription; `POST /billing/webhook` updates a workspace's plan on
subscription events (workspace id + plan travel in Stripe metadata).

## SSO (OIDC)

Set `OIDC_ENABLED=true` and the provider endpoints
(`OIDC_AUTHORIZATION_ENDPOINT`, `OIDC_TOKEN_ENDPOINT`, `OIDC_USERINFO_ENDPOINT`)
plus `OIDC_CLIENT_ID` / `OIDC_CLIENT_SECRET`. Send users to `/auth/oidc/login`;
the callback provisions a user just-in-time and hands tokens to the dashboard.
SAML is a documented extension point behind the same provisioning path.

## Rate limiting & quotas

`RATE_LIMIT_ENABLED=true` caps runs per workspace at
`RATE_LIMIT_RUNS_PER_MINUTE` (429 when exceeded). The in-process limiter is fine
for a single replica; swap in a Redis-backed limiter behind
`legate.security.ratelimit.enforce_run_rate` for multi-replica deployments.

## Metrics

`GET /metrics` exposes Prometheus counters/histograms
(`legate_http_requests_total`, `legate_http_request_duration_seconds`,
`legate_runs_started_total`). The k8s `api` Deployment carries Prometheus scrape
annotations.

## Tracing

Install the extra (`pip install -e ".[tracing]"`) and set
`OTEL_EXPORTER_OTLP_ENDPOINT` to export OpenTelemetry traces (FastAPI is
auto-instrumented). Unset, tracing is a no-op.

## Logging

Production (`LEGATE_ENV=production`) emits structured JSON logs; development uses
human-readable lines.

## Scaling

`api`, `web`, and `worker` are stateless — scale replicas freely. Run exactly one
Celery **beat** replica (it schedules cron-triggered workflows).
