Skip to content

Commit 8bcda51

Browse files
committed
SCFF-31 start method for the appender
1 parent 3660364 commit 8bcda51

1 file changed

Lines changed: 35 additions & 22 deletions

File tree

sumoCFFirehose/sumoLogicAppender.go

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@ import (
1111
)
1212

1313
type SumoLogicAppender struct {
14-
url string
15-
connectionTimeout int //10000
16-
httpClient http.Client
17-
nozzleQueue eventQueue.Queue
18-
eventsBatchSize int
14+
url string
15+
connectionTimeout int //10000
16+
httpClient http.Client
17+
nozzleQueue eventQueue.Queue
18+
eventsBatchSize int
19+
logEventsInCurrentBuffer int
20+
logStringToSend string
1921
}
2022

2123
func NewSumoLogicAppender(urlValue string, connectionTimeoutValue int, nozzleQueue eventQueue.Queue, eventsBatchSize int) *SumoLogicAppender {
2224
return &SumoLogicAppender{
23-
url: urlValue,
24-
connectionTimeout: connectionTimeoutValue,
25-
httpClient: http.Client{Timeout: time.Duration(connectionTimeoutValue * int(time.Millisecond))},
26-
nozzleQueue: nozzleQueue,
27-
eventsBatchSize: eventsBatchSize,
25+
url: urlValue,
26+
connectionTimeout: connectionTimeoutValue,
27+
httpClient: http.Client{Timeout: time.Duration(connectionTimeoutValue * int(time.Millisecond))},
28+
nozzleQueue: nozzleQueue,
29+
eventsBatchSize: eventsBatchSize,
30+
logEventsInCurrentBuffer: 0,
31+
logStringToSend: "",
2832
}
2933
}
3034

@@ -46,7 +50,25 @@ func (s *SumoLogicAppender) Connect() bool {
4650
}
4751

4852
func (s *SumoLogicAppender) Start() {
49-
s.AppendLogs()
53+
timer := time.NewTimer(60 * time.Second)
54+
fmt.Println("Starting Appender Worker")
55+
s.logStringToSend = ""
56+
for {
57+
time.Sleep(300 * time.Millisecond)
58+
if s.nozzleQueue.GetCount() > 0 {
59+
s.AppendLogs()
60+
}
61+
if s.eventsBatchSize >= s.logEventsInCurrentBuffer {
62+
s.SendToSumo(s.logStringToSend)
63+
s.logEventsInCurrentBuffer = 0 // reset counter
64+
s.logStringToSend = "" //reset String
65+
} else if (<-timer.C).Second() == 0 {
66+
s.SendToSumo(s.logStringToSend)
67+
s.logEventsInCurrentBuffer = 0 // reset counter
68+
s.logStringToSend = "" //reset String
69+
}
70+
71+
}
5072
}
5173

5274
func StringBuilder(node *eventQueue.Node) string {
@@ -66,17 +88,8 @@ func StringBuilder(node *eventQueue.Node) string {
6688
func (s *SumoLogicAppender) AppendLogs() {
6789
// the appender calls for the next message in the queue and parse it to a string
6890
//timer := time.NewTimer(60 * time.Second)
69-
logMessage := ""
70-
stringBuilderCalls := 0
71-
for s.nozzleQueue.GetCount() > s.eventsBatchSize { //when the batch limit is met, call stringBuilder
72-
logMessage = logMessage + StringBuilder(s.nozzleQueue.Pop())
73-
stringBuilderCalls++
74-
if s.eventsBatchSize == stringBuilderCalls {
75-
s.SendToSumo(logMessage)
76-
stringBuilderCalls = 0
77-
logMessage = ""
78-
}
79-
}
91+
s.logStringToSend = s.logStringToSend + StringBuilder(s.nozzleQueue.Pop())
92+
s.logEventsInCurrentBuffer++
8093

8194
}
8295

0 commit comments

Comments
 (0)