api

package
v9.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 10 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 api contains representation types for Relay's REST endpoints which may be referenced from multiple packages.

Index

Constants

View Source
const (
	// StatusHealthy means Relay knows its full set of environments and every one of them is
	// healthy.
	StatusHealthy = "healthy"

	// StatusDegraded means at least one environment is unhealthy, or Relay does not yet know its
	// full set of environments. Relay keeps serving flags in this state.
	StatusDegraded = "degraded"

	// EnvStatusConnected means the environment has a client that is initialized and whose data
	// source has not been disconnected for longer than the configured grace period.
	EnvStatusConnected = "connected"

	// EnvStatusDisconnected means the environment has no client yet, or its data source has been
	// away for longer than the configured grace period. The environment still serves the data it
	// has.
	EnvStatusDisconnected = "disconnected"

	// The data store states. These spell their values the same way DataSourceState does, but the
	// data store status is a plain string in the document rather than that type, and it never
	// reports OFF.
	DataStoreStateValid        = "VALID"
	DataStoreStateInitializing = "INITIALIZING"
	DataStoreStateInterrupted  = "INTERRUPTED"
)

The values the status document reports for its state fields. They live here, rather than only where the document is built, because the status metrics report the same vocabulary as attribute values and the two must agree.

View Source
const ExpectParam = "expect"

ExpectParam is the query parameter that carries the assertion clauses.

View Source
const MaxExpectClauses = 100

MaxExpectClauses is the most "expect" clauses one request can carry. The status endpoints are unauthenticated, and each clause walks the status document, so the limit bounds the work that one request can cause.

Variables

This section is empty.

Functions

func ParseExpectQuery

func ParseExpectQuery(rawQuery string) (clauses []string, requested, malformed bool)

ParseExpectQuery reads the "expect" clauses out of a raw URL query string. requested reports whether the caller used the parameter at all; malformed reports whether the query string could be parsed.

This does not go through Request.URL.Query(), which discards the parse error from url.ParseQuery and drops only the offending segment. A clause the relay cannot decode would then look identical to no clause at all, and the handler would answer 200 with the full status document for an assertion it never evaluated. Go rejects a segment holding a raw ";" or a bad "%" escape, and hand-encoding is exactly what the bracket-quoted environment keys ask callers to do, so this is reachable from a single-character typo. A verdict endpoint has to fail closed, so the error is surfaced to the caller instead.

Types

type AutoConfigStatusRep

type AutoConfigStatusRep struct {
	State      interfaces.DataSourceState `json:"state"`
	StateSince ldtime.UnixMillisecondTime `json:"stateSince"`
	LastError  *ConnectionErrorRep        `json:"lastError,omitempty"`
}

AutoConfigStatusRep is the status of the auto-configuration stream. It is present only when Relay runs in automatic configuration mode.

This is exported for use in integration test code.

type BigSegmentStatusRep

type BigSegmentStatusRep struct {
	Available          bool                       `json:"available"`
	PotentiallyStale   bool                       `json:"potentiallyStale"`
	LastSynchronizedOn ldtime.UnixMillisecondTime `json:"lastSynchronizedOn"`
}

BigSegmentStatusRep is the big segment status representation returned by the status endpoint.

This is exported for use in integration test code.

type ConnectionErrorRep

type ConnectionErrorRep struct {
	Kind interfaces.DataSourceErrorKind `json:"kind"`
	// StatusCode is the HTTP status that caused the error. It is absent for an error that did not
	// come from an HTTP response, such as a network failure.
	StatusCode int                        `json:"statusCode,omitempty"`
	Time       ldtime.UnixMillisecondTime `json:"time"`
}

ConnectionErrorRep is the optional error information in ConnectionStatusRep.

This is exported for use in integration test code.

type ConnectionStatusRep

type ConnectionStatusRep struct {
	State      interfaces.DataSourceState `json:"state"`
	StateSince ldtime.UnixMillisecondTime `json:"stateSince"`
	LastError  *ConnectionErrorRep        `json:"lastError,omitempty"`
}

ConnectionStatusRep is the data source status representation returned by the status endpoint.

This is exported for use in integration test code.

type DataStoreStatusRep

type DataStoreStatusRep struct {
	State      string                     `json:"state"`
	StateSince ldtime.UnixMillisecondTime `json:"stateSince"`
	Database   string                     `json:"database,omitempty"`
	DBServer   string                     `json:"dbServer,omitempty"`
	DBPrefix   string                     `json:"dbPrefix,omitempty"`
	DBTable    string                     `json:"dbTable,omitempty"`
}

DataStoreStatusRep is the data store status representation returned by the status endpoint.

This is exported for use in integration test code.

type EnvironmentStatusRep

type EnvironmentStatusRep struct {
	// SDKKey is the obscured anchor SDK key. It designates which SDKKeys entry owns the
	// environment's connection to LaunchDarkly.
	//
	// It is deliberately kept alongside the array rather than replaced by a flag on an entry. It
	// predates concurrent keys and is what consumers read to identify an environment, v8 reports the
	// same pair of fields, and encoding the designation in two places would let them drift.
	SDKKey string `json:"sdkKey"`
	// SDKKeys is every server-side SDK key the environment accepts, the anchor included. It is always
	// present and always holds at least the anchor. Order is unspecified.
	SDKKeys []KeyStatus `json:"sdkKeys"`
	EnvID   string      `json:"envId,omitempty"`
	EnvKey  string      `json:"envKey,omitempty"`
	EnvName string      `json:"envName,omitempty"`
	ProjKey string      `json:"projKey,omitempty"`
	// ProjName is the project's name.
	ProjName string `json:"projName,omitempty"`
	// MobileKey is the obscured primary mobile key. It designates which MobileKeys entry is the one
	// used where a single mobile key is required, such as event forwarding.
	MobileKey string `json:"mobileKey,omitempty"`
	// MobileKeys is every mobile key the environment accepts, the primary included. It is always
	// present, and empty for an environment with no mobile key.
	MobileKeys       []KeyStatus          `json:"mobileKeys"`
	Status           string               `json:"status"`
	ConnectionStatus ConnectionStatusRep  `json:"connectionStatus"`
	DataStoreStatus  DataStoreStatusRep   `json:"dataStoreStatus"`
	BigSegmentStatus *BigSegmentStatusRep `json:"bigSegmentStatus,omitempty"`
}

EnvironmentStatusRep is the per-environment JSON representation returned by the status endpoint.

This is exported for use in integration test code.

type ExpectationResult

type ExpectationResult struct {
	// Expr is the original clause as supplied by the caller.
	Expr string `json:"expr"`
	// Expected is the value the clause asserted. It is omitted for a clause that was not evaluated.
	Expected string `json:"expected,omitempty"`
	// Actual is the value found at the clause's path, rendered as a string. It is omitted for a
	// clause that was not evaluated, and empty when the path is absent from the body.
	Actual string `json:"actual,omitempty"`
	// At names the first entry that failed a clause with a "[*]" step, as a concrete path with each
	// wildcard replaced by that entry's key or index. It is empty for every other result, and for a
	// wildcard clause that failed because the collection itself is absent.
	At string `json:"at,omitempty"`
	// Problem describes why the clause could not be evaluated. It is empty for a clause that was.
	Problem string `json:"problem,omitempty"`
	// OK reports whether the clause held. It is false for a clause that was not evaluated.
	OK bool `json:"ok"`
}

ExpectationResult is the outcome of evaluating a single "expect" clause.

type ExpectationsResult

type ExpectationsResult struct {
	// Satisfied reports whether every clause was evaluated and held.
	Satisfied bool `json:"satisfied"`
	// Results contains one entry per clause, in the order supplied.
	Results []ExpectationResult `json:"results,omitempty"`
	// Error describes why the whole query was abandoned, as opposed to a problem with one clause.
	Error string `json:"error,omitempty"`
}

ExpectationsResult is the body returned when a status request includes "expect" clauses.

func EvaluateExpectations

func EvaluateExpectations(body []byte, clauses []string, schema StatusSchema) (ExpectationsResult, int)

EvaluateExpectations evaluates the "expect" clauses against a marshaled status body and returns the per-clause results together with the HTTP status code the handler should write. Every clause is evaluated, so one request reports every problem the caller needs to fix; the response code is the most serious outcome across all of them:

  • http.StatusBadRequest (400) when any clause does not parse, or when there are more than MaxExpectClauses clauses. In the second case no clause is evaluated.
  • http.StatusUnprocessableEntity (422) when any clause parses but names an operator or a field that cannot be evaluated against the schema.
  • http.StatusPreconditionFailed (412) when every clause is evaluable but at least one does not hold. A clause whose path is absent from the body is treated as unsatisfied: if the field the caller asserted about is not even present, the relay is not in the state they assumed.
  • http.StatusOK (200) when every clause holds.

body is the JSON the handler would otherwise have written, so a clause path matches exactly what the caller sees in the response. schema says which document that is.

type KeyStatus

type KeyStatus struct {
	Key    string `json:"key,omitempty"`
	Value  string `json:"value"`
	Expiry *int64 `json:"expiry,omitempty"`
}

KeyStatus is one accepted credential in the status resource's sdkKeys and mobileKeys arrays.

Key is the non-secret wire identifier, omitted when the source carried none. Value is the credential secret, obscured. Expiry is a Unix millisecond timestamp, omitted for a permanent key.

This replaces the singular expiringSdkKey field, which could name only one key and so could not describe an environment that accepts several with different expiries.

type RefusedEnvironmentRep

type RefusedEnvironmentRep struct {
	EnvID string `json:"envId"`
	// Reason is a short stable phrase. The detail is in Relay's log, because this resource needs no
	// authentication.
	Reason string `json:"reason"`
	// Serving distinguishes the two ways an environment reaches this list, which need different
	// responses.
	//
	// False means Relay has no configuration for the environment at all: it is absent from
	// Environments and SDKs presenting its credentials get a 401. That is an outage for it.
	//
	// True means Relay refused an update for an environment it already had, so the environment
	// appears in Environments as well and keeps serving the credentials it had before. Its flag data
	// is current; only the configuration Relay refused is not applied.
	Serving bool `json:"serving"`
}

RefusedEnvironmentRep is an environment whose configuration Relay would not accept.

The top-level status stays healthy for one of these, and so does autoConfigStatus, because the connection is working and the rest of the configuration applied. Without this list the only lasting signal is a log line.

This is exported for use in integration test code.

type StatusRep

type StatusRep struct {
	Environments     map[string]EnvironmentStatusRep `json:"environments"`
	AutoConfigStatus *AutoConfigStatusRep            `json:"autoConfigStatus,omitempty"`
	// RefusedEnvironments is every environment LaunchDarkly sent that Relay could not use. Read each
	// entry's Serving field before treating one as an outage: a refused configuration for an
	// environment Relay already had leaves that environment serving what it had before. The field is
	// always present, and empty when there is nothing refused, so a monitor can address it without
	// having to tell an empty list apart from a Relay too old to report one.
	RefusedEnvironments []RefusedEnvironmentRep `json:"refusedEnvironments"`
	Status              string                  `json:"status"`
	Version             string                  `json:"version"`
	ClientVersion       string                  `json:"clientVersion"`
}

StatusRep is the JSON representation returned by the status endpoint.

This is exported for use in integration test code.

type StatusSchema

type StatusSchema int

StatusSchema identifies which status document a set of clauses is evaluated against. Paths are relative to the body of the route that serves them, so the two routes validate against different roots.

const (
	// SchemaAllEnvironments is the body of the /status route: a StatusRep.
	SchemaAllEnvironments StatusSchema = iota
	// SchemaSingleEnvironment is the body of the per-environment status routes: a bare
	// EnvironmentStatusRep, with no "environments" wrapper.
	SchemaSingleEnvironment
)

Jump to

Keyboard shortcuts

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