Documentation
¶
Overview ¶
Package runtime contains Vale's collectionx-backed compiled data plane model, route matcher, middleware chain, health checker, access logging, and metrics recorder contracts.
Config file DTOs live in package config. Runtime values are already compiled and are suitable for embedded library users that want to construct snapshots directly with NewSnapshot, NewService, NewRoute, and related helpers.
Index ¶
- Constants
- func WrapMiddlewares(handler http.Handler, middlewares *collectionlist.List[MiddlewareRuntime]) http.Handler
- func WrapMiddlewaresWithRegistry(handler http.Handler, middlewares *collectionlist.List[MiddlewareRuntime], ...) http.Handler
- type ACMERuntime
- type AccessEvent
- type AccessLogger
- type BasicAuthRuntime
- type CORSMiddlewareRuntime
- type Catalog
- type CircuitBreakerRuntime
- type CompiledRoute
- func (r *CompiledRoute) WithHeader(key, value string) *CompiledRoute
- func (r *CompiledRoute) WithHost(host string) *CompiledRoute
- func (r *CompiledRoute) WithMethod(method string) *CompiledRoute
- func (r *CompiledRoute) WithMiddleware(middleware MiddlewareRuntime) *CompiledRoute
- func (r *CompiledRoute) WithPathPrefix(pathPrefix string) *CompiledRoute
- type CompiledSnapshot
- func (s *CompiledSnapshot) AddEntrypoint(name, address string, entrypoint EntrypointRuntime) *CompiledSnapshot
- func (s *CompiledSnapshot) AddRoute(route *CompiledRoute) *CompiledSnapshot
- func (s *CompiledSnapshot) AddService(service *ServiceRuntime) *CompiledSnapshot
- func (s *CompiledSnapshot) BuildCatalog() *CompiledSnapshot
- func (s *CompiledSnapshot) BuildMatchers() *CompiledSnapshot
- func (s *CompiledSnapshot) QueryRoutes(filter RouteFilter) *collectionlist.List[RouteView]
- func (s *CompiledSnapshot) Routes() *collectionlist.List[RouteView]
- func (s *CompiledSnapshot) ServicesView() *collectionlist.List[ServiceView]
- type CompressRuntime
- type EndpointRecord
- type EndpointRuntime
- type EndpointView
- type EntrypointMatcher
- type EntrypointRuntime
- type ForwardAuthRuntime
- type Gateway
- func (g *Gateway) Handler(entrypoint string) http.Handler
- func (g *Gateway) MetricsHandler() http.Handler
- func (g *Gateway) ObserveHealth(endpoint *EndpointRuntime, healthy bool)
- func (g *Gateway) ObserveHealthCheck(endpoint *EndpointRuntime, healthy bool, duration time.Duration)
- func (g *Gateway) ObserveRaftApply(group string, duration time.Duration, result string)
- func (g *Gateway) ObserveReload(result string)
- func (g *Gateway) ObserveReloadDebounce(delay time.Duration, sourceCount int)
- func (g *Gateway) ObserveReloadDuration(result string, duration time.Duration)
- func (g *Gateway) ObserveRouteCache(hit bool)
- func (g *Gateway) ObserveSnapshot(snapshot *CompiledSnapshot)
- func (g *Gateway) Snapshot() *CompiledSnapshot
- func (g *Gateway) Swap(snapshot *CompiledSnapshot)
- type HealthCheckMetricsRecorder
- type HealthChecker
- type HealthMetricsRecorder
- type IPAllowListRuntime
- type MetricsRecorder
- type MiddlewareFactory
- type MiddlewareRecord
- type MiddlewareRegistry
- func (r *MiddlewareRegistry) Clone() *MiddlewareRegistry
- func (r *MiddlewareRegistry) Factory(middlewareType string) (MiddlewareFactory, bool)
- func (r *MiddlewareRegistry) Names() *collectionlist.List[string]
- func (r *MiddlewareRegistry) Register(middlewareType string, factory MiddlewareFactory) error
- type MiddlewareRuntime
- type RaftApplyMetricsRecorder
- type RateLimitRuntime
- type ReloadDebounceMetricsRecorder
- type ReloadDurationMetricsRecorder
- type ReloadMetricsRecorder
- type ResourceDiff
- type RouteCacheMetricsRecorder
- type RouteFilter
- type RouteRecord
- type RouteView
- type SecureMiddlewareRuntime
- type SecurityRuntime
- type ServiceRecord
- type ServiceRuntime
- type ServiceView
- type SnapshotDiff
- type SnapshotMetricsRecorder
- type TLSRuntime
Constants ¶
View Source
const ( PredicateHost = iota PredicatePathPrefix PredicateMethod PredicateHeaders )
View Source
const MiddlewareTypeBuiltin = "builtin"
Variables ¶
This section is empty.
Functions ¶
func WrapMiddlewares ¶
func WrapMiddlewares(handler http.Handler, middlewares *collectionlist.List[MiddlewareRuntime]) http.Handler
func WrapMiddlewaresWithRegistry ¶
func WrapMiddlewaresWithRegistry(handler http.Handler, middlewares *collectionlist.List[MiddlewareRuntime], registry *MiddlewareRegistry) http.Handler
Types ¶
type ACMERuntime ¶
type AccessEvent ¶
type AccessEvent struct {
Method string `json:"method"`
Path string `json:"path"`
Host string `json:"host"`
StatusCode int `json:"status_code"`
DurationMs int64 `json:"duration_ms"`
Route string `json:"route"`
Service string `json:"service"`
Endpoint string `json:"endpoint"`
UserAgent string `json:"user_agent"`
RemoteAddr string `json:"remote_addr"`
}
type AccessLogger ¶
type AccessLogger struct {
// contains filtered or unexported fields
}
func NewAccessLogger ¶
func NewAccessLogger(logger *slog.Logger, enabled bool) *AccessLogger
func (*AccessLogger) Enabled ¶ added in v0.1.1
func (l *AccessLogger) Enabled() bool
func (*AccessLogger) Log ¶
func (l *AccessLogger) Log(event AccessEvent)
type BasicAuthRuntime ¶ added in v0.1.1
type CORSMiddlewareRuntime ¶
type CORSMiddlewareRuntime struct {
Enabled bool
AllowedOrigins *collectionlist.List[string]
AllowedMethods *collectionlist.List[string]
AllowedHeaders *collectionlist.List[string]
ExposedHeaders *collectionlist.List[string]
MaxAge int
AllowCredentials bool
AllowPrivateNetwork bool
OptionsPassthrough bool
OptionsSuccessStatus int
}
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog is a control-plane index over a compiled snapshot. It is not used by the request hot path; route matching stays on EntrypointMatcher.
func BuildCatalog ¶
func BuildCatalog(snapshot *CompiledSnapshot) (*Catalog, error)
func (*Catalog) RouteViews ¶
func (c *Catalog) RouteViews(filter RouteFilter) (*collectionlist.List[RouteView], error)
func (*Catalog) Routes ¶
func (c *Catalog) Routes(filter RouteFilter) (*collectionlist.List[RouteRecord], error)
type CircuitBreakerRuntime ¶
type CompiledRoute ¶
type CompiledRoute struct {
Name string
Entrypoint string
Host string
PathPrefix string
Method string
Headers *mapping.Map[string, string]
Service *ServiceRuntime
Predicates *bitset.BitSet
Middlewares *collectionlist.List[MiddlewareRuntime]
}
func MatchRoute ¶
func MatchRoute(matcher *EntrypointMatcher, routes *collectionlist.List[*CompiledRoute], request *http.Request) *CompiledRoute
func NewRoute ¶
func NewRoute(name, entrypoint string, service *ServiceRuntime) *CompiledRoute
func (*CompiledRoute) WithHeader ¶
func (r *CompiledRoute) WithHeader(key, value string) *CompiledRoute
func (*CompiledRoute) WithHost ¶
func (r *CompiledRoute) WithHost(host string) *CompiledRoute
func (*CompiledRoute) WithMethod ¶
func (r *CompiledRoute) WithMethod(method string) *CompiledRoute
func (*CompiledRoute) WithMiddleware ¶
func (r *CompiledRoute) WithMiddleware(middleware MiddlewareRuntime) *CompiledRoute
func (*CompiledRoute) WithPathPrefix ¶
func (r *CompiledRoute) WithPathPrefix(pathPrefix string) *CompiledRoute
type CompiledSnapshot ¶
type CompiledSnapshot struct {
Entrypoints *mapping.Map[string, string]
EntrypointConfigs *mapping.Map[string, EntrypointRuntime]
RoutesByEntrypoint *mapping.MultiMap[string, *CompiledRoute]
EntrypointMatchers *mapping.Map[string, *EntrypointMatcher]
Catalog *Catalog
Services *mapping.Map[string, *ServiceRuntime]
AdminAddress string
AccessLogEnabled bool
MetricsEnabled bool
HealthInterval string
HealthTimeout string
Security SecurityRuntime
ProxyEngine string
Fingerprint string
BuiltAt time.Time
}
func NewSnapshot ¶
func NewSnapshot() *CompiledSnapshot
func (*CompiledSnapshot) AddEntrypoint ¶
func (s *CompiledSnapshot) AddEntrypoint(name, address string, entrypoint EntrypointRuntime) *CompiledSnapshot
func (*CompiledSnapshot) AddRoute ¶
func (s *CompiledSnapshot) AddRoute(route *CompiledRoute) *CompiledSnapshot
func (*CompiledSnapshot) AddService ¶
func (s *CompiledSnapshot) AddService(service *ServiceRuntime) *CompiledSnapshot
func (*CompiledSnapshot) BuildCatalog ¶
func (s *CompiledSnapshot) BuildCatalog() *CompiledSnapshot
func (*CompiledSnapshot) BuildMatchers ¶
func (s *CompiledSnapshot) BuildMatchers() *CompiledSnapshot
func (*CompiledSnapshot) QueryRoutes ¶
func (s *CompiledSnapshot) QueryRoutes(filter RouteFilter) *collectionlist.List[RouteView]
func (*CompiledSnapshot) Routes ¶
func (s *CompiledSnapshot) Routes() *collectionlist.List[RouteView]
func (*CompiledSnapshot) ServicesView ¶
func (s *CompiledSnapshot) ServicesView() *collectionlist.List[ServiceView]
type CompressRuntime ¶ added in v0.1.1
type EndpointRuntime ¶
type EndpointRuntime struct {
URL *url.URL
Weight int
Proxy http.Handler
Healthy atomic.Bool
LastChecked atomic.Int64
}
func NewEndpoint ¶
type EndpointView ¶
type EntrypointMatcher ¶
type EntrypointMatcher struct {
// contains filtered or unexported fields
}
func BuildEntrypointMatcher ¶
func BuildEntrypointMatcher(routes *collectionlist.List[*CompiledRoute]) *EntrypointMatcher
type EntrypointRuntime ¶
type EntrypointRuntime struct {
Name string
Address string
TLS TLSRuntime
}
type ForwardAuthRuntime ¶ added in v0.1.2
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
func NewGateway ¶
func NewGateway(snapshot *CompiledSnapshot, logger *slog.Logger, accessEnabled bool, metrics MetricsRecorder) *Gateway
func NewGatewayWithMiddlewareRegistry ¶
func NewGatewayWithMiddlewareRegistry(snapshot *CompiledSnapshot, logger *slog.Logger, accessEnabled bool, metrics MetricsRecorder, registry *MiddlewareRegistry) *Gateway
func (*Gateway) MetricsHandler ¶
func (*Gateway) ObserveHealth ¶
func (g *Gateway) ObserveHealth(endpoint *EndpointRuntime, healthy bool)
func (*Gateway) ObserveHealthCheck ¶ added in v0.1.1
func (g *Gateway) ObserveHealthCheck(endpoint *EndpointRuntime, healthy bool, duration time.Duration)
func (*Gateway) ObserveRaftApply ¶ added in v0.1.4
func (*Gateway) ObserveReload ¶
func (*Gateway) ObserveReloadDebounce ¶ added in v0.1.4
func (*Gateway) ObserveReloadDuration ¶ added in v0.1.4
func (*Gateway) ObserveRouteCache ¶ added in v0.1.1
func (*Gateway) ObserveSnapshot ¶
func (g *Gateway) ObserveSnapshot(snapshot *CompiledSnapshot)
func (*Gateway) Snapshot ¶
func (g *Gateway) Snapshot() *CompiledSnapshot
func (*Gateway) Swap ¶
func (g *Gateway) Swap(snapshot *CompiledSnapshot)
type HealthCheckMetricsRecorder ¶ added in v0.1.1
type HealthCheckMetricsRecorder interface {
ObserveHealthCheck(endpoint *EndpointRuntime, healthy bool, duration time.Duration)
}
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
func NewHealthChecker ¶
func NewHealthChecker(interval, timeout time.Duration) *HealthChecker
func NewHealthCheckerWithLogger ¶
func NewHealthCheckerWithLogger(interval, timeout time.Duration, logger *slog.Logger) *HealthChecker
func (*HealthChecker) Stop ¶
func (h *HealthChecker) Stop()
type HealthMetricsRecorder ¶
type HealthMetricsRecorder interface {
ObserveHealth(endpoint *EndpointRuntime, healthy bool)
}
type IPAllowListRuntime ¶ added in v0.1.1
type IPAllowListRuntime struct {
Enabled bool
SourceRange *collectionlist.List[string]
TrustForwardHeader bool
}
type MetricsRecorder ¶
type MetricsRecorder interface {
Observe(route *CompiledRoute, endpoint *EndpointRuntime, status int, duration time.Duration)
Handler() http.Handler
}
func NewNoopMetrics ¶
func NewNoopMetrics() MetricsRecorder
func NewObservabilityMetrics ¶
func NewObservabilityMetrics(enabled bool, obs observabilityx.Observability, handler http.Handler) MetricsRecorder
type MiddlewareFactory ¶
type MiddlewareFactory func(http.Handler, MiddlewareRuntime) http.Handler
type MiddlewareRecord ¶
type MiddlewareRegistry ¶
type MiddlewareRegistry struct {
// contains filtered or unexported fields
}
func DefaultMiddlewareRegistry ¶
func DefaultMiddlewareRegistry() *MiddlewareRegistry
func NewMiddlewareRegistry ¶
func NewMiddlewareRegistry() *MiddlewareRegistry
func (*MiddlewareRegistry) Clone ¶
func (r *MiddlewareRegistry) Clone() *MiddlewareRegistry
func (*MiddlewareRegistry) Factory ¶
func (r *MiddlewareRegistry) Factory(middlewareType string) (MiddlewareFactory, bool)
func (*MiddlewareRegistry) Names ¶
func (r *MiddlewareRegistry) Names() *collectionlist.List[string]
func (*MiddlewareRegistry) Register ¶
func (r *MiddlewareRegistry) Register(middlewareType string, factory MiddlewareFactory) error
type MiddlewareRuntime ¶
type MiddlewareRuntime struct {
Name string
Type string
StripPrefix string
StripPrefixes *collectionlist.List[string]
AddPrefix string
ReplacePath string
ReplacePathRegex string
ReplacePathReplacement string
RedirectScheme string
RedirectPort string
RedirectRegex string
RedirectReplacement string
RedirectPermanent bool
RequestHeaders *mapping.Map[string, string]
ResponseHeaders *mapping.Map[string, string]
MaxBodyBytes int64
Chain *collectionlist.List[string]
Secure SecureMiddlewareRuntime
CORS CORSMiddlewareRuntime
RateLimit RateLimitRuntime
CircuitBreaker CircuitBreakerRuntime
BasicAuth BasicAuthRuntime
Compress CompressRuntime
IPAllowList IPAllowListRuntime
ForwardAuth ForwardAuthRuntime
}
func NewMiddleware ¶
func NewMiddleware(name string) MiddlewareRuntime
type RaftApplyMetricsRecorder ¶ added in v0.1.4
type RateLimitRuntime ¶
type ReloadDebounceMetricsRecorder ¶ added in v0.1.4
type ReloadDurationMetricsRecorder ¶ added in v0.1.4
type ReloadMetricsRecorder ¶
type ReloadMetricsRecorder interface {
ObserveReload(result string)
}
type ResourceDiff ¶ added in v0.1.1
type ResourceDiff struct {
Added *collectionlist.List[string] `json:"added"`
Removed *collectionlist.List[string] `json:"removed"`
Changed *collectionlist.List[string] `json:"changed"`
}
func EmptyResourceDiff ¶ added in v0.1.1
func EmptyResourceDiff() ResourceDiff
func (ResourceDiff) HasChanges ¶ added in v0.1.1
func (d ResourceDiff) HasChanges() bool
type RouteCacheMetricsRecorder ¶ added in v0.1.1
type RouteCacheMetricsRecorder interface {
ObserveRouteCache(hit bool)
}
type RouteFilter ¶
type RouteRecord ¶
type SecureMiddlewareRuntime ¶
type SecureMiddlewareRuntime struct {
Enabled bool
AllowedHosts *collectionlist.List[string]
AllowedHostsAreRegex bool
SSLRedirect bool
SSLHost string
SSLTemporaryRedirect bool
STSSeconds int64
STSIncludeSubdomains bool
STSPreload bool
FrameDeny bool
ContentTypeNosniff bool
BrowserXSSFilter bool
ContentSecurityPolicy string
ContentSecurityPolicyReportOnly string
ReferrerPolicy string
PermissionsPolicy string
}
type SecurityRuntime ¶
type ServiceRecord ¶
type ServiceRuntime ¶
type ServiceRuntime struct {
Name string
Strategy string
Endpoints *collectionlist.List[*EndpointRuntime]
// contains filtered or unexported fields
}
func NewService ¶
func NewService(name, strategy string, endpoints ...*EndpointRuntime) *ServiceRuntime
func (*ServiceRuntime) BuildSlots ¶
func (s *ServiceRuntime) BuildSlots()
func (*ServiceRuntime) Pick ¶
func (s *ServiceRuntime) Pick() (*EndpointRuntime, error)
type ServiceView ¶
type ServiceView struct {
Name string `json:"name"`
Strategy string `json:"strategy"`
Endpoints *collectionlist.List[EndpointView] `json:"endpoints"`
}
type SnapshotDiff ¶ added in v0.1.1
type SnapshotDiff struct {
Routes ResourceDiff `json:"routes"`
Services ResourceDiff `json:"services"`
Endpoints ResourceDiff `json:"endpoints"`
}
func DiffSnapshots ¶ added in v0.1.1
func DiffSnapshots(current, next *CompiledSnapshot) SnapshotDiff
func (SnapshotDiff) HasChanges ¶ added in v0.1.1
func (d SnapshotDiff) HasChanges() bool
type SnapshotMetricsRecorder ¶
type SnapshotMetricsRecorder interface {
ObserveSnapshot(snapshot *CompiledSnapshot)
}
type TLSRuntime ¶
type TLSRuntime struct {
Enabled bool
CertFile string
KeyFile string
ACME ACMERuntime
}
Source Files
¶
- access_log.go
- access_middleware.go
- admin_view.go
- builder.go
- catalog.go
- catalog_fallback.go
- catalog_insert.go
- catalog_schema.go
- compress_middleware.go
- diff.go
- doc.go
- entrypoint_handler.go
- forward_auth_middleware.go
- gateway_runtime.go
- handler_index.go
- health.go
- matcher.go
- matcher_normalize.go
- matcher_predicate.go
- metrics.go
- metrics_recorders.go
- middleware.go
- policy_middleware.go
- route_match_cache.go
- runtime.go
- service.go
- status_recorder.go
Click to show internal directories.
Click to hide internal directories.