Skip to content

Commit cf44262

Browse files
committed
SCFF-50 checking the timer just before do the post to sumo
1 parent a53618c commit cf44262

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

sumoCFFirehose/sumoLogicAppender.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"compress/gzip"
66
"errors"
7+
"fmt"
78
"net/http"
89
"runtime"
910
"time"
@@ -195,10 +196,6 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string /*, wg *sync.WaitG
195196
g := gzip.NewWriter(&buf)
196197
g.Write([]byte(logStringToSend))
197198
g.Close()
198-
for time.Since(s.timerBetweenPost) < s.sumoPostMinimumDelay {
199-
logging.Info. /*Trace*/ Println("Delaying post to honor minimum post delay")
200-
time.Sleep(100 * time.Millisecond)
201-
}
202199
request, err := http.NewRequest("POST", s.url, &buf)
203200
if err != nil {
204201
logging.Error.Printf("http.NewRequest() error: %v\n", err)
@@ -216,7 +213,12 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string /*, wg *sync.WaitG
216213
if s.sumoCategory != "" {
217214
request.Header.Add("X-Sumo-Category", s.sumoCategory)
218215
}
219-
216+
fmt.Println(time.Since(s.timerBetweenPost))
217+
//checking the timer before first POST intent
218+
for time.Since(s.timerBetweenPost) < s.sumoPostMinimumDelay {
219+
logging.Info. /*Trace.*/ Println("Delaying post to honor minimum post delay")
220+
time.Sleep(100 * time.Millisecond)
221+
}
220222
response, err := s.httpClient.Do(request)
221223

222224
if (err != nil) || (response.StatusCode != 200 && response.StatusCode != 302 && response.StatusCode < 500) {
@@ -226,7 +228,6 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string /*, wg *sync.WaitG
226228
statusCode := 0
227229
err := Retry(func(attempt int) (bool, error) {
228230
var errRetry error
229-
//create again request
230231
request, err := http.NewRequest("POST", s.url, &buf)
231232
if err != nil {
232233
logging.Error.Printf("http.NewRequest() error: %v\n", err)
@@ -242,6 +243,12 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string /*, wg *sync.WaitG
242243
if s.sumoCategory != "" {
243244
request.Header.Add("X-Sumo-Category", s.sumoCategory)
244245
}
246+
fmt.Println(time.Since(s.timerBetweenPost))
247+
//checking the timer before POST (retry intent)
248+
for time.Since(s.timerBetweenPost) < s.sumoPostMinimumDelay {
249+
logging.Info. /*Trace.*/ Println("Delaying post to honor minimum post delay (retry intent)")
250+
time.Sleep(100 * time.Millisecond)
251+
}
245252
response, errRetry = s.httpClient.Do(request)
246253
if errRetry != nil {
247254
logging.Error.Printf("http.Do() error: %v\n", errRetry)
@@ -255,7 +262,7 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string /*, wg *sync.WaitG
255262
time.Sleep(300 * time.Millisecond)
256263
return attempt < 5, errRetry
257264
} else if response.StatusCode == 200 {
258-
logging.Trace.Println("Post of logs successful after retry...")
265+
logging.Info. /*Trace.*/ Println("Post of logs successful after retry...")
259266
s.timerBetweenPost = time.Now()
260267
statusCode = response.StatusCode
261268
return true, err
@@ -270,7 +277,7 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string /*, wg *sync.WaitG
270277
logging.Error.Printf("Not able to post after retry, with status code: %d", statusCode)
271278
}
272279
} else if response.StatusCode == 200 {
273-
logging.Trace.Println("Post of logs successful")
280+
logging.Info. /*Trace.*/ Println("Post of logs successful")
274281
s.timerBetweenPost = time.Now()
275282
}
276283

0 commit comments

Comments
 (0)