core

package
v6.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package core contains Relay Proxy core implementation components and internal APIs.

The principle behind the organization of this code is as follows:

1. Anything that needs to be referenced from the top-level Relay application code should be in internal/core or one of its subpackages - unless it is entirely related to an "enterprise" feature (such as autoconfig), in which case it can be in internal/ but outside of core.

2. Anything that needs to be referenced only from within the core code, and not from any higher level, should be in a subpackage of internal/core/internal so that it cannot be imported from anywhere outside of the internal/core subtree.

This is meant to encourage as much encapsulation as possible, and also to facilitate separating out the "enterprise" code from the rest of the Relay distribution if that ever becomes desirable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ObscureKey

func ObscureKey(key string) string

ObscureKey returns an obfuscated version of an SDK key or mobile key.

Types

type BigSegmentStatusRep added in v6.4.0

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"`
	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           string               `json:"sdkKey"`
	EnvID            string               `json:"envId,omitempty"`
	EnvKey           string               `json:"envKey,omitempty"`
	EnvName          string               `json:"envName,omitempty"`
	ProjKey          string               `json:"projKey,omitempty"`
	ProjName         string               `json:"projName,omitempty"`
	MobileKey        string               `json:"mobileKey,omitempty"`
	ExpiringSDKKey   string               `json:"expiringSdkKey,omitempty"`
	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 RelayCore

type RelayCore struct {
	Version string

	Loggers ldlog.Loggers
	// contains filtered or unexported fields
}

RelayCore encapsulates the core logic for all variants of Relay Proxy.

func NewRelayCore

func NewRelayCore(
	c config.Config,
	loggers ldlog.Loggers,
	clientFactory sdks.ClientFactoryFunc,
	version string,
	userAgent string,
	envLogNameMode relayenv.LogNameMode,
) (*RelayCore, error)

NewRelayCore creates and configures an instance of RelayCore, and immediately starts initializing all configured environments.

func (*RelayCore) AddEnvironment

func (r *RelayCore) AddEnvironment(
	identifiers relayenv.EnvIdentifiers,
	envConfig config.EnvConfig,
	transformClientConfig func(ld.Config) ld.Config,
) (relayenv.EnvContext, <-chan relayenv.EnvContext, error)

AddEnvironment attempts to add a new environment. It returns an error only if the configuration is invalid; it does not wait to see whether the connection to LaunchDarkly succeeded.

func (*RelayCore) AddedEnvironmentCredential

func (r *RelayCore) AddedEnvironmentCredential(env relayenv.EnvContext, newCredential config.SDKCredential)

AddedEnvironmentCredential 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 (*RelayCore) Close

func (r *RelayCore) Close()

Close shuts down all existing environments and releases all resources used by RelayCore.

func (*RelayCore) GetAllEnvironments

func (r *RelayCore) GetAllEnvironments() []relayenv.EnvContext

GetAllEnvironments returns all currently configured environments.

func (*RelayCore) GetEnvironment

func (r *RelayCore) GetEnvironment(credential config.SDKCredential) (relayenv.EnvContext, bool)

GetEnvironment returns the environment object corresponding to the given credential, or nil if not found. The credential can be an SDK key, a mobile key, or an environment ID. The second return value is normally true, but is false if Relay does not yet have a valid configuration (which affects our error handling).

func (*RelayCore) MakeRouter

func (r *RelayCore) MakeRouter() *mux.Router

MakeRouter creates and configures a Router containing all of the standard routes for RelayCore. The Relay or RelayEnterprise code may add additional routes.

IMPORTANT: The route strings that are used here, such as "/sdk/evalx/{envId}/users/{user}", will appear in metrics data under the "route" tag if Relay is configured to export metrics. Therefore, we should use variable names like {envId} consistently and make sure they correspond to how the routes are shown in docs/endpoints.md.

func (*RelayCore) RemoveEnvironment

func (r *RelayCore) RemoveEnvironment(env relayenv.EnvContext) bool

RemoveEnvironment shuts down and removes an existing environment. All network connections, metrics resources, and (if applicable) database connections, are immediately closed for this environment. Subsequent requests using credentials for this environment will be rejected.

It returns true if successful, or false if there was no such environment.

func (*RelayCore) RemovingEnvironmentCredential

func (r *RelayCore) RemovingEnvironmentCredential(oldCredential config.SDKCredential)

RemovingEnvironmentCredential 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.

func (*RelayCore) SetFullyConfigured added in v6.1.1

func (r *RelayCore) SetFullyConfigured(fullyConfigured bool)

SetFullyConfigured updates the state of whether Relay has a valid set of environments.

func (*RelayCore) WaitForAllClients

func (r *RelayCore) WaitForAllClients(timeout time.Duration) error

WaitForAllClients blocks until all environments that were in the initial configuration have reported back as either successfully connected or failed, or until the specified timeout (if the timeout is non-zero).

type StatusRep

type StatusRep struct {
	Environments  map[string]EnvironmentStatusRep `json:"environments"`
	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.

Directories

Path Synopsis
Package application providers helpers used by the command-line entry points of all versions of Relay.
Package application providers helpers used by the command-line entry points of all versions of Relay.
Package bigsegments contains logic for synchronizing big segments.
Package bigsegments contains logic for synchronizing big segments.
Package httpconfig provides helpers for special types of HTTP client configuration supported by Relay.
Package httpconfig provides helpers for special types of HTTP client configuration supported by Relay.
internal
browser
Package browser contains internal helpers that are only used for browser requests.
Package browser contains internal helpers that are only used for browser requests.
events
Package events contains the internal implementation of event forwarding.
Package events contains the internal implementation of event forwarding.
metrics
Package metrics implements Relay's integration with OpenCensus.
Package metrics implements Relay's integration with OpenCensus.
store
Package store contains the internal implementation of how Relay interacts with the SDK's DataStore to detect data updates.
Package store contains the internal implementation of how Relay interacts with the SDK's DataStore to detect data updates.
Package logging provides logging-related helpers.
Package logging provides logging-related helpers.
Package middleware contains helpers for adding standard behavior like authentication and metrics to REST endpoints.
Package middleware contains helpers for adding standard behavior like authentication and metrics to REST endpoints.
Package relayenv contains the internal interface and implementation of EnvConfig, the object that manages Relay state for a specific configured LD environment.
Package relayenv contains the internal interface and implementation of EnvConfig, the object that manages Relay state for a specific configured LD environment.
Package sdks contains types and helpers for describing the behavior of different kinds of SDKs that can connect to Relay, and also for Relay's own use of the Go SDK.
Package sdks contains types and helpers for describing the behavior of different kinds of SDKs that can connect to Relay, and also for Relay's own use of the Go SDK.
Package sharedtest provides helper code and test data that may be used by tests in all Relay components and distributions.
Package sharedtest provides helper code and test data that may be used by tests in all Relay components and distributions.
testclient
Package testclient contains test helpers that reference the SDK-related packages.
Package testclient contains test helpers that reference the SDK-related packages.
testenv
Package testenv contains test helpers that reference the relayenv package.
Package testenv contains test helpers that reference the relayenv package.
testsuites
Package testsuites contains shared test suites that should be run against every version of Relay to validate the behavior of the core code.
Package testsuites contains shared test suites that should be run against every version of Relay to validate the behavior of the core code.
Package streams defines the Relay core abstractions for implementing streaming endpoints, and provides some standard implementations for those endpoints.
Package streams defines the Relay core abstractions for implementing streaming endpoints, and provides some standard implementations for those endpoints.

Jump to

Keyboard shortcuts

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