Documentation
¶
Index ¶
- func NewGraphCache(c *Config) *graph.GraphCache[string, *v1.Vertex]
- func NewGrpcServer(options []grpc.ServerOption) *grpc.Server
- func NewGrpcServerMetrics(reg *prometheus.Registry) *grpcprom.ServerMetrics
- func NewGrpcServerOptions(c *Config, logger *slog.Logger, metrics *grpcprom.ServerMetrics) ([]grpc.ServerOption, error)
- func NewHealthServer() *health.Server
- func NewLifecycleConfig(c *Config) service.LifecycleConfig
- func NewListener(c *Config) (net.Listener, error)
- func NewLogger(c *Config) *slog.Logger
- func NewPrometheusRegistry() *prometheus.Registry
- func RegisterHealth(s *grpc.Server, hs *health.Server)
- func RegisterReflection(c *Config, s *grpc.Server)
- type Config
- type MetricsServer
- type RateLimitInterceptor
- type ValidationInterceptor
- type ValidationLimits
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewGraphCache ¶
func NewGrpcServer ¶
func NewGrpcServer(options []grpc.ServerOption) *grpc.Server
func NewGrpcServerMetrics ¶ added in v0.5.0
func NewGrpcServerMetrics(reg *prometheus.Registry) *grpcprom.ServerMetrics
NewGrpcServerMetrics exposes per-RPC histograms/counters via the grpc-middleware Prometheus provider.
func NewGrpcServerOptions ¶
func NewGrpcServerOptions( c *Config, logger *slog.Logger, metrics *grpcprom.ServerMetrics, ) ([]grpc.ServerOption, error)
NewGrpcServerOptions assembles the modern interceptor + stats-handler chain:
- otelgrpc stats handler (replaces the deprecated unary interceptor)
- recovery interceptor (panic -> Internal status)
- slog logging interceptor
- Prometheus server metrics interceptor
- request validation interceptor (codes.InvalidArgument guard rails)
- optional token-bucket rate limiter (codes.ResourceExhausted)
- keepalive policy that pings idle clients and rejects abusive ones
- message size + concurrent stream caps
- optional TLS / mTLS credentials
func NewHealthServer ¶ added in v0.5.0
NewHealthServer is the gRPC health-checking implementation.
func NewLifecycleConfig ¶ added in v0.5.0
func NewLifecycleConfig(c *Config) service.LifecycleConfig
NewLifecycleConfig forwards Config knobs into the service-layer lifecycle struct. Kept narrow so service.go doesn't need to import provider.
func NewLogger ¶ added in v0.5.0
NewLogger builds the process-wide structured logger and installs it as the slog default so any package-level slog.* call inherits the same handler.
func NewPrometheusRegistry ¶ added in v0.5.0
func NewPrometheusRegistry() *prometheus.Registry
NewPrometheusRegistry isolates server metrics in a dedicated registry so the global default stays clean.
func RegisterHealth ¶ added in v0.5.0
RegisterHealth wires the gRPC health service so probes / LBs can query SERVING status.
func RegisterReflection ¶ added in v0.5.0
RegisterReflection enables grpcurl-style descriptor reflection when allowed by the LANTERN_REFLECTION env var.
Types ¶
type Config ¶
type Config struct {
Port int
TTL time.Duration
GCInterval time.Duration
ShutdownTimeout time.Duration
LogLevel slog.Level
LogFormat string
MetricsAddr string
EnableReflection bool
MaxRecvMsgBytes int
MaxSendMsgBytes int
MaxConcurrentStreams uint32
RateLimitRPS float64
RateLimitBurst int
MaxKeyLen int
MaxBatchSize int
IlluminateMaxStep int
IlluminateMaxK int
TLSCertFile string
TLSKeyFile string
TLSClientCAFile string
}
Config captures runtime configuration sourced from the environment.
Backwards-compatible vars:
- LANTERN_PORT (default 6380)
- LANTERN_DEFAULT_TTL_SECONDS (default 60)
Observability / lifecycle additions:
- LANTERN_GC_INTERVAL_SECONDS (default 60) — GraphCache.Watch tick
- LANTERN_SHUTDOWN_TIMEOUT_SECONDS (default 30) — GracefulStop deadline
- LANTERN_LOG_LEVEL debug|info|warn|error (default info)
- LANTERN_LOG_FORMAT json|text (default json)
- LANTERN_METRICS_ADDR host:port for /metrics + /healthz (default :9090; set empty to disable)
- LANTERN_REFLECTION true|false (default true)
Resource & limits:
- LANTERN_MAX_RECV_MSG_BYTES (default 16 MiB)
- LANTERN_MAX_SEND_MSG_BYTES (default 16 MiB)
- LANTERN_MAX_CONCURRENT_STREAMS (default 1024; 0 = unlimited)
- LANTERN_RATE_LIMIT_RPS per-process token bucket replenish rate; 0 disables rate limiting (default 0)
- LANTERN_RATE_LIMIT_BURST token bucket burst (default 2x RPS)
Validation guard rails (codes.InvalidArgument):
- LANTERN_MAX_KEY_LEN (default 1024)
- LANTERN_MAX_BATCH_SIZE (default 10000)
- LANTERN_ILLUMINATE_MAX_STEP (default 16)
- LANTERN_ILLUMINATE_MAX_K (default 1024)
TLS (all-or-nothing; mTLS engaged when client CA is set):
- LANTERN_TLS_CERT_FILE PEM cert path (enables TLS)
- LANTERN_TLS_KEY_FILE PEM key path
- LANTERN_TLS_CLIENT_CA_FILE PEM client CA path (enables mTLS)
type MetricsServer ¶ added in v0.5.0
type MetricsServer struct {
// contains filtered or unexported fields
}
MetricsServer hosts /metrics (Prometheus) and /healthz + /readyz on a dedicated HTTP port. Returns nil when LANTERN_METRICS_ADDR is empty.
func NewMetricsServer ¶ added in v0.5.0
func NewMetricsServer(c *Config, reg *prometheus.Registry, logger *slog.Logger) *MetricsServer
type RateLimitInterceptor ¶ added in v0.5.0
type RateLimitInterceptor struct {
// contains filtered or unexported fields
}
RateLimitInterceptor enforces a process-wide token bucket. Requests beyond the bucket return codes.ResourceExhausted so well-behaved clients (and the SDK's default retry policy) can back off.
func NewRateLimitInterceptor ¶ added in v0.5.0
func NewRateLimitInterceptor(rps float64, burst int) *RateLimitInterceptor
func (*RateLimitInterceptor) StreamServerInterceptor ¶ added in v0.5.0
func (r *RateLimitInterceptor) StreamServerInterceptor() grpc.StreamServerInterceptor
func (*RateLimitInterceptor) UnaryServerInterceptor ¶ added in v0.5.0
func (r *RateLimitInterceptor) UnaryServerInterceptor() grpc.UnaryServerInterceptor
type ValidationInterceptor ¶ added in v0.5.0
type ValidationInterceptor struct {
// contains filtered or unexported fields
}
func NewValidationInterceptor ¶ added in v0.5.0
func NewValidationInterceptor(l ValidationLimits) *ValidationInterceptor
func (*ValidationInterceptor) StreamServerInterceptor ¶ added in v0.5.0
func (v *ValidationInterceptor) StreamServerInterceptor() grpc.StreamServerInterceptor
func (*ValidationInterceptor) UnaryServerInterceptor ¶ added in v0.5.0
func (v *ValidationInterceptor) UnaryServerInterceptor() grpc.UnaryServerInterceptor
type ValidationLimits ¶ added in v0.5.0
type ValidationLimits struct {
MaxKeyLen int
MaxBatchSize int
IlluminateMaxStep int
IlluminateMaxK int
}
ValidationLimits caps user-controllable request dimensions so a single caller can't exhaust server resources before the rate limiter or message size cap kicks in.