Documentation
¶
Overview ¶
Package optimizely wraps the Optimizely SDK
Package optimizely wraps the Optimizely SDK ¶
Package optimizely wraps the Optimizely SDK ¶
Package optimizely //
Package optimizely //
Index ¶
- Variables
- func SetLogger(logger *zerolog.Logger)
- type Cache
- type Decision
- type LogConsumer
- type MetricsRegistry
- type OptlyCache
- type OptlyClient
- func (c *OptlyClient) ActivateExperiment(key string, uc entities.UserContext, disableTracking bool) (*Decision, error)
- func (c *OptlyClient) ActivateFeature(key string, uc entities.UserContext, disableTracking bool) (*Decision, error)
- func (c *OptlyClient) RemoveForcedVariation(experimentKey, userID string) (*Override, error)
- func (c *OptlyClient) SetForcedVariation(experimentKey, userID, variationKey string) (*Override, error)
- func (c *OptlyClient) TrackEvent(eventKey string, uc entities.UserContext, eventTags map[string]interface{}) (*Track, error)
- func (c *OptlyClient) UpdateConfig()
- type Override
- type SyncedConfigManager
- type Track
Constants ¶
This section is empty.
Variables ¶
var ErrEntityNotFound = errors.New("not found")
ErrEntityNotFound is returned when no entity exists with a given key
var ErrForcedVariationsUninitialized = errors.New("client forced variations store not initialized")
ErrForcedVariationsUninitialized is returned from SetForcedVariation and GetForcedVariation when the forced variations store is not initialized
var ErrValidationFailure = errors.New("sdkKey failed validation")
ErrValidationFailure is returned when the provided SDK key fails initial validation
var ShouldIncludeSDKKey = true
ShouldIncludeSDKKey Defaults to true to include the SDK in log fields
Functions ¶
Types ¶
type Cache ¶
type Cache interface {
GetClient(sdkKey string) (*OptlyClient, error)
UpdateConfigs(sdkKey string)
// SetUserProfileService sets userProfileService to be used for the given sdkKey
SetUserProfileService(sdkKey, userProfileService string)
}
Cache defines a basic interface for retrieving an instance of the OptlyClient keyed off of the SDK Key
type Decision ¶
type Decision struct {
UserID string `json:"userId"`
ExperimentKey string `json:"experimentKey"`
FeatureKey string `json:"featureKey"`
VariationKey string `json:"variationKey"`
Type string `json:"type"`
Variables map[string]interface{} `json:"variables,omitempty"`
Enabled bool `json:"enabled"`
Error string `json:"error,omitempty"`
}
Decision Model
type LogConsumer ¶
type LogConsumer struct {
// contains filtered or unexported fields
}
LogConsumer is an implementation of the OptimizelyLogConsumer that wraps a zerolog logger
func (*LogConsumer) Log ¶
func (l *LogConsumer) Log(level logging.LogLevel, message string, fields map[string]interface{})
Log logs the message if it's log level is higher than or equal to the logger's set level
func (*LogConsumer) SetLogLevel ¶
func (l *LogConsumer) SetLogLevel(level logging.LogLevel)
SetLogLevel changes the log level to the given level
type MetricsRegistry ¶
type MetricsRegistry struct {
// contains filtered or unexported fields
}
MetricsRegistry initializes metrics registry
func NewRegistry ¶
func NewRegistry(registry *metrics.Registry) *MetricsRegistry
NewRegistry initializes metrics registry
func (*MetricsRegistry) GetCounter ¶
func (m *MetricsRegistry) GetCounter(key string) go_sdk_metrics.Counter
GetCounter gets sdk Counter
func (*MetricsRegistry) GetGauge ¶
func (m *MetricsRegistry) GetGauge(key string) go_sdk_metrics.Gauge
GetGauge gets sdk Gauge
type OptlyCache ¶
type OptlyCache struct {
// contains filtered or unexported fields
}
OptlyCache implements the Cache interface backed by a concurrent map. The default OptlyClient lookup is based on supplied configuration via env variables.
func NewCache ¶
func NewCache(ctx context.Context, conf config.ClientConfig, metricsRegistry *MetricsRegistry) *OptlyCache
NewCache returns a new implementation of OptlyCache interface backed by a concurrent map.
func (*OptlyCache) GetClient ¶
func (c *OptlyCache) GetClient(sdkKey string) (*OptlyClient, error)
GetClient is used to fetch an instance of the OptlyClient when the SDK Key is explicitly supplied.
func (*OptlyCache) Init ¶
func (c *OptlyCache) Init(sdkKeys []string)
Init takes a slice of sdkKeys to warm the cache upon startup
func (*OptlyCache) SetUserProfileService ¶
func (c *OptlyCache) SetUserProfileService(sdkKey, userProfileService string)
SetUserProfileService sets userProfileService to be used for the given sdkKey
func (*OptlyCache) UpdateConfigs ¶
func (c *OptlyCache) UpdateConfigs(sdkKey string)
UpdateConfigs is used to update config for all clients corresponding to a particular SDK key.
func (*OptlyCache) Wait ¶
func (c *OptlyCache) Wait()
Wait for all optimizely clients to gracefully shutdown
type OptlyClient ¶
type OptlyClient struct {
*optimizelyclient.OptimizelyClient
ConfigManager SyncedConfigManager
ForcedVariations *decision.MapExperimentOverridesStore
UserProfileService decision.UserProfileService
}
OptlyClient wraps an instance of the OptimizelyClient to provide higher level functionality
func (*OptlyClient) ActivateExperiment ¶
func (c *OptlyClient) ActivateExperiment(key string, uc entities.UserContext, disableTracking bool) (*Decision, error)
ActivateExperiment activates an experiment
func (*OptlyClient) ActivateFeature ¶
func (c *OptlyClient) ActivateFeature(key string, uc entities.UserContext, disableTracking bool) (*Decision, error)
ActivateFeature activates a feature for a given user by getting the feature enabled status and all associated variables
func (*OptlyClient) RemoveForcedVariation ¶
func (c *OptlyClient) RemoveForcedVariation(experimentKey, userID string) (*Override, error)
RemoveForcedVariation removes any forced variation that was previously set for the argument experiment key and user ID
func (*OptlyClient) SetForcedVariation ¶
func (c *OptlyClient) SetForcedVariation(experimentKey, userID, variationKey string) (*Override, error)
SetForcedVariation sets a forced variation for the argument experiment key and user ID Returns false if the same forced variation was already set for the argument experiment and user, true otherwise Returns an error when forced variations are not available on this OptlyClient instance
func (*OptlyClient) TrackEvent ¶
func (c *OptlyClient) TrackEvent(eventKey string, uc entities.UserContext, eventTags map[string]interface{}) (*Track, error)
TrackEvent checks for the existence of the event before calling the OptimizelyClient Track method
func (*OptlyClient) UpdateConfig ¶
func (c *OptlyClient) UpdateConfig()
UpdateConfig uses config manager to sync and set project config
type Override ¶
type Override struct {
UserID string `json:"userId"`
ExperimentKey string `json:"experimentKey"`
VariationKey string `json:"variationKey"`
PrevVariationKey string `json:"prevVariationKey"`
Messages []string `json:"messages"`
}
Override model
type SyncedConfigManager ¶
type SyncedConfigManager interface {
optimizelyconfig.ProjectConfigManager
SyncConfig()
}
SyncedConfigManager has the basic ConfigManager methods plus the SyncConfig method to trigger immediate updates