@@ -125,7 +125,6 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string) {
125125 time .Sleep (100 * time .Millisecond )
126126 }
127127
128- //logging.Info.Println("Sending logs to Sumo Logic...")
129128 request , err := http .NewRequest ("POST" , s .url , & buf )
130129 if err != nil {
131130 logging .Error .Printf ("http.NewRequest() error: %v\n " , err )
@@ -138,27 +137,35 @@ func (s *SumoLogicAppender) SendToSumo(logStringToSend string) {
138137 if err != nil {
139138 logging .Error .Printf ("http.Do() error: %v\n " , err )
140139 return
141- } else if response .StatusCode == 429 { //that the endpoint needs some time and dropped the post sent
142- logging .Trace .Println ("Endpoint dropped the post send" )
143- logging .Trace .Println ("Waiting for 300 ms to retry" )
140+ } else if response .StatusCode != 200 && response . StatusCode != 302 && response . StatusCode < 500 {
141+ logging .Info .Println ("Endpoint dropped the post send" )
142+ logging .Info .Println ("Waiting for 300 ms to retry" )
144143 time .Sleep (300 * time .Millisecond )
145144 responseRetry , errRetry := s .httpClient .Do (request )
146- for responseRetry .StatusCode == 429 {
147- logging .Trace .Println ("Waiting for 300 ms to retry" )
148- time .Sleep (300 * time .Millisecond )
149- responseRetry , errRetry = s .httpClient .Do (request )
150- }
151145 if errRetry != nil {
152- logging .Error .Printf ("http.Do() error: %v\n " , err )
146+ logging .Error .Printf ("http.Do() error: %v\n " , errRetry )
153147 return
154148 } else {
155- logging .Trace .Println ("Post of logs successful" )
156-
157- s .timerBetweenPost = time .Now ()
149+ maxAttempts := 5
150+ for i := 0 ; i <= maxAttempts ; i ++ {
151+ if responseRetry .StatusCode != 200 && response .StatusCode != 302 && response .StatusCode < 500 {
152+ logging .Info .Println ("Waiting for 300 ms to retry..." )
153+ time .Sleep (300 * time .Millisecond )
154+ responseRetry , errRetry = s .httpClient .Do (request )
155+ if errRetry != nil {
156+ logging .Error .Printf ("http.Do() error: %v\n " , errRetry )
157+ return
158+ } else {
159+ logging .Info .Println ("Post of logs successful (after retry)" )
160+ }
161+ }
162+ s .timerBetweenPost = time .Now ()
163+ }
164+ logging .Info . /*Trace*/ Println ("Not possible to send the logs after the maximum number of possible attempts" )
158165 }
159166
160- } else {
161- logging .Trace . Println ("Post of logs successful" )
167+ } else if response . StatusCode == 200 {
168+ logging .Info . /*Trace*/ Println ("Post of logs successful" )
162169 s .timerBetweenPost = time .Now ()
163170 }
164171
0 commit comments