diff --git a/pkg/middlewares/canary/canary.go b/pkg/middlewares/canary/canary.go index 0f2a9d9e2e..20cc70c1dc 100644 --- a/pkg/middlewares/canary/canary.go +++ b/pkg/middlewares/canary/canary.go @@ -82,15 +82,6 @@ func (c *Canary) GetTracingInformation() (string, ext.SpanKindEnum) { func (c *Canary) ServeHTTP(rw http.ResponseWriter, req *http.Request) { c.processRequestID(rw, req) c.processCanary(rw, req) - - if logData := accesslog.GetLogData(req); logData != nil { - if requestID := req.Header.Get(headerXRequestID); requestID != "" { - logData.Core["XRequestID"] = requestID - } - if xCanary := req.Header.Values(headerXCanary); len(xCanary) > 0 { - logData.Core["XCanary"] = xCanary - } - } c.next.ServeHTTP(rw, req) } @@ -102,6 +93,10 @@ func (c *Canary) processRequestID(rw http.ResponseWriter, req *http.Request) { req.Header.Set(headerXRequestID, requestID) } rw.Header().Set(headerXRequestID, requestID) + + if logData := accesslog.GetLogData(req); logData != nil { + logData.Core["XRequestID"] = requestID + } } } @@ -135,6 +130,15 @@ func (c *Canary) processCanary(rw http.ResponseWriter, req *http.Request) { if c.canaryResponseHeader { info.intoHeader(rw.Header()) } + + if logData := accesslog.GetLogData(req); logData != nil { + if info.uid != "" { + logData.Core["UID"] = info.uid + } + if xCanary := req.Header.Values(headerXCanary); len(xCanary) > 0 { + logData.Core["XCanary"] = xCanary + } + } } type userInfo struct { diff --git a/pkg/middlewares/canary/request.go b/pkg/middlewares/canary/request.go index f4f564176d..2b660a9d99 100644 --- a/pkg/middlewares/canary/request.go +++ b/pkg/middlewares/canary/request.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + "net" "net/http" "os" "runtime" @@ -29,13 +30,22 @@ func init() { var userAgent string var tr = &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - ForceAttemptHTTP2: true, + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + DialContext: (&net.Dialer{ + Timeout: 3 * time.Second, + KeepAlive: 30 * time.Second, + }).DialContext, + ForceAttemptHTTP2: true, + MaxIdleConns: 100, + MaxIdleConnsPerHost: 20, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 3 * time.Second, + ExpectContinueTimeout: 1 * time.Second, } var client = &http.Client{ Transport: tr, - Timeout: time.Second, + Timeout: time.Second * 3, } type labelsRes struct {