event

package
v1.0.0-beta7 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Overview

Package event //

Package event //

Package event //

Package event //

Package event //

Package event //

Index

Constants

View Source
const DefaultBatchSize = 10

DefaultBatchSize holds the default value for the batch size

View Source
const DefaultEventFlushInterval = 30 * time.Second

DefaultEventFlushInterval holds the default value for the event flush interval

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

	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

func (*ChanQueue) Add

func (i *ChanQueue) Add(item interface{})

Add appends item to queue

func (*ChanQueue) Get

func (i *ChanQueue) Get(count int) []interface{}

Get returns queue for given count size

func (*ChanQueue) Remove

func (i *ChanQueue) Remove(count int) []interface{}

Remove removes item from queue and returns elements slice

func (*ChanQueue) Size

func (i *ChanQueue) Size() int

Size returns size of 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

type Dispatcher interface {
	DispatchEvent(event LogEvent) (bool, error)
}

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

type InMemoryQueue struct {
	Queue []interface{}
	Mux   sync.Mutex
}

InMemoryQueue represents a in-memory queue

func (*InMemoryQueue) Add

func (i *InMemoryQueue) Add(item interface{})

Add appends item to 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

func (*InMemoryQueue) Size

func (i *InMemoryQueue) Size() int

Size returns size of queue

type LogEvent

type LogEvent struct {
	EndPoint string
	Event    Batch
}

LogEvent represents a log event

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

func NewChanQueue(queueSize int) Queue

NewChanQueue returns new go channel based queue with given in memory queueSize

func NewInMemoryQueue

func NewInMemoryQueue(queueSize int) Queue

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

Jump to

Keyboard shortcuts

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