Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Shushlin <v.shushlin@gmail.com>2022-01-28 15:47:48 +0300
committerVladimir Shushlin <v.shushlin@gmail.com>2022-01-31 16:37:22 +0300
commitadc0b9233fa4a0b2b449e27336d9ae39c75819ba (patch)
tree3c21a4379bfdbcc459b27742f4dbf97122aacfc8 /internal/logging/logging.go
parent008e2afc8d6de32a30696dbf813ebc0fdf5192c7 (diff)
fix: fix metrics and logs not including domain resolution time
Currently we do logging and metrics capturing after we did the domain information lookup. It allows us to add more information to access logs. But it also distorts metrics because domain information lookup takes time. This logic was originally introduced in https://gitlab.com/gitlab-org/gitlab-pages/-/merge_requests/157/diffs It didn't matter back than because we didn't lookup domain via API as we do now. Now it does matter. So this commits moves metrics and logging middlewares almost to the top of pipeline. Changelog: fixed
Diffstat (limited to 'internal/logging/logging.go')
-rw-r--r--internal/logging/logging.go24
1 files changed, 7 insertions, 17 deletions
diff --git a/internal/logging/logging.go b/internal/logging/logging.go
index edc670d6..6e8533d8 100644
--- a/internal/logging/logging.go
+++ b/internal/logging/logging.go
@@ -52,34 +52,24 @@ func getAccessLogger(format string) (*logrus.Logger, error) {
}
// BasicAccessLogger configures the GitLab pages basic HTTP access logger middleware
-func BasicAccessLogger(handler http.Handler, format string, extraFields log.ExtraFieldsGeneratorFunc) (http.Handler, error) {
+func BasicAccessLogger(handler http.Handler, format string) (http.Handler, error) {
accessLogger, err := getAccessLogger(format)
if err != nil {
return nil, err
}
return log.AccessLogger(handler,
- log.WithExtraFields(enrichExtraFields(extraFields)),
+ log.WithExtraFields(extraFields),
log.WithAccessLogger(accessLogger),
log.WithXFFAllowed(func(sip string) bool { return false }),
), nil
}
-func enrichExtraFields(extraFields log.ExtraFieldsGeneratorFunc) log.ExtraFieldsGeneratorFunc {
- return func(r *http.Request) log.Fields {
- enrichedFields := log.Fields{
- "correlation_id": correlation.ExtractFromContext(r.Context()),
- "pages_https": request.IsHTTPS(r),
- "pages_host": r.Host,
- }
-
- if extraFields != nil {
- for field, value := range extraFields(r) {
- enrichedFields[field] = value
- }
- }
-
- return enrichedFields
+func extraFields(r *http.Request) log.Fields {
+ return log.Fields{
+ "correlation_id": correlation.ExtractFromContext(r.Context()),
+ "pages_https": request.IsHTTPS(r),
+ "pages_host": r.Host,
}
}