event

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 19 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 DefaultEventEndPoint = "https://logx.optimizely.com/v1/events"

DefaultEventEndPoint is used as the default endpoint for sending events.

View Source
const DefaultEventFlushInterval = 30 * time.Second

DefaultEventFlushInterval holds the default value for the event flush interval

View Source
const DefaultEventQueueSize = 2000

DefaultEventQueueSize holds the default value for the event queue size

Variables

View Source
var ClientName = "go-sdk"

ClientName is the name of the client

View Source
var Version = "1.8.4"

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

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

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

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

Dispatcher dispatches events

func NewHTTPEventDispatcher added in v1.1.3

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) Add

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

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

func (*InMemoryQueue) Size

func (q *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) 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

func NewInMemoryQueue(queueSize int) Queue

NewInMemoryQueue returns new InMemoryQueue with given queueSize

func NewInMemoryQueueWithLogger added in v1.3.0

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

Jump to

Keyboard shortcuts

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