optimizely

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrEntityNotFound = errors.New("not found")

ErrEntityNotFound is returned when no entity exists with a given key

View Source
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

Functions

func SetLogger

func SetLogger(logger *zerolog.Logger)

SetLogger explicitly overwrites the zerolog used by the SDK with the provided zerolog logger.

Types

type Cache

type Cache interface {
	GetClient(sdkKey string) (*OptlyClient, error)
}

Cache defines a basic interface for retrieving an instance of the OptlyClient keyed off of the SDK Key

type Decision added in v0.12.0

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 added in v0.11.0

type MetricsRegistry struct {
	// contains filtered or unexported fields
}

MetricsRegistry initializes metrics registry

func NewRegistry added in v0.11.0

func NewRegistry(registry *metrics.Registry) *MetricsRegistry

NewRegistry initializes metrics registry

func (*MetricsRegistry) GetCounter added in v0.11.0

func (m *MetricsRegistry) GetCounter(key string) go_sdk_metrics.Counter

GetCounter gets sdk Counter

func (*MetricsRegistry) GetGauge added in v0.11.0

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 added in v0.12.0

func (c *OptlyCache) Init(sdkKeys []string)

Init takes a slice of sdkKeys to warm the cache upon startup

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
}

OptlyClient wraps an instance of the OptimizelyClient to provide higher level functionality

func (*OptlyClient) ActivateExperiment added in v0.12.0

func (c *OptlyClient) ActivateExperiment(key string, uc entities.UserContext, disableTracking bool) (*Decision, error)

ActivateExperiment activates an experiment

func (*OptlyClient) ActivateFeature added in v0.12.0

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 added in v0.13.0

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 added in v1.0.0

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 added in v0.13.0

type SyncedConfigManager interface {
	optimizelyconfig.ProjectConfigManager
	SyncConfig()
}

SyncedConfigManager has the basic ConfigManager methods plus the SyncConfig method to trigger immediate updates

type Track added in v1.0.0

type Track struct {
	UserID   string `json:"userId"`
	EventKey string `json:"eventKey"`
	Error    string `json:"error,omitempty"`
}

Track response model

Directories

Path Synopsis
Package optimizelytest //
Package optimizelytest //

Jump to

Keyboard shortcuts

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