prolane

package
v8.175.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package prolane is devctl serve's side of pro's lane: the loopback HTTP stand-in for https://api.github.com through which every GitHub request of the workspace App's installations goes: one serial queue with pacing, a conditional cache and the installation's token per installation.

devctl holds no GitHub credential in App mode. Transport sends its requests to the lane without one, names the lane's priority class and, where the path names no account, the installation's account, counts the points they cost, and turns the lane's refusals into a *RefusedError. Lane.Observe reports what one observation's poll cost and answers when to poll it next.

Index

Constants

View Source
const (
	// HeaderOwner names the account whose installation's lane a request
	// takes when its path names none: GraphQL, and REST paths outside
	// /repos/{owner}, /orgs/{org} and /users/{user}.
	HeaderOwner = "X-Lane-Owner"
	// HeaderPriority is the request's priority class.
	HeaderPriority = "X-Lane-Priority"
	// HeaderMaxWait bounds how long the request may wait in its lane, in
	// milliseconds; the lane's default is 20,000.
	HeaderMaxWait = "X-Lane-Max-Wait-Ms"
	// HeaderCache says whether the lane answered from its cache: hit or miss.
	HeaderCache = "X-Lane-Cache"
	// HeaderRefused names why the lane refused a request.
	HeaderRefused = "X-Lane-Refused"
	// HeaderRetryAfterMs is a 429's Retry-After in milliseconds.
	HeaderRetryAfterMs = "X-Lane-Retry-After-Ms"
)

The headers of the lane.

View Source
const (
	// RefusedSaturated (429): the request would wait in its lane past its
	// limit.
	RefusedSaturated = "saturated"
	// RefusedPaused (429): GitHub's rate limit paused the lane.
	RefusedPaused = "paused"
	// RefusedReserve (429): a starting or metrics request while the
	// primary budget is below its reserve.
	RefusedReserve = "reserve"
	// RefusedWritesOff (403): a write while the lane's writes are off.
	RefusedWritesOff = "writes-off"
	// RefusedForbiddenPath (403): a path that mints, lists or revokes
	// credentials.
	RefusedForbiddenPath = "forbidden-path"
	// RefusedNotInstalled (403): a request for an account the App is not
	// installed on.
	RefusedNotInstalled = "not-installed"
	// RefusedNoOwner (400): a request whose path names no account, without
	// HeaderOwner.
	RefusedNoOwner = "no-owner"
)

The lane's reasons for a refusal, in HeaderRefused.

View Source
const CacheHit = "hit"

CacheHit is HeaderCache of an answer the lane gave from its cache: GitHub answered 304 and the lane its cached 200.

View Source
const DefaultMaxWait = 20 * time.Second

DefaultMaxWait is the lane's own bound on a request's wait in its lane; a request whose deadline is nearer names that instead.

View Source
const EnvAddress = "PRO_LANE_ADDRESS"

EnvAddress is the environment variable pro reads the lane's address from; devctl serve reads the same one.

View Source
const MetaPriority = "giantswarm.io/priority"

MetaPriority is the key of a tool call's _meta that names its priority class.

View Source
const MinNextPoll = 10 * time.Second

MinNextPoll is the shortest wait before an observation's next poll that the lane answers.

Variables

This section is empty.

Functions

func ParseAddress

func ParseAddress(address string) (*url.URL, error)

ParseAddress is the lane's address as a URL: http on a loopback host, as "127.0.0.1:8081" or "http://127.0.0.1:8081/". The lane takes no credential of its own, so devctl sends its requests to no other host.

Types

type Lane

type Lane struct {
	URL *url.URL
	// Client sends the reports; nil is a client of http.DefaultTransport
	// with a 10 s timeout.
	Client *http.Client
}

Lane is the lane endpoint at URL, an address ParseAddress accepted.

func (Lane) Observe

func (l Lane) Observe(ctx context.Context, owner, key string, points Points) (State, error)

Observe reports one poll of the observation key on owner's lane, which cost points, and returns the lane's state with its NextPollMs.

type Points

type Points struct {
	REST    int `json:"rest"`
	GraphQL int `json:"graphql"`
}

Points are what requests cost in their lane: a REST GET or HEAD 1 and any other method 5, a GraphQL query 1 and a mutation 5. Every request the lane sends upstream is charged, a 304 included.

type Priority

type Priority string

Priority is a request's class in its lane. The lane sends the oldest request of the highest waiting class its budget allows; under saturation the lower classes wait, and are refused, first.

const (
	// PriorityMerge is for merges and repairs.
	PriorityMerge Priority = "merge"
	// PriorityWrite is for every other write.
	PriorityWrite Priority = "write"
	// PriorityContinuing is for the observations of runs that hold a
	// lease, and the default of every read.
	PriorityContinuing Priority = "continuing"
	// PriorityStarting is for the observations of runs that wait to start,
	// and trigger sources.
	PriorityStarting Priority = "starting"
	// PriorityMetrics is for metrics and reports.
	PriorityMetrics Priority = "metrics"
)

The classes, highest first.

func ParsePriority

func ParsePriority(value string) (Priority, error)

ParsePriority is the class named value; empty is PriorityContinuing.

type RefusedError

type RefusedError struct {
	// Reason is the lane's, HeaderRefused.
	Reason string
	// Status is the HTTP status the lane answered.
	Status int
	// Message is the lane's message.
	Message string
	// RetryAfter is when the lane takes the request again, for a 429.
	RetryAfter time.Duration
	// Method and Path are the request's.
	Method, Path string
}

RefusedError is a lane response marked with HeaderRefused. agentcli.Retrying passes it to the caller, which can poll again.

func (*RefusedError) Answered

func (e *RefusedError) Answered() bool

Answered implements agentcli.Answered.

func (*RefusedError) Deferred added in v8.175.0

func (e *RefusedError) Deferred() bool

Deferred implements agentcli.Deferred: a busy lane (429) takes the read again later, while any other refusal stands.

func (*RefusedError) Error

func (e *RefusedError) Error() string

func (*RefusedError) ExitCode

func (e *RefusedError) ExitCode() int

ExitCode implements agentcli.ExitCoder.

func (*RefusedError) ExitVerdict

func (e *RefusedError) ExitVerdict() agentcli.Verdict

ExitVerdict implements agentcli.ExitCoder.

type State

type State struct {
	// NextPollMs is when to poll the observation again, in milliseconds:
	// max(10,000, 60,000 × roundPoints / (0.8 × pointsPerMinute), pause
	// left), roundPoints being what one poll of every observation active on
	// the lane costs.
	NextPollMs int64 `json:"nextPollMs"`
	// Installation is the App installation the lane serves.
	Installation int64 `json:"installation"`
	// RoundPoints is the cost of polling every active observation once,
	// split by API. Observations is the number of active observations.
	RoundPoints  Points `json:"roundPoints"`
	Observations int    `json:"observations"`
	// PausedForMs is how long the lane stays paused.
	PausedForMs int64 `json:"pausedForMs"`
	// Queued is how many requests wait in the lane.
	Queued int `json:"queued"`
}

State is the lane's answer to an observation's report.

type Transport

type Transport struct {
	// Base sends the requests; nil is http.DefaultTransport.
	Base http.RoundTripper
	// Owner is the account a request whose path names none is for.
	Owner string
	// Priority is every request's class; empty is PriorityContinuing.
	Priority Priority
	// Prefix is the lane's path prefix, "/" for a lane at its root.
	Prefix string
	// contains filtered or unexported fields
}

Transport sends requests to the lane: Base sends them to the lane's address, which the client's base URL already names.

It removes any Authorization and Cookie header (the lane drops them too), sets HeaderPriority, HeaderOwner where the path names no account and HeaderMaxWait from the request's deadline (at most DefaultMaxWait), counts the Points of every request the lane did not refuse, and returns a refusal as a *RefusedError. Responses without HeaderRefused pass through to the GitHub client and its usual retry handling.

func (*Transport) CacheHits

func (t *Transport) CacheHits() int

CacheHits is how many answers the lane gave from its cache.

func (*Transport) Points

func (t *Transport) Points() Points

Points are what the requests sent so far cost.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

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