proxy

package
v0.1.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 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 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 {

	// Activate is the scale-to-zero hook (T-71). Nil for now.
	Activate func(envID string)

	// 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) ServeHTTP

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

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