proxy

package
v0.1.0-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package proxy hosts the embedded L7/L4 proxy (tasks T-41..T-48). This file freezes the RouteSource contract between the route-table client and the proxy/DNS/VIP consumers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivateFunc

type ActivateFunc func(ctx context.Context, envID string) error

ActivateFunc asks the control plane to wake a scaled-to-zero env. It returns when the activation has been requested (not when the endpoint is ready).

type Activator

type Activator struct {
	// contains filtered or unexported fields
}

Activator holds a request for a scaled-to-zero env: it triggers activation, waits (bounded) for the env to gain a healthy endpoint via route updates, then signals the caller to retry — or sheds/expires the request (T-70).

func NewActivator

func NewActivator(source RouteSource, activate ActivateFunc, clk clock.Clock) *Activator

NewActivator builds an activator over a route source and an activation hook.

func (*Activator) ColdStart

func (a *Activator) ColdStart() (count uint64, avg time.Duration, max time.Duration)

ColdStart returns cold-start latency stats for metrics/introspection.

func (*Activator) Hold

func (a *Activator) Hold(w http.ResponseWriter, r *http.Request, envID string, ready func() bool) bool

Hold parks a request for an env until ready() reports the caller may proceed — a healthy endpoint appearing (scale-to-zero cold start) or a replica freeing capacity (serverless backpressure). It triggers activation (which nudges the scheduler to add replicas) and waits on route updates plus a short poll. Returns true when the caller should re-select an endpoint and proxy; false when the activator has already written a response (503 shed, 504 timeout, or oversized body).

type L4

type L4 struct {
	// contains filtered or unexported fields
}

L4 is the raw TCP passthrough proxy (spec F5). It reconciles one listener per L4Route.public_port to the current RouteSnapshot, and for each accepted connection picks a healthy backend (P2C) and splices bytes both ways.

func NewL4

func NewL4(source RouteSource, node string, log *slog.Logger) *L4

NewL4 builds the L4 proxy over a route source. node is this node's id (used to break P2C ties toward node-local backends).

func (*L4) Run

func (l *L4) Run(ctx context.Context)

Run reconciles listeners to each snapshot until ctx is canceled, then closes all listeners (established connections drain on their own).

type L7

type L7 struct {

	// DisableHTTPSRedirect serves plaintext requests directly instead of
	// 308-redirecting them to HTTPS. Single-node/dev sets this: HTTPS runs on a
	// non-standard port with a self-signed cert, so a bare https:// redirect
	// would be broken (T-54).
	DisableHTTPSRedirect bool
	// contains filtered or unexported fields
}

L7 is the ingress HTTP reverse proxy: it matches a request to a route from the current RouteSnapshot, load-balances across the route's healthy endpoints (P2C), applies per-route middleware, and proxies. It serves both the :80 and :443 listeners (HTTPS redirect happens on the plaintext side).

func NewL7

func NewL7(source RouteSource, node string, clk clock.Clock) *L7

NewL7 builds an L7 proxy over a route source. node is this node's id (used to prefer node-local endpoints).

func (*L7) Activator

func (p *L7) Activator() *Activator

Activator returns the configured activator (nil if wake-on-request is off).

func (*L7) ServeHTTP

func (p *L7) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*L7) SetActivator

func (p *L7) SetActivator(a *Activator)

SetActivator enables wake-on-request for scaled-to-zero envs (T-70).

func (*L7) Stats

func (p *L7) Stats() *Stats

Stats exposes the metrics accumulator (heartbeat sampling).

type RouteClient

type RouteClient struct {
	// contains filtered or unexported fields
}

RouteClient keeps a WatchRoutes stream, persists each snapshot to disk, and implements proxy.RouteSource. It loads the last snapshot at startup so a node keeps serving traffic while the control plane is unreachable (spec §7).

func NewRouteClient

func NewRouteClient(dialer RouteDialer, nodeID, path string, log *slog.Logger) *RouteClient

NewRouteClient constructs the client. path is where snapshots are cached.

func (*RouteClient) Current

func (c *RouteClient) Current() *clusterv1.RouteSnapshot

Current returns the latest snapshot (never nil).

func (*RouteClient) Run

func (c *RouteClient) Run(ctx context.Context)

Run keeps the WatchRoutes stream alive, applying each snapshot and reconnecting with backoff. It returns when ctx is canceled.

func (*RouteClient) Updates

func (c *RouteClient) Updates(ctx context.Context) <-chan *clusterv1.RouteSnapshot

Updates returns a channel receiving each new snapshot until ctx is canceled.

type RouteDialer

type RouteDialer interface {
	WatchRoutes(ctx context.Context, haveVersion uint64) (RouteStream, error)
}

RouteDialer opens a WatchRoutes stream to a control node (over node mTLS). The daemon supplies the concrete transport; tests inject a fake.

type RouteSource

type RouteSource interface {
	// Current returns the latest snapshot (never nil; may be an empty
	// snapshot with Version 0 before the first sync).
	Current() *clusterv1.RouteSnapshot
	// Updates returns a channel receiving each new snapshot. The channel is
	// closed when ctx is canceled. Slow consumers may miss intermediate
	// versions but always eventually receive the latest.
	Updates(ctx context.Context) <-chan *clusterv1.RouteSnapshot
}

RouteSource provides the current route table and change notifications. Implementations: the RouteStream gRPC client with disk cache (T-42), a static source for tests, and a direct in-process source on control nodes.

type RouteStream

type RouteStream interface {
	Recv() (*clusterv1.RouteSnapshot, error)
}

RouteStream is the receive side of a WatchRoutes stream.

type StaticRouteSource

type StaticRouteSource struct {
	Snapshot *clusterv1.RouteSnapshot
}

StaticRouteSource serves a fixed snapshot (tests, and the bootstrap window before the first stream sync).

func (*StaticRouteSource) Current

func (*StaticRouteSource) Updates

func (s *StaticRouteSource) Updates(ctx context.Context) <-chan *clusterv1.RouteSnapshot

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

Stats accumulates per-environment proxy metrics. The agent heartbeat reads a Snapshot into ProxySample (T-14).

func NewStats

func NewStats(clk clock.Clock) *Stats

NewStats constructs the metrics accumulator.

func (*Stats) Inflight

func (s *Stats) Inflight(env string) int64

Inflight returns the current in-flight count for an env (test/introspection).

func (*Stats) Snapshot

func (s *Stats) Snapshot() map[string]*clusterv1.ProxySample

Snapshot returns the current per-env ProxySample and resets the rps window.

Jump to

Keyboard shortcuts

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