Skip to content

Commit

Permalink
feat: retry on request timeout (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
snakorse authored Mar 20, 2023
1 parent 8bc931f commit e0c5ec4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions plugins/flusher/http/flusher_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io/ioutil"
"math/big"
"net/http"
"net/url"
"sync"
"time"

Expand Down Expand Up @@ -281,10 +282,17 @@ func (f *FlusherHTTP) flush(data []byte, varValues map[string]string) (ok, retry
req.Header.Add(k, v)
}
response, err := f.client.Do(req)
logger.Debugf(f.context.GetRuntimeContext(), "request [method]: %v; [header]: %v; [url]: %v; [body]: %v", req.Method, req.Header, req.URL, string(data))
if logger.DebugFlag() {
logger.Debugf(f.context.GetRuntimeContext(), "request [method]: %v; [header]: %v; [url]: %v; [body]: %v", req.Method, req.Header, req.URL, string(data))
}
if err != nil {
urlErr, ok := err.(*url.Error)
retry := false
if ok && (urlErr.Timeout() || urlErr.Temporary()) {
retry = true
}
logger.Error(f.context.GetRuntimeContext(), "FLUSHER_FLUSH_ALRAM", "http flusher send request fail, error", err)
return false, false, err
return false, retry, err
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
Expand Down

0 comments on commit e0c5ec4

Please sign in to comment.