config

package
v0.9.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config centralizes all RELAY_* env var parsing for the relay binary. It is the single source of truth for the env contract; grep here to learn what env vars Relay reads.

Load() validates inputs at boot (master key shape, cluster-mode enum, etc.) so subsystem constructors can trust the fields they receive. Subsystems do NOT read env vars themselves — they accept values via their own typed configs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Cluster
	ClusterMode bool

	// Backends
	CatalogBackend  string
	StateBackend    string
	EventlogBackend string

	// Connections
	PGDSN      string
	PGMaxConns int // RELAY_PG_MAX_CONNS; 0 = storage default (10)
	PGMinConns int // RELAY_PG_MIN_CONNS warm floor; 0 = storage default (2)
	RedisAddr  string
	// RedisPoolSize / RedisMinIdleConns tune the go-redis client pool.
	// 0 = library defaults (pool 10×GOMAXPROCS, NO idle floor). A warm
	// floor keeps connections pre-dialed so request bursts never pay
	// cold-dial (TCP + uncached DNS) latency inside a request budget —
	// same rationale as the PG warm floor above.
	RedisPoolSize     int // RELAY_REDIS_POOL_SIZE
	RedisMinIdleConns int // RELAY_REDIS_MIN_IDLE_CONNS
	CHDSN             string
	OTLPEndpoint      string

	// Auth
	AdminToken string
	MasterKey  []byte // already parsed via crypto.ParseMasterKey; nil if unset

	// MultiUser selects the owner-scoped authorizer on the control API:
	// each user sees and mutates only the rows they own; catalog rows stay
	// readable by all and admin-mutable. Off (the default) keeps the
	// single-user always-allow behavior.
	MultiUser bool

	// Behavior knobs
	CHRetentionDays int
	AutoSeedIfEmpty bool
	ConfigDir       string
	CatalogDir      string
	CatalogVersion  string
	CatalogURL      string
	CatalogIndexURL string
	InstanceID      string
	EventlogDir     string
	MaxRequestBytes int64 // 0 = use httpmw.DefaultMaxRequestBytes
	MaxInflight     int   // RELAY_MAX_INFLIGHT per-pod in-flight cap; 0 = httpapi.DefaultMaxInflight

	// UpstreamMaxIdlePerHost caps idle keep-alive connections the upstream
	// transport pools per host (RELAY_UPSTREAM_MAX_IDLE_PER_HOST, default 128).
	// The stdlib default (2) forces a fresh dial on nearly every request at
	// high per-host RPS; a higher ceiling keeps hot upstream connections warm.
	UpstreamMaxIdlePerHost int

	// StreamKeepAlive is the silence interval after which relay emits the inbound wire shape's own no-op SSE frame on a streamed response (RELAY_STREAM_KEEPALIVE_S, default 15s; 0 disables). Upstreams send nothing during long prompt processing or thinking, and coding-agent clients abort a stream after a few minutes without bytes.
	StreamKeepAlive time.Duration

	// StreamIdleTimeout ends a streamed upstream call that has sent no bytes for this long (RELAY_STREAM_IDLE_TIMEOUT_S, default 600s; 0 disables). Deliberately above the clients' own silence watchdogs so relay is never the first to give up. Streams have no total deadline; buffered calls do.
	StreamIdleTimeout time.Duration

	HealthzDeadlineMS int
	ShutdownDeadlineS int

	// DevTrustEventTime makes the inference edge honor the X-WR-Event-Time
	// header as the usage Event timestamp (RELAY_DEV_TRUST_EVENT_TIME=1).
	// Dev/replay tooling only — never enable in production.
	DevTrustEventTime bool

	// ControlPort is the listener port for the control-plane HTTP server.
	// Empty disables the control listener entirely (data plane only).
	ControlPort string

	// ControlAllowOrigins is the CORS allowlist for the control API. Comma-
	// separated list of exact origin strings (no wildcards — credentialed
	// CORS forbids them). Empty disables CORS entirely.
	ControlAllowOrigins []string

	// UIDisable suppresses serving the embedded admin UI on the control
	// listener (RELAY_UI_DISABLE=1). Off by default; the UI is same-origin
	// and adds no surface beyond the control API it already fronts.
	UIDisable bool

	// Runtime is the public, unauthenticated runtime config the embedded admin
	// UI fetches at boot via GET /config.json. Public values only — it is
	// world-readable. All fields are optional; empty URL fields make the UI
	// fall back to its own origin (which is correct for controlApiUrl in the
	// single-binary case, but NOT for inferenceApiUrl when the data plane is a
	// separate origin — hence RELAY_INFERENCE_API_URL).
	Runtime RuntimeConfig
}

Config holds every RELAY_* setting parsed and validated at startup.

func Load

func Load() (*Config, error)

Load reads every RELAY_* environment variable, validates them, and returns a fully-populated *Config. Returns a descriptive error on the first validation failure.

type RuntimeConfig added in v0.2.0

type RuntimeConfig struct {
	ControlAPIURL   string // RELAY_CONTROL_API_URL   (empty ⇒ UI uses its origin)
	InferenceAPIURL string // RELAY_INFERENCE_API_URL (empty ⇒ UI prompts; no safe origin default)
	Mode            string // RELAY_MODE ("oss" | "cloud"); default "oss"
	SentryDSN       string // RELAY_UI_SENTRY_DSN        (public client-side DSN)
	TelemetryEnv    string // RELAY_UI_TELEMETRY_ENV
	DocsURL         string // RELAY_UI_DOCS_URL
	SupportURL      string // RELAY_UI_SUPPORT_URL
}

RuntimeConfig carries the deployment-specific values surfaced to the browser via GET /config.json. Mirrors the JSON the UI reads; see config_json.go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL