relay

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 29 Imported by: 0 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 relay starts an in-process relay proxy for the benchmarks and the soak harness.

Index

Constants

View Source
const (

	// APIKey is the key of the flag set that the requests of the harness carry.
	APIKey = "loadtest-key"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Endpoint

type Endpoint string

Endpoint is one of the relay proxy evaluation endpoints.

const (
	// SemaphoreEval is POST /v1/feature/{key}/eval.
	SemaphoreEval Endpoint = "semaphore-eval"
	// SemaphoreAllFlags is POST /v1/allflags.
	SemaphoreAllFlags Endpoint = "semaphore-allflags"
	// OFREPEval is POST /ofrep/v1/evaluate/flags/{key}.
	OFREPEval Endpoint = "ofrep-eval"
	// OFREPBulk is POST /ofrep/v1/evaluate/flags.
	OFREPBulk Endpoint = "ofrep-bulk"
)

func Endpoints

func Endpoints() []Endpoint

Endpoints returns all the endpoints.

func ParseEndpoint

func ParseEndpoint(name string) (Endpoint, error)

ParseEndpoint validates an endpoint name. The legacy goff-eval and goff-allflags names are aliases.

func (Endpoint) Body

func (e Endpoint) Body(i int) string

Body returns a request body with a realistic evaluation context (10 attributes) for the user i.

func (Endpoint) EmitsEvents

func (e Endpoint) EmitsEvents() bool

EmitsEvents reports whether evaluating through the endpoint queues feature events in the exporter. The bulk endpoints (GetFlagStates / AllFlagsState) evaluate without emitting events.

func (Endpoint) NewRequest

func (e Endpoint) NewRequest(baseURL, flagKey string, i int) (*http.Request, error)

NewRequest builds the HTTP request (without a URL host) for the endpoint.

func (Endpoint) Path

func (e Endpoint) Path(flagKey string) string

Path returns the URL path of the endpoint for a flag key.

type Options

type Options struct {
	// FlagsYAML is the flag configuration (see loadtest.FlagsYAML).
	FlagsYAML string
	// ExporterMode is the behaviour of the webhook sink the relay proxy exports to.
	// An empty value disables the exporter.
	ExporterMode loadtest.ExporterMode
	// TempDir is the directory the flag file directory is created in (default: os.TempDir()).
	TempDir string
	// FlushIntervalMs is the flush interval of the exporter (default 1000).
	FlushIntervalMs int64
	// MaxEventInMemory is the flush trigger of the exporter (default 100000).
	MaxEventInMemory int64
	// H2C makes the relay proxy accept HTTP/2 over cleartext; only with Listen.
	H2C bool
	// Listen enables the real HTTP server on a free loopback port (needed for the soak).
	Listen bool
	// ReadySeconds bounds the wait for the first generation to be applied, in seconds (default 15): a very large
	// fleet needs more, above all with the race detector. It is a small integer to keep Options small.
	ReadySeconds uint16
}

Options configures Start.

type Relay

type Relay struct {

	// FlagSets finds the flag set of APIKey, to build handlers in-process.
	FlagSets service.FlagSetResolver
	// Metrics are the metrics of the handlers.
	Metrics *metric.Metrics
	// BaseURL is the loopback URL of the HTTP server (only if Options.Listen).
	BaseURL string

	// SinkRequests counts the requests received by the webhook sink.
	SinkRequests atomic.Int64
	// SinkBytes counts the bytes received by the webhook sink.
	SinkBytes atomic.Int64
	// contains filtered or unexported fields
}

Relay is a running relay proxy: a version 2 core on a file store, and its HTTP server when it listens.

func Start

func Start(opts Options) (*Relay, error)

Start starts a relay proxy.

func StartDocument added in v0.2.0

func StartDocument(doc string, lookupEnv func(string) (string, bool), opts *Options) (*Relay, error)

StartDocument starts a relay proxy on a version 2 bootstrap file that the caller wrote, and on content that the caller published to the store that the file names before the call (generation 1 at least). The relay owns no directory and no sink. lookupEnv resolves the secrets of the file (nil: none). A failed start releases what it started.

func StartDocumentWithLogger added in v0.3.0

func StartDocumentWithLogger(
	doc string, lookupEnv func(string) (string, bool), opts *Options, logger *slog.Logger,
) (*Relay, error)

StartDocumentWithLogger is StartDocument with a logger that receives the logs of the relay and the lines of its log exporter (nil: they are discarded).

func StartDocumentWithManager added in v1.0.0

func StartDocumentWithManager(
	doc string, lookupEnv func(string) (string, bool), opts *Options, logger *slog.Logger,
	newManager events.NewManagerFunc,
) (_ *Relay, err error)

StartDocumentWithManager is StartDocumentWithLogger with the function that builds the manager of each exporter (nil: the default manager). A test sets the clock and the limits of the managers with it.

func StartWithStore added in v0.2.0

func StartWithStore(opts *Options, store *StoreOptions) (_ *Relay, err error)

StartWithStore starts a relay proxy with the segment store that store describes (nil: none, as Start).

func (*Relay) Close

func (r *Relay) Close()

Close stops the relay proxy and removes its temporary flag file.

func (*Relay) Dir

func (r *Relay) Dir() string

Dir returns the temporary directory holding the flag file (removed by Close).

func (*Relay) OpenStreams added in v1.0.0

func (r *Relay) OpenStreams() int

OpenStreams is the number of change streams (SSE) that clients have open on the relay.

func (*Relay) Refresh added in v0.2.0

func (r *Relay) Refresh(ctx context.Context) (uint64, error)

Refresh polls the control plane now (what the admin refresh does) and returns the generation that the relay serves once the engine decided what the poll found. It fails when the engine did not apply the generation.

func (*Relay) Republish added in v0.2.0

func (r *Relay) Republish(ctx context.Context, flagsYAML string) error

Republish publishes flagsYAML as the next manifest generation, polls the control plane now (what the admin refresh does) and returns once the engine decided it. It fails when the engine did not apply the generation.

func (*Relay) Status added in v0.3.0

func (r *Relay) Status() relaycore.Status

Status is the status of the core of the relay: its exporters, their counters and the event queue. It can be read after Close.

type StoreOptions added in v0.2.0

type StoreOptions struct {
	// Logger receives the logs of the relay; nil discards them.
	Logger *slog.Logger
	// Connections is more entries of the connections section of the bootstrap file, written as YAML flow lines
	// indented by two spaces.
	Connections string
	// Sections is more top-level sections of the bootstrap file (for example the segments resolver).
	Sections string
	// SegmentsDoc is a Segments document that the flag set lists in its segmentSources. Empty: none.
	SegmentsDoc string
}

StoreOptions adds a segment store to a relay (see StartWithStore): the load and chaos tests of the dynamic segments.

type Target

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

Target evaluates flags against a real relay proxy over loopback HTTP.

func NewTarget

func NewTarget(opts Options, endpoint Endpoint, flagKey string, workers int) (*Target, error)

NewTarget starts a relay proxy and returns a soak target for the endpoint. It rejects an unknown endpoint, and a slow or failing exporter on an endpoint that does not emit events (the exporter would be bypassed and the soak would not measure what it claims).

func (*Target) Close

func (t *Target) Close()

Close implements loadtest.Target.

func (*Target) Eval

func (t *Target) Eval(worker, i int) error

Eval implements loadtest.Target.

func (*Target) Extra

func (t *Target) Extra() map[string]int64

Extra implements loadtest.Target.

func (*Target) FlagsPerCall

func (t *Target) FlagsPerCall() int

FlagsPerCall implements loadtest.Weighted: the number of flags of a bulk response, 1 for a single evaluation.

func (*Target) Protocol

func (t *Target) Protocol() string

Protocol returns the HTTP protocol the target speaks ("HTTP/1.1" or "h2c").

func (*Target) Relay added in v0.2.0

func (t *Target) Relay() *Relay

Relay is the relay proxy the target evaluates against (a test republishes its flags through it).

Jump to

Keyboard shortcuts

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