Something went wrong. Try again.
Metric and Time-Series Engine: A Minimal Archiving Time Series Storage Service
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111package proxy
import ( "fmt" "net/url" "strings" "time")
// Config holds the complete runtime configuration for the mats-proxy daemon.type Config struct { // BackendURL specifies the upstream primary mats service address. BackendURL string
// ListenAddr specifies the local address to bind the public HTTP server. ListenAddr string
// AllowedHosts specifies the list of allowed host identifiers. AllowedHosts []string
// AllowedServices specifies the list of allowed service names. AllowedServices []string
// MaxQueryWindow defines the maximum allowable time window for queries. MaxQueryWindow time.Duration
// CacheSize specifies the maximum number of in-memory cached responses. CacheSize int
// CacheDir optionally specifies a directory for disk cache persistence. CacheDir string
// RateLimitRPS specifies maximum requests per second per IP address. RateLimitRPS float64
// RateLimitBurst specifies maximum burst size for the per-IP token bucket. RateLimitBurst int
// MaxConnections limits the number of simultaneous active TCP connections. MaxConnections int
// ReadTimeout and WriteTimeout set bounded HTTP request/response deadlines. ReadTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration
// Sandboxing flags EnableLandlock bool EnableSeccomp bool
// Pre-rendered snapshot ticker EnableSnapshot bool SnapshotInterval time.Duration}
// DefaultConfig returns recommended production defaults for mats-proxy.func DefaultConfig() Config { return Config{ BackendURL: "http://127.0.0.1:8080", ListenAddr: ":8088", AllowedHosts: nil, AllowedServices: nil, MaxQueryWindow: 365 * 24 * time.Hour, // 1 year default CacheSize: 512, CacheDir: "", RateLimitRPS: 10, RateLimitBurst: 20, MaxConnections: 128, ReadTimeout: 5 * time.Second, WriteTimeout: 120 * time.Second, IdleTimeout: 180 * time.Second, EnableLandlock: true, EnableSeccomp: true, EnableSnapshot: true, SnapshotInterval: 5 * time.Minute, }}
// Validate checks configuration values for correctness.func (c *Config) Validate() error { if strings.TrimSpace(c.BackendURL) == "" { return fmt.Errorf("backend URL cannot be empty") } u, err := url.Parse(c.BackendURL) if err != nil || (u.Scheme != "http" && u.Scheme != "https") { return fmt.Errorf("invalid backend URL %q: must start with http:// or https://", c.BackendURL) } if strings.TrimSpace(c.ListenAddr) == "" { return fmt.Errorf("listen address cannot be empty") } if c.MaxQueryWindow <= 0 { return fmt.Errorf("max query window must be positive") } if c.CacheSize < 0 { return fmt.Errorf("cache size cannot be negative") } if c.RateLimitRPS <= 0 { c.RateLimitRPS = 10 } if c.RateLimitBurst <= 0 { c.RateLimitBurst = 20 } if c.MaxConnections <= 0 { c.MaxConnections = 128 } if c.SnapshotInterval <= 0 { c.SnapshotInterval = 5 * time.Minute } return nil}