1
0
Fork 0

Move origin fields capture to service level

Co-authored-by: lbenguigui <lbenguigui@gmail.com>
This commit is contained in:
Romain 2023-09-27 15:22:06 +02:00 committed by GitHub
parent b786f58f80
commit b966215e6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 121 additions and 17 deletions

View file

@ -46,11 +46,6 @@ func AddServiceFields(rw http.ResponseWriter, req *http.Request, next http.Handl
data.Core[ServiceURL] = req.URL // note that this is *not* the original incoming URL
data.Core[ServiceAddr] = req.URL.Host
next.ServeHTTP(rw, req)
}
// AddOriginFields add origin fields.
func AddOriginFields(rw http.ResponseWriter, req *http.Request, next http.Handler, data *LogData) {
start := time.Now().UTC()
next.ServeHTTP(rw, req)
@ -72,3 +67,14 @@ func AddOriginFields(rw http.ResponseWriter, req *http.Request, next http.Handle
data.Core[OriginStatus] = capt.StatusCode()
data.Core[OriginContentSize] = capt.ResponseSize()
}
// InitServiceFields init service fields.
func InitServiceFields(rw http.ResponseWriter, req *http.Request, next http.Handler, data *LogData) {
// Because they are expected to be initialized when the logger is processing the data table,
// the origin fields are initialized in case the response is returned by Traefik itself, and not a service.
data.Core[OriginDuration] = time.Duration(0)
data.Core[OriginStatus] = 0
data.Core[OriginContentSize] = int64(0)
next.ServeHTTP(rw, req)
}