Documentation
¶
Overview ¶
Package relay is the customer end of a Perfloop relay tunnel. It runs inside the customer network, opens WebSockets to the Perfloop API, and answers the proxy's validated telemetry reads by forwarding them to the configured upstreams, and carries opaque code-host TLS streams to fixed destinations. It collects nothing: no telemetry is stored or pushed and no inbound port is opened. Telemetry credentials stay here; code-host credentials and authorization stay at the proxy, inside end-to-end TLS. README.md describes the contract; package link owns the wire shape.
Index ¶
Constants ¶
const ( // DefaultMaxSeconds is the `seconds` cap of a pprof upstream that sets // none: net/http/pprof's own default CPU profile length. The largest cap // a config may set is link.MaxProfileSeconds. DefaultMaxSeconds = 30 // DefaultMaxConcurrent is the in-flight cap of a pprof upstream that // sets none: one profile at a time per upstream. DefaultMaxConcurrent = 1 // MaxConcurrentBound is the largest max_concurrent a config may set. It // is a config bound on how many processes profile at once, not a tunnel // property: the relay keeps two tunnels of maxStreams each. MaxConcurrentBound = 8 )
Variables ¶
This section is empty.
Functions ¶
func Routes ¶
Routes writes what a validated configuration permits, one upstream at a time: the kind, the URL the relay forwards to, the request headers it passes from Perfloop, the names of the headers it adds, and every request the relay will forward. For codehost it lists the fixed CONNECT name and destination, not HTTP read routes. The relay forwards a telemetry query unchanged unless it is a pprof query, whose seconds cap it checks. Secrets are never written: header values and the token stay out. The listing is written whole, in one write, so a failed write never leaves a partial listing that reports success.
Types ¶
type Config ¶
type Config struct {
// API is the URL of the Perfloop API the relay opens its tunnels to, for
// example https://app.perfloop.ai. The relay reaches it through
// HTTPS_PROXY when that is set; such a proxy must carry WebSockets.
API string `yaml:"api"`
// APICA is an optional PEM file trusted for the API certificate instead
// of the system roots, for networks whose egress proxy re-signs TLS.
APICA string `yaml:"api_ca"`
// Token is the operator-issued relay token for this tenant.
Token string `yaml:"token"`
// Upstreams lists the sources this relay may reach.
Upstreams []Upstream `yaml:"upstreams"`
// LogLevel is debug, info, warn, or error.
LogLevel string `yaml:"log_level"`
}
Config is the YAML shape of perfloop-relay. `${VAR}` references in the file expand from the environment before parsing, so the token and upstream credentials can come from a Kubernetes Secret; an unset variable fails at start, not at the first read.
type Relay ¶
type Relay struct {
// contains filtered or unexported fields
}
Relay answers proxy telemetry reads and carries code-host TLS streams to configured upstreams over tunnels to Perfloop.
func (*Relay) Run ¶
Run keeps the tunnels open until ctx ends. A tunnel that ends, for any reason, is reopened with backoff; a tunnel that lasted a minute resets the backoff. When ctx ends the tunnels close at once, including every CONNECT stream. Perfloop may move a telemetry read whose tunnel failed before its response started to another tunnel. CONNECT bytes are never replayed.
func (*Relay) ServeHTTP ¶
func (r *Relay) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP answers one proxy request from the tunnel. The Host names the upstream. A codehost upstream accepts only a pathless HTTP/2 CONNECT and streams opaque bytes to its fixed address. For telemetry, the path is forwarded under the upstream URL when its route is a documented read. For a pprof upstream the first path segment names the target process and the query is checked against the configured caps. One audit line records every decision with the read id Perfloop gave it, `<session id>/<tool call ref>`, which names the transcript turn that asked; a read no tool call made has none.
type Upstream ¶
type Upstream struct {
// Name is the `relay://<name>` endpoint that Setup registers. It is one
// lowercase DNS label.
Name string `yaml:"name"`
// Kind selects the transport or read routes the relay permits; routes.go
// lists the kinds (prometheus, victoriametrics, loki, pprof, and codehost).
Kind string `yaml:"kind"`
// URL is the provider base: scheme, host, port, and an optional path
// prefix for telemetry. The relay appends the proxy's request path to it.
// A codehost URL is an HTTPS origin with no path; the relay dials only its
// TCP address. A pprof upstream has Targets instead.
URL string `yaml:"url"`
// Targets are the processes of a pprof upstream: target name to the
// http(s) base of that process's net/http/pprof handler. Perfloop names
// one target per read as the first path segment; a name not listed here
// is refused. Each name is one lowercase DNS label.
Targets map[string]string `yaml:"targets"`
// MaxSeconds caps the `seconds` a pprof read may ask for, so a CPU
// profile cannot run longer than the customer allows. Zero means
// DefaultMaxSeconds. The bound is link.MaxProfileSeconds.
MaxSeconds int `yaml:"max_seconds"`
// MaxConcurrent caps the pprof reads in flight on this upstream across
// all of its targets, per relay process; a further read is refused at
// once with status 429. Perfloop spreads reads over every relay a tenant
// runs with the same token, so N relay processes admit N times this cap.
// The customer controls that count. Zero means DefaultMaxConcurrent. The
// bound is MaxConcurrentBound.
MaxConcurrent int `yaml:"max_concurrent"`
// Headers are added to every upstream request, for example an
// Authorization header holding a read token. They replace any header of
// the same name from the proxy. A codehost upstream refuses Headers.
Headers map[string]string `yaml:"headers"`
// CA is an optional PEM file trusted for this upstream's TLS certificate
// instead of the system roots. A codehost upstream refuses CA: its TLS
// goes end to end from the proxy, which owns certificate trust.
CA string `yaml:"ca"`
}
Upstream is one source inside the customer network.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
perfloop-relay
command
Command perfloop-relay runs inside a customer network.
|
Command perfloop-relay runs inside a customer network. |
|
Package link is what the two ends of a relay tunnel share: the wire shape (the relay that a customer runs and the Perfloop API that terminates the tunnel must agree on it) and the one way both read their configuration.
|
Package link is what the two ends of a relay tunnel share: the wire shape (the relay that a customer runs and the Perfloop API that terminates the tunnel must agree on it) and the one way both read their configuration. |