@@ -25,7 +25,6 @@ type SumoBuffer struct {
2525 logStringToSend * bytes.Buffer
2626 logEventsInCurrentBuffer int
2727 timerIdlebuffer time.Time
28- channelMessage chan string
2928}
3029
3130func NewSumoLogicAppender (urlValue string , connectionTimeoutValue int , nozzleQueue * eventQueue.Queue , eventsBatchSize int , sumoPostMinimumDelay time.Duration ) * SumoLogicAppender {
@@ -43,7 +42,6 @@ func newBuffer() SumoBuffer {
4342 return SumoBuffer {
4443 logStringToSend : bytes .NewBufferString ("" ),
4544 logEventsInCurrentBuffer : 0 ,
46- channelMessage : make (chan string ),
4745 }
4846}
4947
@@ -54,29 +52,37 @@ func (s *SumoLogicAppender) Start() {
5452 Buffer .timerIdlebuffer = time .Now ()
5553 logging .Info .Println ("Starting Appender Worker" )
5654 for {
57- for s .nozzleQueue .GetCount () == 0 {
55+ logging .Info .Println ("Log queue size: " )
56+ logging .Info .Println (s .nozzleQueue .GetCount ())
57+ if s .nozzleQueue .GetCount () == 0 {
58+ logging .Trace .Println ("Waiting for 300 ms" )
5859 time .Sleep (300 * time .Millisecond )
5960 }
6061
6162 if time .Since (Buffer .timerIdlebuffer ).Seconds () >= 10 && Buffer .logEventsInCurrentBuffer > 0 {
6263 logging .Info .Println ("Sending current batch of logs after timer exceeded limit" )
6364 go s .SendToSumo (& Buffer )
64- <- Buffer .channelMessage
6565 Buffer = newBuffer ()
66+ Buffer .timerIdlebuffer = time .Now ()
67+ continue
6668 }
67- for s .nozzleQueue .GetCount () != 0 {
68- if s .nozzleQueue .GetCount () >= s .eventsBatchSize - Buffer .logEventsInCurrentBuffer {
69- for Buffer .logEventsInCurrentBuffer < s .eventsBatchSize {
69+
70+ if s .nozzleQueue .GetCount () != 0 {
71+ queueCount := s .nozzleQueue .GetCount ()
72+ remainingBufferCount := s .eventsBatchSize - Buffer .logEventsInCurrentBuffer
73+ if queueCount >= remainingBufferCount {
74+ logging .Trace .Println ("Pushing Logs to Sumo: " )
75+ logging .Trace .Println (remainingBufferCount )
76+ for i := 0 ; i < remainingBufferCount ; i ++ {
7077 s .AppendLogs (& Buffer )
7178 Buffer .timerIdlebuffer = time .Now ()
7279 }
73- logging .Trace .Println ("Batch Size complete" )
7480 go s .SendToSumo (& Buffer )
75- <- Buffer .channelMessage
7681 Buffer = newBuffer ()
7782 } 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
83+ logging .Trace .Println ("Pushing Logs to Buffer: " )
84+ logging .Trace .Println (queueCount )
85+ for i := 0 ; i < queueCount ; i ++ {
8086 s .AppendLogs (& Buffer )
8187 Buffer .timerIdlebuffer = time .Now ()
8288 }
@@ -107,15 +113,12 @@ func (s *SumoLogicAppender) AppendLogs(buffer *SumoBuffer) {
107113}
108114
109115func (s * SumoLogicAppender ) SendToSumo (buffer * SumoBuffer ) {
110- //wait period between posts to Sumo
111116 for time .Since (s .timerBetweenPost ) < s .sumoPostMinimumDelay {
112- time .Sleep (100 * time .Millisecond ) // wait to retry
117+ logging .Trace .Println ("Delaying post to honor minimum post delay" )
118+ time .Sleep (100 * time .Millisecond )
113119 }
114- /*fmt.Println(buffer.logStringToSend.String())
115- fmt.Println("........")*/
116- buffer .channelMessage <- "Buffer being sent"
117120
118- logging .Trace .Println ("Sending logs to Sumologic..." )
121+ logging .Info .Println ("Sending logs to Sumologic..." )
119122 request , err := http .NewRequest ("POST" , s .url , buffer .logStringToSend )
120123 if err != nil {
121124 logging .Error .Printf ("http.NewRequest() error: %v\n " , err )
@@ -128,8 +131,8 @@ func (s *SumoLogicAppender) SendToSumo(buffer *SumoBuffer) {
128131 logging .Error .Printf ("http.Do() error: %v\n " , err )
129132 return
130133 } else {
131- logging .Trace .Println ("Do(Request) successful" )
132- s .timerBetweenPost = time .Now () //reset timer post minimum
134+ logging .Trace .Println ("Post of logs successful" )
135+ s .timerBetweenPost = time .Now ()
133136 }
134137
135138 defer response .Body .Close ()
0 commit comments