Skip to content

Commit ef17eaf

Browse files
authored
feat(event-dispatcher): Exposing logx URL for agent. (#268)
1 parent 5fed301 commit ef17eaf

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

pkg/event/dispatcher_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2019, Optimizely, Inc. and contributors *
2+
* Copyright 2019-2020, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -106,7 +106,7 @@ func TestQueueEventDispatcher_DispatchEvent(t *testing.T) {
106106
q := NewQueueEventDispatcher("", metricsRegistry)
107107

108108
assert.True(t, q.Dispatcher != nil)
109-
if d,ok := q.Dispatcher.(*httpEventDispatcher); ok {
109+
if d, ok := q.Dispatcher.(*httpEventDispatcher); ok {
110110
assert.True(t, d.requester != nil && d.logger != nil)
111111
} else {
112112
assert.True(t, false)
@@ -121,7 +121,7 @@ func TestQueueEventDispatcher_DispatchEvent(t *testing.T) {
121121

122122
batch := createBatchEvent(conversionUserEvent, createVisitorFromUserEvent(conversionUserEvent))
123123

124-
logEvent := createLogEvent(batch)
124+
logEvent := createLogEvent(batch, DefaultEventEndPoint)
125125

126126
success, _ := q.DispatchEvent(logEvent)
127127

@@ -179,7 +179,7 @@ func TestQueueEventDispatcher_FailDispath(t *testing.T) {
179179

180180
batch := createBatchEvent(conversionUserEvent, createVisitorFromUserEvent(conversionUserEvent))
181181

182-
logEvent := createLogEvent(batch)
182+
logEvent := createLogEvent(batch, DefaultEventEndPoint)
183183

184184
q.DispatchEvent(logEvent)
185185

pkg/event/factory.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2019, Optimizely, Inc. and contributors *
2+
* Copyright 2019-2020, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -32,11 +32,10 @@ const impressionKey string = "campaign_activated"
3232
const attributeType = "custom"
3333
const specialPrefix = "$opt_"
3434
const botFilteringKey = "$opt_bot_filtering"
35-
const eventEndPoint = "https://logx.optimizely.com/v1/events"
3635
const revenueKey = "revenue"
3736
const valueKey = "value"
3837

39-
func createLogEvent(event Batch) LogEvent {
38+
func createLogEvent(event Batch, eventEndPoint string) LogEvent {
4039
return LogEvent{EndPoint: eventEndPoint, Event: event}
4140
}
4241

pkg/event/processor.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2019, Optimizely, Inc. and contributors *
2+
* Copyright 2019-2020, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -46,6 +46,7 @@ type BatchEventProcessor struct {
4646
MaxQueueSize int // max size of the queue before flush
4747
FlushInterval time.Duration // in milliseconds
4848
BatchSize int
49+
EventEndPoint string
4950
Q Queue
5051
flushLock sync.Mutex
5152
Ticker *time.Ticker
@@ -64,6 +65,9 @@ const DefaultEventQueueSize = 2000
6465
// DefaultEventFlushInterval holds the default value for the event flush interval
6566
const DefaultEventFlushInterval = 30 * time.Second
6667

68+
// DefaultEventEndPoint is used as the default endpoint for sending events.
69+
const DefaultEventEndPoint = "https://logx.optimizely.com/v1/events"
70+
6771
const maxFlushWorkers = 1
6872

6973
// BPOptionConfig is the BatchProcessor options that give you the ability to add one more more options before the processor is initialized.
@@ -76,6 +80,13 @@ func WithBatchSize(bsize int) BPOptionConfig {
7680
}
7781
}
7882

83+
// WithEventEndPoint sets the end point as a config option to be passed into the NewProcessor method
84+
func WithEventEndPoint(endPoint string) BPOptionConfig {
85+
return func(qp *BatchEventProcessor) {
86+
qp.EventEndPoint = endPoint
87+
}
88+
}
89+
7990
// WithQueueSize sets the queue size as a config option to be passed into the NewProcessor method
8091
func WithQueueSize(qsize int) BPOptionConfig {
8192
return func(qp *BatchEventProcessor) {
@@ -141,6 +152,10 @@ func NewBatchEventProcessor(options ...BPOptionConfig) *BatchEventProcessor {
141152
p.BatchSize = DefaultBatchSize
142153
}
143154

155+
if p.EventEndPoint == "" {
156+
p.EventEndPoint = DefaultEventEndPoint
157+
}
158+
144159
if p.BatchSize > p.MaxQueueSize {
145160
p.logger.Warning(
146161
fmt.Sprintf("Batch size %d is larger than queue size %d. Setting to defaults",
@@ -297,7 +312,7 @@ func (p *BatchEventProcessor) flushEvents() {
297312
}
298313
if batchEventCount > 0 {
299314
// TODO: figure out what to do with the error
300-
logEvent := createLogEvent(batchEvent)
315+
logEvent := createLogEvent(batchEvent, p.EventEndPoint)
301316
notificationCenter := registry.GetNotificationCenter(p.sdkKey)
302317

303318
err := notificationCenter.Send(notification.LogEvent, logEvent)

pkg/event/processor_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2019, Optimizely, Inc. and contributors *
2+
* Copyright 2019-2020, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -102,6 +102,17 @@ func TestCustomEventProcessor_Create(t *testing.T) {
102102
assert.Equal(t, 0, processor.eventsCount())
103103
}
104104

105+
func TestEndPointOptionEventProcessor(t *testing.T) {
106+
// Default end point
107+
processor := NewBatchEventProcessor()
108+
assert.Equal(t, DefaultEventEndPoint, processor.EventEndPoint)
109+
110+
customEndPoint := "https://logx.optimizely.com"
111+
processor = NewBatchEventProcessor(
112+
WithEventEndPoint(customEndPoint))
113+
assert.Equal(t, customEndPoint, processor.EventEndPoint)
114+
}
115+
105116
func TestDefaultEventProcessor_LogEventNotification(t *testing.T) {
106117
eg := newExecutionContext()
107118
processor := NewBatchEventProcessor(

0 commit comments

Comments
 (0)