Skip to content

Commit ee1abf8

Browse files
committed
SCFF-35 changed the forever loop from the start method
1 parent 78b2c8d commit ee1abf8

1 file changed

Lines changed: 30 additions & 24 deletions

File tree

sumoCFFirehose/sumoLogicAppender.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sumoCFFirehose
22

33
import (
44
"bytes"
5-
"fmt"
65
"net/http"
76
"runtime"
87
"time"
@@ -52,36 +51,37 @@ func (s *SumoLogicAppender) Start() {
5251
s.timerBetweenPost = time.Now()
5352
runtime.GOMAXPROCS(1)
5453
Buffer := newBuffer()
55-
fmt.Printf("First Buffer Reference: %v \n", &Buffer)
5654
Buffer.timerIdlebuffer = time.Now()
57-
msgFromChannel := ""
5855
logging.Info.Println("Starting Appender Worker")
5956
for {
60-
time.Sleep(300 * time.Millisecond)
61-
if Buffer.logEventsInCurrentBuffer >= s.eventsBatchSize || msgFromChannel == "Buffer being sent" {
62-
Buffer = newBuffer()
57+
for s.nozzleQueue.GetCount() == 0 {
58+
time.Sleep(300 * time.Millisecond)
6359
}
6460

65-
for s.nozzleQueue.GetCount() != 0 && Buffer.logEventsInCurrentBuffer < s.eventsBatchSize {
66-
s.AppendLogs(&Buffer)
67-
time.Sleep(300 * time.Millisecond)
68-
Buffer.timerIdlebuffer = time.Now()
69-
if Buffer.logEventsInCurrentBuffer == s.eventsBatchSize {
70-
logging.Info.Println("Batch Size complete")
71-
break
72-
} else if time.Since(Buffer.timerIdlebuffer).Seconds() >= 10 {
73-
logging.Info.Println("Sending current batch of logs after timer exceeded limit")
74-
break
75-
}
61+
if time.Since(Buffer.timerIdlebuffer).Seconds() >= 10 && Buffer.logEventsInCurrentBuffer > 0 {
62+
logging.Info.Println("Sending current batch of logs after timer exceeded limit")
63+
go s.SendToSumo(&Buffer)
64+
<-Buffer.channelMessage
65+
Buffer = newBuffer()
7666
}
77-
//wait period between posts to Sumo
78-
for time.Since(s.timerBetweenPost) < s.sumoPostMinimumDelay {
79-
time.Sleep(30 * time.Millisecond) // wait to retry
67+
for s.nozzleQueue.GetCount() != 0 {
68+
if s.nozzleQueue.GetCount() >= s.eventsBatchSize-Buffer.logEventsInCurrentBuffer {
69+
for Buffer.logEventsInCurrentBuffer < s.eventsBatchSize {
70+
s.AppendLogs(&Buffer)
71+
Buffer.timerIdlebuffer = time.Now()
72+
}
73+
logging.Trace.Println("Batch Size complete")
74+
go s.SendToSumo(&Buffer)
75+
<-Buffer.channelMessage
76+
Buffer = newBuffer()
77+
} else {
78+
for s.nozzleQueue.GetCount() > 0 && Buffer.logEventsInCurrentBuffer < s.eventsBatchSize {
79+
//TODO fill the buffer with whatever is in the queue without sending to sumo
80+
s.AppendLogs(&Buffer)
81+
Buffer.timerIdlebuffer = time.Now()
82+
}
83+
}
8084
}
81-
go s.SendToSumo(&Buffer)
82-
msgFromChannel = <-Buffer.channelMessage
83-
84-
Buffer.timerIdlebuffer = time.Now() //reset Buffer timer
8585
}
8686

8787
}
@@ -107,6 +107,12 @@ func (s *SumoLogicAppender) AppendLogs(buffer *SumoBuffer) {
107107
}
108108

109109
func (s *SumoLogicAppender) SendToSumo(buffer *SumoBuffer) {
110+
//wait period between posts to Sumo
111+
for time.Since(s.timerBetweenPost) < s.sumoPostMinimumDelay {
112+
time.Sleep(100 * time.Millisecond) // wait to retry
113+
}
114+
/*fmt.Println(buffer.logStringToSend.String())
115+
fmt.Println("........")*/
110116
buffer.channelMessage <- "Buffer being sent"
111117

112118
logging.Trace.Println("Sending logs to Sumologic...")

0 commit comments

Comments
 (0)