upstreamretry

package
v1.135.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package upstreamretry is the one reading of when an upstream HTTP answer is worth asking for again and how long the upstream asked to be left alone. The api gateway reports it on its results (#1859), a managed script's host acts on it, and the gateway's own page walk pauses by the same Retry-After parse (#1535), so the three cannot disagree about what a 429 means.

Index

Constants

View Source
const (
	KeyRetryable  = "upstream_retryable"
	KeyRetryAfter = "retry_after_seconds"
)

The result keys an answer's advice is reported under. They are the contract between the tool that reports it and the host that acts on it.

View Source
const (
	CodeUnavailable     = "upstream_unavailable"
	CategoryUnavailable = "upstream"
)

The error code and category of a tool whose upstream timed out, dropped the connection or could not be reached: not the caller's fault, and the same call made later is expected to succeed. The error contract (pkg/middleware) sets them on such a result, and a managed script's host records a run ended by one as retryable.

View Source
const (
	// MaxRetries is how many times one call is issued again.
	MaxRetries = 3
)

The host side (#1859). A managed script's host reads the advice a tool result carries, waits and issues the call again, a bounded number of times and never past the run's deadline, and then hands the script whatever the upstream answered last: a script has no clock and no try/except, so a throttled request it cannot outwait itself is a run it cannot finish.

Variables

This section is empty.

Functions

func After

func After(value string, now time.Time) (time.Duration, bool)

After reads a Retry-After value in either form RFC 9110 allows: a delay in seconds or an HTTP date. A date in the past is a zero wait; an empty or unreadable value is no interval at all.

func Retryable

func Retryable(method string, status int) bool

Retryable reports whether an upstream that answered a method request with status is expected to admit the same request later. A 429 is, whatever the method: the upstream says it refused the request for its rate, not for its content, and did not act on it. A 503 is only for a GET or a HEAD, whose repetition cannot change anything, because an unavailable service may have done part of what a write asked before it answered.

Types

type Advice

type Advice struct {
	// Retryable is set on an answer the same request is expected to get past
	// later (see Retryable).
	Retryable bool `json:"upstream_retryable,omitempty"`
	// RetryAfterSeconds is how long the upstream asked to be left alone, when
	// it said; zero when it did not.
	RetryAfterSeconds int `json:"retry_after_seconds,omitempty"`
}

Advice is what one upstream answer says about asking again, as a tool result carries it: absent on an answer that is not worth repeating.

func Advise

func Advise(method string, status int, header http.Header, now time.Time) Advice

Advise reads the advice of one answer to a request made with method.

type Seen

type Seen struct {
	Retryable bool
	// Status is the upstream's HTTP status, read from upstream_status
	// (api_export) or status (api_invoke_endpoint).
	Status int
	// After is the interval the upstream asked for; zero when it named none.
	After time.Duration
}

Seen is what one tool result says about issuing the call again.

func FromResult

func FromResult(out map[string]any) Seen

FromResult reads the advice a tool result carries.

func (Seen) Answer

func (a Seen) Answer() string

Answer names the upstream's answer for the run log: "429 Too Many Requests".

func (Seen) Wait

func (a Seen) Wait(retry int, remaining time.Duration) (time.Duration, bool)

Wait is how long to wait before issuing the call again as retry number retry (zero-based), given how long the run has left; ok is false when the call is not to be issued again and its answer goes to the script.

Jump to

Keyboard shortcuts

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