Documentation ¶
Overview ¶
Package event //
Package event //
Package event //
Package event //
Package event //
Package event //
Index ¶
- Constants
- Variables
- type BPOptionConfig
- func WithBatchSize(bsize int) BPOptionConfig
- func WithEventDispatcher(d Dispatcher) BPOptionConfig
- func WithEventDispatcherMetrics(metricsRegistry metrics.Registry) BPOptionConfig
- func WithEventEndPoint(endPoint string) BPOptionConfig
- func WithFlushInterval(flushInterval time.Duration) BPOptionConfig
- func WithQueue(q Queue) BPOptionConfig
- func WithQueueSize(qsize int) BPOptionConfig
- func WithSDKKey(sdkKey string) BPOptionConfig
- type Batch
- type BatchEventProcessor
- type Context
- type ConversionEvent
- type Decision
- type DecisionMetadata
- type Dispatcher
- type ImpressionEvent
- type InMemoryQueue
- type LogEvent
- type Processor
- type Queue
- type QueueEventDispatcher
- type Snapshot
- type SnapshotEvent
- type UserEvent
- type Visitor
- type VisitorAttribute
Constants ¶
const CloseEventDispatchTimeout = 30 * time.Second
CloseEventDispatchTimeout holds the timeout value for the waiting for the dispatching events on client close
const CloseEventDispatchWaitTime = 500 * time.Millisecond
CloseEventDispatchWaitTime holds the checking interval for the dispatching events on client close
const DefaultBatchSize = 10
DefaultBatchSize holds the default value for the batch size
const DefaultEventEndPoint = "https://logx.optimizely.com/v1/events"
DefaultEventEndPoint is used as the default endpoint for sending events.
const DefaultEventFlushInterval = 30 * time.Second
DefaultEventFlushInterval holds the default value for the event flush interval
const DefaultEventQueueSize = 2000
DefaultEventQueueSize holds the default value for the event queue size
Variables ¶
var ClientName = "go-sdk"
ClientName is the name of the client
var Version = "2.0.0"
Version is the current version of the client
Functions ¶
This section is empty.
Types ¶
type BPOptionConfig ¶
type BPOptionConfig func(qp *BatchEventProcessor)
BPOptionConfig is the BatchProcessor options that give you the ability to add one more more options before the processor is initialized.
func WithBatchSize ¶
func WithBatchSize(bsize int) BPOptionConfig
WithBatchSize sets the batch size as a config option to be passed into the NewProcessor method
func WithEventDispatcher ¶
func WithEventDispatcher(d Dispatcher) BPOptionConfig
WithEventDispatcher sets the Processor Dispatcher as a config option to be passed into the NewProcessor method
func WithEventDispatcherMetrics ¶
func WithEventDispatcherMetrics(metricsRegistry metrics.Registry) BPOptionConfig
WithEventDispatcherMetrics sets metrics into the NewProcessor method
func WithEventEndPoint ¶
func WithEventEndPoint(endPoint string) BPOptionConfig
WithEventEndPoint sets the end point as a config option to be passed into the NewProcessor method
func WithFlushInterval ¶
func WithFlushInterval(flushInterval time.Duration) BPOptionConfig
WithFlushInterval sets the flush interval as a config option to be passed into the NewProcessor method
func WithQueue ¶
func WithQueue(q Queue) BPOptionConfig
WithQueue sets the Processor Queue as a config option to be passed into the NewProcessor method
func WithQueueSize ¶
func WithQueueSize(qsize int) BPOptionConfig
WithQueueSize sets the queue size as a config option to be passed into the NewProcessor method
func WithSDKKey ¶
func WithSDKKey(sdkKey string) BPOptionConfig
WithSDKKey sets the SDKKey used to register for notifications. This should be removed when the project config supports sdk key.
type Batch ¶
type Batch struct { Revision string `json:"revision"` AccountID string `json:"account_id"` ClientVersion string `json:"client_version"` Visitors []Visitor `json:"visitors"` ProjectID string `json:"project_id"` ClientName string `json:"client_name"` AnonymizeIP bool `json:"anonymize_ip"` EnrichDecisions bool `json:"enrich_decisions"` }
Batch - Context about the event to send in batch
type BatchEventProcessor ¶
type BatchEventProcessor struct { MaxQueueSize int // max size of the queue before flush FlushInterval time.Duration // in milliseconds BatchSize int EventEndPoint string Q Queue Ticker *time.Ticker EventDispatcher Dispatcher // contains filtered or unexported fields }
BatchEventProcessor is used out of the box by the SDK to queue up and batch events to be sent to the Optimizely log endpoint for results processing.
func NewBatchEventProcessor ¶
func NewBatchEventProcessor(options ...BPOptionConfig) *BatchEventProcessor
NewBatchEventProcessor returns a new instance of BatchEventProcessor with queueSize and flushInterval
func (*BatchEventProcessor) OnEventDispatch ¶
func (p *BatchEventProcessor) OnEventDispatch(callback func(logEvent LogEvent)) (int, error)
OnEventDispatch registers a handler for LogEvent notifications
func (*BatchEventProcessor) ProcessEvent ¶
func (p *BatchEventProcessor) ProcessEvent(event UserEvent) bool
ProcessEvent takes the given user event (can be an impression or conversion event) and queues it up to be dispatched to the Optimizely log endpoint. A dispatch happens when we flush the events, which can happen on a set interval or when the specified batch size (defaulted to 10) is reached.
func (*BatchEventProcessor) RemoveOnEventDispatch ¶
func (p *BatchEventProcessor) RemoveOnEventDispatch(id int) error
RemoveOnEventDispatch removes handler for LogEvent notification with given id
func (*BatchEventProcessor) Start ¶
func (p *BatchEventProcessor) Start(ctx context.Context)
Start does not do any initialization, just starts the ticker
type Context ¶
type Context struct { Revision string `json:"revision"` AccountID string `json:"account_id"` ClientVersion string `json:"client_version"` ProjectID string `json:"project_id"` ClientName string `json:"client_name"` AnonymizeIP bool `json:"anonymize_ip"` BotFiltering bool `json:"bot_filtering"` }
Context holds project-related contextual information about a UserEvent
func CreateEventContext ¶
func CreateEventContext(projectConfig config.ProjectConfig) Context
CreateEventContext creates and returns EventContext
type ConversionEvent ¶
type ConversionEvent struct { EntityID string `json:"entity_id"` Key string `json:"key"` Attributes []VisitorAttribute Tags map[string]interface{} `json:"tags,omitempty"` // these need to be pointers because 0 is a valid Revenue or Value. // 0 is equivalent to omitempty for json marshaling. Revenue *int64 `json:"revenue,omitempty"` Value *float64 `json:"value,omitempty"` }
ConversionEvent represents a conversion event
type Decision ¶
type Decision struct { VariationID string `json:"variation_id"` CampaignID string `json:"campaign_id"` ExperimentID string `json:"experiment_id"` Metadata DecisionMetadata `json:"metadata"` }
Decision represents a decision of a snapshot
type DecisionMetadata ¶
type DecisionMetadata struct { FlagKey string `json:"flag_key"` RuleKey string `json:"rule_key"` RuleType string `json:"rule_type"` VariationKey string `json:"variation_key"` Enabled bool `json:"enabled"` }
DecisionMetadata captures additional information regarding the decision
type Dispatcher ¶
Dispatcher dispatches events
func NewHTTPEventDispatcher ¶
func NewHTTPEventDispatcher(sdkKey string, requester *utils.HTTPRequester, logger logging.OptimizelyLogProducer) Dispatcher
NewHTTPEventDispatcher creates a full http dispatcher. The requester and logger parameters can be nil.
type ImpressionEvent ¶
type ImpressionEvent struct { Attributes []VisitorAttribute CampaignID string `json:"campaign_id"` EntityID string `json:"entity_id"` ExperimentID string `json:"experiment_id"` Key string `json:"key"` Metadata DecisionMetadata `json:"metadata"` VariationID string `json:"variation_id"` }
ImpressionEvent represents an impression event
type InMemoryQueue ¶
type InMemoryQueue struct { MaxSize int Queue []interface{} Mux sync.Mutex // contains filtered or unexported fields }
InMemoryQueue represents a in-memory queue
func (*InMemoryQueue) Get ¶
func (q *InMemoryQueue) Get(count int) []interface{}
Get returns queue for given count size
func (*InMemoryQueue) Remove ¶
func (q *InMemoryQueue) Remove(count int) []interface{}
Remove removes item from queue and returns elements slice
type Processor ¶
type Processor interface { ProcessEvent(event UserEvent) bool OnEventDispatch(callback func(logEvent LogEvent)) (int, error) RemoveOnEventDispatch(id int) error }
Processor processes events
type Queue ¶
type Queue interface { Add(item interface{}) // TODO Should return a bool Remove(count int) []interface{} Get(count int) []interface{} Size() int }
Queue represents a queue
func NewInMemoryQueue ¶
NewInMemoryQueue returns new InMemoryQueue with given queueSize
func NewInMemoryQueueWithLogger ¶
func NewInMemoryQueueWithLogger(queueSize int, logger logging.OptimizelyLogProducer) Queue
NewInMemoryQueueWithLogger returns new InMemoryQueue with given queueSize and logger
type QueueEventDispatcher ¶
type QueueEventDispatcher struct { Dispatcher Dispatcher // contains filtered or unexported fields }
QueueEventDispatcher is a queued version of the event Dispatcher that queues, returns success, and dispatches events in the background
func NewQueueEventDispatcher ¶
func NewQueueEventDispatcher(sdkKey string, metricsRegistry metrics.Registry) *QueueEventDispatcher
NewQueueEventDispatcher creates a Dispatcher that queues in memory and then sends via go routine.
func (*QueueEventDispatcher) DispatchEvent ¶
func (ed *QueueEventDispatcher) DispatchEvent(event LogEvent) (bool, error)
DispatchEvent queues event with callback and calls flush in a go routine.
type Snapshot ¶
type Snapshot struct { Decisions []Decision `json:"decisions,omitempty"` Events []SnapshotEvent `json:"events"` }
Snapshot represents a snapshot of a visitor
type SnapshotEvent ¶
type SnapshotEvent struct { EntityID string `json:"entity_id"` Key string `json:"key"` Timestamp int64 `json:"timestamp"` UUID string `json:"uuid"` Tags map[string]interface{} `json:"tags,omitempty"` Revenue *int64 `json:"revenue,omitempty"` Value *float64 `json:"value,omitempty"` }
SnapshotEvent represents an event of a snapshot
type UserEvent ¶
type UserEvent struct { Timestamp int64 `json:"timestamp"` UUID string `json:"uuid"` EventContext Context VisitorID string Impression *ImpressionEvent Conversion *ConversionEvent }
UserEvent represents a user event
func CreateConversionUserEvent ¶
func CreateConversionUserEvent(projectConfig config.ProjectConfig, event entities.Event, userContext entities.UserContext, eventTags map[string]interface{}) UserEvent
CreateConversionUserEvent creates and returns ConversionEvent for user
func CreateImpressionUserEvent ¶
func CreateImpressionUserEvent(projectConfig config.ProjectConfig, experiment entities.Experiment, variation *entities.Variation, userContext entities.UserContext, flagKey, ruleKey, ruleType string, enabled bool) (UserEvent, bool)
CreateImpressionUserEvent creates and returns ImpressionEvent for user
type Visitor ¶
type Visitor struct { Attributes []VisitorAttribute `json:"attributes"` Snapshots []Snapshot `json:"snapshots"` VisitorID string `json:"visitor_id"` }
Visitor represents a visitor of an eventbatch
type VisitorAttribute ¶
type VisitorAttribute struct { Value interface{} `json:"value"` Key string `json:"key"` AttributeType string `json:"type"` EntityID string `json:"entity_id"` }
VisitorAttribute represents an attribute of a visitor