Documentation
¶
Overview ¶
Package event //
Package event //
Package event //
Package event //
Package event //
Package event //
Index ¶
- Constants
- type BPOptionConfig
- type Batch
- type BatchEventProcessor
- func (p *BatchEventProcessor) EventsCount() int
- func (p *BatchEventProcessor) FlushEvents()
- func (p *BatchEventProcessor) GetEvents(count int) []interface{}
- func (p *BatchEventProcessor) OnEventDispatch(callback func(logEvent LogEvent)) (int, error)
- func (p *BatchEventProcessor) ProcessEvent(event UserEvent)
- func (p *BatchEventProcessor) Remove(count int) []interface{}
- func (p *BatchEventProcessor) RemoveOnEventDispatch(id int) error
- func (p *BatchEventProcessor) Start(exeCtx utils.ExecutionCtx)
- type ChanQueue
- type Context
- type ConversionEvent
- type Decision
- type Dispatcher
- type HTTPEventDispatcher
- type ImpressionEvent
- type InMemoryQueue
- type LogEvent
- type Processor
- type Queue
- type QueueEventDispatcher
- type Snapshot
- type SnapshotEvent
- type UserEvent
- type Visitor
- type VisitorAttribute
Constants ¶
const DefaultBatchSize = 10
DefaultBatchSize holds the default value for the batch size
const DefaultEventFlushInterval = 30 * time.Second
DefaultEventFlushInterval holds the default value for the event flush interval
const DefaultEventQueueSize = 100
DefaultEventQueueSize holds the default value for the event queue size
Variables ¶
This section is empty.
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 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
Q Queue
Mux sync.Mutex
Ticker *time.Ticker
EventDispatcher Dispatcher
// contains filtered or unexported fields
}
BatchEventProcessor is used out of the box by the SDK
func NewBatchEventProcessor ¶
func NewBatchEventProcessor(options ...BPOptionConfig) *BatchEventProcessor
NewBatchEventProcessor returns a new instance of BatchEventProcessor with queueSize and flushInterval
func (*BatchEventProcessor) EventsCount ¶
func (p *BatchEventProcessor) EventsCount() int
EventsCount returns size of an event queue
func (*BatchEventProcessor) FlushEvents ¶
func (p *BatchEventProcessor) FlushEvents()
FlushEvents flushes events in queue
func (*BatchEventProcessor) GetEvents ¶
func (p *BatchEventProcessor) GetEvents(count int) []interface{}
GetEvents returns events from event queue for count
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)
ProcessEvent processes the given impression event
func (*BatchEventProcessor) Remove ¶
func (p *BatchEventProcessor) Remove(count int) []interface{}
Remove removes events from queue for count
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(exeCtx utils.ExecutionCtx)
Start initializes the event processor
type ChanQueue ¶
type ChanQueue struct {
// contains filtered or unexported fields
}
ChanQueue is a go channel based queue that takes things from the channel and puts them in a in memory queue
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 pkg.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"`
}
Decision represents a decision of a snapshot
type Dispatcher ¶
Dispatcher dispatches events
func NewQueueEventDispatcher ¶
func NewQueueEventDispatcher(ctx context.Context) Dispatcher
NewQueueEventDispatcher creates a Dispatcher that queues in memory and then sends via go routine.
type HTTPEventDispatcher ¶
type HTTPEventDispatcher struct {
}
HTTPEventDispatcher is the HTTP implementation of the Dispatcher interface
func (*HTTPEventDispatcher) DispatchEvent ¶
func (*HTTPEventDispatcher) DispatchEvent(event LogEvent) (bool, error)
DispatchEvent dispatches event with callback
type ImpressionEvent ¶
type ImpressionEvent struct {
EntityID string `json:"entity_id"`
Key string `json:"key"`
Attributes []VisitorAttribute
VariationID string `json:"variation_id"`
CampaignID string `json:"campaign_id"`
ExperimentID string `json:"experiment_id"`
}
ImpressionEvent represents an impression event
type InMemoryQueue ¶
InMemoryQueue represents a in-memory queue
func (*InMemoryQueue) Get ¶
func (i *InMemoryQueue) Get(count int) []interface{}
Get returns queue for given count size
func (*InMemoryQueue) Remove ¶
func (i *InMemoryQueue) Remove(count int) []interface{}
Remove removes item from queue and returns elements slice
type Processor ¶
type Processor interface {
ProcessEvent(event UserEvent)
}
Processor processes events
type Queue ¶
type Queue interface {
Add(item interface{})
Remove(count int) []interface{}
Get(count int) []interface{}
Size() int
}
Queue represents a queue
func NewChanQueue ¶
NewChanQueue returns new go channel based queue with given in memory queueSize
func NewInMemoryQueue ¶
NewInMemoryQueue returns new InMemoryQueue with given queueSize
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 (*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"`
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 pkg.ProjectConfig, event entities.Event, userContext entities.UserContext, eventTags map[string]interface{}) UserEvent
CreateConversionUserEvent creates and returns ConversionEvent for user
func CreateImpressionUserEvent ¶
func CreateImpressionUserEvent(projectConfig pkg.ProjectConfig, experiment entities.Experiment, variation entities.Variation, userContext entities.UserContext) UserEvent
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