Documentation ¶
Overview ¶
Package relayenv contains the internal interface and implementation of EnvConfig, the object that manages Relay state for a specific configured LD environment.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetEnvironmentID ¶
func GetEnvironmentID(env EnvContext) config.EnvironmentID
GetEnvironmentID is a helper for extracting the EnvironmentID, if any, from the set of credentials.
Types ¶
type EnvContext ¶
type EnvContext interface { io.Closer // GetIdentifiers returns information about the environment and project names and keys. GetIdentifiers() EnvIdentifiers // GetPayloadFilter returns the environment's filter key, which may be an empty string indicating // default/unfiltered. GetPayloadFilter() config.FilterKey // SetIdentifiers updates the environment and project names and keys. SetIdentifiers(EnvIdentifiers) // GetCredentials returns all currently enabled and non-deprecated credentials for the environment. GetCredentials() []credential.SDKCredential // GetDeprecatedCredentials returns all deprecated and not-yet-removed credentials for the environment. GetDeprecatedCredentials() []credential.SDKCredential // AddCredential adds a new credential for the environment. // // If the credential is an SDK key, then a new SDK client is started with that SDK key, and event forwarding // to server-side endpoints is switched to use the new key. AddCredential(credential.SDKCredential) // RemoveCredential removes a credential from the environment. Any active stream connections using that // credential are immediately dropped. // // If the credential is an SDK key, then the SDK client that we started with that SDK key is disposed of. RemoveCredential(credential.SDKCredential) // DeprecateCredential marks an existing credential as not being a preferred one, without removing it or // dropping any connections. It will no longer be included in the return value of GetCredentials(). This is // used in Relay Proxy Enterprise when an SDK key is being changed but the old key has not expired yet. DeprecateCredential(credential.SDKCredential) // GetClient returns the SDK client instance for this environment. This is nil if initialization is not yet // complete. Rather than providing the full client object, we use the simpler sdks.LDClientContext which // includes only the operations Relay needs to do. GetClient() sdks.LDClientContext // GetStore returns the SDK data store instance for this environment. This is nil if initialization is not // yet complete. GetStore() subsystems.DataStore // GetEvaluator returns an instance of the evaluation engine for evaluating feature flags in this environment. // This is nil if initialization is not yet complete. GetEvaluator() ldeval.Evaluator // GetBigSegmentStore returns the big segment data store instance for this environment. If a big // segment store is not configured this returns nil. GetBigSegmentStore() bigsegments.BigSegmentStore // GetLoggers returns a Loggers instance that is specific to this environment. We configure each of these to // have its own prefix string and, optionally, its own log level. GetLoggers() ldlog.Loggers // GetHandler returns the HTTP handler for the specified kind of stream requests and credential for this // environment. If there is none, it returns a handler for a 404 status (not nil). GetStreamHandler(streams.StreamProvider, credential.SDKCredential) http.Handler // GetEventDispatcher returns the object that proxies events for this environment. GetEventDispatcher() *events.EventDispatcher // GetJSClientContext returns the JSClientContext that is used for browser endpoints. GetJSClientContext() JSClientContext // GetMetricsContext returns the Context that should be used for OpenCensus operations related to this // environment. GetMetricsContext() context.Context // GetTTL returns the configured cache TTL for PHP SDK endpoints for this environment. GetTTL() time.Duration // SetTTL changes the configured cache TTL for PHP SDK endpoints for this environment. SetTTL(time.Duration) // GetInitError returns an error if initialization has failed, or nil otherwise. GetInitError() error // IsSecureMode returns true if client-side evaluation requests for this environment must have a valid // secure mode hash. IsSecureMode() bool // SetSecureMode changes the secure mode setting. SetSecureMode(bool) // GetCreationTime returns the time that this EnvContext was created. GetCreationTime() time.Time // GetDataStoreInfo returns information about the environment's data store. GetDataStoreInfo() sdks.DataStoreEnvironmentInfo // FlushMetricsEvents is used in testing to ensure that metrics events are delivered promptly. FlushMetricsEvents() }
EnvContext is the interface for all Relay operations that are specific to one configured LD environment.
The EnvContext is normally associated with an LDClient instance from the Go SDK, and allows direct access to the DataStore that is used by the SDK client. However, these are created asynchronously since the client connection may take a while, so it is possible for the client and store references to be nil if initialization is not yet complete.
func NewEnvContext ¶
func NewEnvContext( params EnvContextImplParams, readyCh chan<- EnvContext, ) (EnvContext, error)
NewEnvContext creates the internal implementation of EnvContext.
It immediately begins trying to initialize the SDK client for this environment. Since that might take a while, it is done on a separate goroutine. The EnvContext instance is returned immediately in an uninitialized state, and once the SDK client initialization has either succeeded or failed, the same EnvContext will be pushed to the channel readyCh.
NewEnvContext can also immediately return an error, with a nil EnvContext, if the configuration is invalid.
type EnvContextImplParams ¶
type EnvContextImplParams struct { Identifiers EnvIdentifiers EnvConfig config.EnvConfig AllConfig config.Config ClientFactory sdks.ClientFactoryFunc DataStoreFactory subsystems.ComponentConfigurer[subsystems.DataStore] DataStoreInfo sdks.DataStoreEnvironmentInfo StreamProviders []streams.StreamProvider JSClientContext JSClientContext MetricsManager *metrics.Manager BigSegmentStoreFactory bigsegments.BigSegmentStoreFactory BigSegmentSynchronizerFactory bigsegments.BigSegmentSynchronizerFactory SDKBigSegmentsConfigFactory subsystems.ComponentConfigurer[subsystems.BigSegmentsConfiguration] // set only in tests UserAgent string LogNameMode LogNameMode Loggers ldlog.Loggers }
EnvContextImplParams contains the constructor parameters for NewEnvContextImpl. These have their own type because there are a lot of them, and many are irrelevant in tests.
type EnvIdentifiers ¶
type EnvIdentifiers struct { // EnvKey is the environment key (normally a lowercase string like "production"). EnvKey string // EnvName is the environment name (normally a title-cased string like "Production"). EnvName string // ProjKey is the project key (normally a lowercase string like "my-application"). ProjKey string // ProjName is the project name (normally a title-cased string like "My Application"). ProjName string // FilterKey is the environment's payload filter. Empty string indicates no filter. FilterKey config.FilterKey // ConfiguredName is a human-readable unique name for this environment, if the user specified one. When // using a local configuration, this is always set; in auto-configuration mode, it is always empty (but // EnvIdentifiers.GetDisplayName() will compute one). ConfiguredName string }
EnvIdentifiers contains environment and project name and key properties.
When running in Relay Proxy Enterprise's auto-configuration mode, EnvKey, EnvName, ProjKey, and ProjName are copied from the LaunchDarkly dashboard settings. Otherwise, those are all blank and ConfiguredName is set in the local configuration.
func (EnvIdentifiers) GetDisplayName ¶
func (ei EnvIdentifiers) GetDisplayName() string
GetDisplayName returns a human-readable unique name for this environment. If none was set in the configuration, it computes one in the format "ProjName EnvName".
type JSClientContext ¶
type JSClientContext struct { // Origins is the configured list of allowed origins for CORS requests. Origins []string // Headers is the configured list of allowed headers for CORS requests. Headers []string // Proxy is a ReverseProxy that we create for requests that are to be directly proxied to a // LaunchDarkly endpoint. Despite its name, the Relay Proxy does not normally use direct // proxying, but in the case of the goals resource for JS clients it is the simplest way. Proxy *httputil.ReverseProxy }
JSClientContext contains additional environment properties that are only relevant if this environment supports JavaScript clients (i.e. we know its environment ID).
func (JSClientContext) AllowedHeaders ¶
func (c JSClientContext) AllowedHeaders() []string
AllowedHeaders implements the internal interface for getting additional CORS allowed headers.
func (JSClientContext) AllowedOrigins ¶
func (c JSClientContext) AllowedOrigins() []string
AllowedOrigins implements the internal interface for getting CORS allowed origins.
type LogNameMode ¶
type LogNameMode bool
LogNameMode is used in NewEnvContext to determine whether the environment's log messages should be tagged by SDK key or by environment ID.
const ( // LogNameIsSDKKey means the log messages should be tagged with the last 4 characters of the SDK key. // This is the default behavior for the Relay Proxy. LogNameIsSDKKey LogNameMode = false // LogNameIsEnvID means the log messages should be tagged with the last 4 characters of the environment // ID. This is the default behavior for Relay Proxy Enterprise when running in auto-configuration mode, // where we always know the environment ID but the SDK key is subject to change. LogNameIsEnvID LogNameMode = true )