Documentation
¶
Overview ¶
Package relay contains the Relay application component that combines all of the internal components and implements HTTP endpoints.
This package is not in internal/ so that the exported Relay type can be used by external code to embed Relay functionality into a customized application. See docs/in-app.md.
Index ¶
- func IsNotReady(err error) bool
- func IsUnrecognizedEnvironment(err error) bool
- type ClientFactoryFunc
- type EnvironmentLookup
- func (e *EnvironmentLookup) DeleteEnvironment(params credential.SDKCredential) (relayenv.EnvContext, bool)
- func (e *EnvironmentLookup) Environments() (envs []relayenv.EnvContext)
- func (e *EnvironmentLookup) InsertEnvironment(env relayenv.EnvContext)
- func (e *EnvironmentLookup) Lookup(params credential.SDKCredential) (relayenv.EnvContext, bool)
- func (e *EnvironmentLookup) LookupByIdentifier(identifier string) (relayenv.EnvContext, bool)
- func (e *EnvironmentLookup) MapRequestParams(params credential.SDKCredential, env relayenv.EnvContext)
- func (e *EnvironmentLookup) RefreshEnvironmentIndexes(env relayenv.EnvContext)
- func (e *EnvironmentLookup) UnmapRequestParams(params credential.SDKCredential)
- type Relay
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotReady ¶
Types ¶
type ClientFactoryFunc ¶
ClientFactoryFunc is a function that can be used with NewRelay to specify custom behavior when Relay needs to create a Go SDK client instance.
type EnvironmentLookup ¶
type EnvironmentLookup struct {
// contains filtered or unexported fields
}
EnvironmentLookup is responsible for maintaining a mapping between incoming requests from SDKs, and outbound connections to LaunchDarkly.
A configured LaunchDarkly connection can be authenticated in one or more ways: SDK key, mobile key, or client-side environment ID, and, in v9, several of each kind can be accepted at once. This component must be able to accept any of these credentials and find the correct environment.
The credential mapping is one entry per accepted credential, and the conns set holds each unique environment connection exactly once. Identifier-based indexes (environment ID, configured name, and project/environment key pairs) make the status endpoints able to address an environment without knowing its credentials.
As an example, assume two environments are configured (envA and envB). Both are authenticated with an SDK key, mobile key, and environment ID.
The credential map has 6 entries:
envA SDK key, envA mobile key, envA env-ID -> envA envB SDK key, envB mobile key, envB env-ID -> envB
and conns holds the two environments themselves. An environment that accepts several SDK keys (from a concurrent-keys payload or a rotation in progress) has one entry per accepted key, all pointing at the same environment.
func NewEnvironmentLookup ¶
func NewEnvironmentLookup() *EnvironmentLookup
NewEnvironmentLookup instantiates an empty instance of EnvironmentLookup. Calls into EnvironmentLookup are thread safe.
func (*EnvironmentLookup) DeleteEnvironment ¶
func (e *EnvironmentLookup) DeleteEnvironment(params credential.SDKCredential) (relayenv.EnvContext, bool)
DeleteEnvironment searches for an environment identified by the client request params, deletes it, and then removes all other credential mappings. If an environment was deleted, returns true; otherwise, returns false and the first value is undefined.
func (*EnvironmentLookup) Environments ¶
func (e *EnvironmentLookup) Environments() (envs []relayenv.EnvContext)
Environments returns a list of all managed environment connections. Environments are only removed by DeleteEnvironment/DeleteEnvironment; removing credential mappings do not affect the environment itself.
func (*EnvironmentLookup) InsertEnvironment ¶
func (e *EnvironmentLookup) InsertEnvironment(env relayenv.EnvContext)
InsertEnvironment creates a mapping from the given environment's credentials (and optional filter key) to that environment, which can later be looked up using Lookup. Only credentials that are defined are mapped (credential.Defined() must return true for each).
func (*EnvironmentLookup) Lookup ¶
func (e *EnvironmentLookup) Lookup(params credential.SDKCredential) (relayenv.EnvContext, bool)
Lookup searches for a mapping from connection parameters to a suitable environment connection. If a connection is found, returns true; otherwise, returns false and the first value is undefined.
func (*EnvironmentLookup) LookupByIdentifier ¶
func (e *EnvironmentLookup) LookupByIdentifier(identifier string) (relayenv.EnvContext, bool)
LookupByIdentifier searches for an environment by a flexible identifier string and optional filter key. The identifier can be: - An environment ID (e.g., "507f1f77bcf86cd799439011") - A project/environment key pair separated by "/" (e.g., "my-app/production") - A configured name (e.g., "My Production Environment")
Lookup precedence: envID → projKey/envKey (contains "/") → configuredName
If a matching environment is found, returns true; otherwise, returns false.
func (*EnvironmentLookup) MapRequestParams ¶
func (e *EnvironmentLookup) MapRequestParams(params credential.SDKCredential, env relayenv.EnvContext)
MapRequestParams creates a mapping from connection parameters to an environment connection. It can be used if a new credential/filter is introduced which wasn't present when the environment was originally inserted using InsertEnvironment.
func (*EnvironmentLookup) RefreshEnvironmentIndexes ¶
func (e *EnvironmentLookup) RefreshEnvironmentIndexes(env relayenv.EnvContext)
RefreshEnvironmentIndexes updates the identifier-based indexes for an environment. This should be called after the environment's identifiers have changed via SetIdentifiers. It removes all existing index entries for this environment and re-adds them with current identifiers.
func (*EnvironmentLookup) UnmapRequestParams ¶
func (e *EnvironmentLookup) UnmapRequestParams(params credential.SDKCredential)
UnmapRequestParams removes a mapping from connection parameters to an environment.
type Relay ¶
Relay represents the overall Relay Proxy application.
It can also be referenced externally in order to embed Relay Proxy functionality into a customized application; see docs/in-app.md.
This type deliberately exports no methods other than ServeHTTP and Close. Everything else is an implementation detail which is subject to change.
func NewRelay ¶
func NewRelay(c config.Config, logger *slog.Logger, clientFactory ClientFactoryFunc) (*Relay, error)
NewRelay creates a new Relay given a configuration and a method to create a client.
If OTLP metrics export is enabled in c.OpenTelemetry, it also sets up the metrics pipeline.
The clientFactory parameter can be nil and is only needed if you want to customize how Relay creates the Go SDK client instance.
func (*Relay) AddConnectionMapping ¶
func (r *Relay) AddConnectionMapping(params credential.SDKCredential, env relayenv.EnvContext)
AddConnectionMapping updates the RelayCore's environment mapping to reflect that a new credential is now enabled for this EnvContext. This should be done only *after* calling EnvContext.AddCredential() so that if the RelayCore receives an incoming request with the new credential immediately after this, it will work.
func (*Relay) Close ¶
Close shuts down components created by the Relay Proxy.
This includes dropping all connections to the LaunchDarkly services and to SDK clients, closing database connections if any, and stopping all Relay port listeners, goroutines, and OpenCensus exporters.
func (*Relay) RemoveConnectionMapping ¶
func (r *Relay) RemoveConnectionMapping(params credential.SDKCredential)
RemoveConnectionMapping updates the RelayCore's environment mapping to reflect that this credential is no longer enabled. This should be done *before* calling EnvContext.RemoveCredential() because RemoveCredential() disconnects all existing streams, and if a client immediately tries to reconnect using the same credential we want it to be rejected.