From 9c4d6471bfa66874e9ebe0f2ed16aef05572facc Mon Sep 17 00:00:00 2001 From: aymericDD Date: Mon, 25 Oct 2021 10:31:07 +0200 Subject: [PATCH] query-frontend+api: add context to start call log (#4769) Add "X-REQUEST-ID" to identify requests and link log related to the same request. Add "http.method" to know witch request is executed. Add "http.method_name" to know witch method is called. Signed-off-by: Aymeric Co-authored-by: Aymeric --- CHANGELOG.md | 1 + cmd/thanos/query_frontend.go | 7 ++++--- pkg/api/api.go | 6 +++--- pkg/logging/http.go | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e28c8a1242e..80036ed4be2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#4754](https://github.com/thanos-io/thanos/pull/4754) Query: Fix possible panic on stores endpoint. - [#4753](https://github.com/thanos-io/thanos/pull/4753) Store: validate block sync concurrency parameter - [#4792](https://github.com/thanos-io/thanos/pull/4792) Store: Fix data race in BucketedBytes pool. +- [#4769](https://github.com/thanos-io/thanos/pull/4769) Query-frontend+api: add "X-Request-ID" field and other fields to start call log. ## [v0.23.1](https://github.com/thanos-io/thanos/tree/release-0.23) - 2021.10.1 diff --git a/cmd/thanos/query_frontend.go b/cmd/thanos/query_frontend.go index 51fdabcb890..86069f2d9c0 100644 --- a/cmd/thanos/query_frontend.go +++ b/cmd/thanos/query_frontend.go @@ -284,9 +284,10 @@ func runQueryFrontend( logger, ins.NewHandler( name, - logMiddleware.HTTPMiddleware( - name, - gziphandler.GzipHandler(middleware.RequestID(f)), + gziphandler.GzipHandler( + middleware.RequestID( + logMiddleware.HTTPMiddleware(name, f), + ), ), ), // Cortex frontend middlewares require orgID. diff --git a/pkg/api/api.go b/pkg/api/api.go index 5e361ffc6fc..6a29775d83e 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -219,9 +219,9 @@ func GetInstr( return tracing.HTTPMiddleware(tracer, name, logger, ins.NewHandler(name, - logMiddleware.HTTPMiddleware(name, - gziphandler.GzipHandler( - middleware.RequestID(hf), + gziphandler.GzipHandler( + middleware.RequestID( + logMiddleware.HTTPMiddleware(name, hf), ), ), ), diff --git a/pkg/logging/http.go b/pkg/logging/http.go index 8fb12cdc4ae..6fc5b297866 100644 --- a/pkg/logging/http.go +++ b/pkg/logging/http.go @@ -22,9 +22,9 @@ type HTTPServerMiddleware struct { logger log.Logger } -func (m *HTTPServerMiddleware) preCall(start time.Time) { +func (m *HTTPServerMiddleware) preCall(name string, start time.Time, r *http.Request) { logger := m.opts.filterLog(m.logger) - level.Debug(logger).Log("http.start_time", start.String(), "msg", "started call") + level.Debug(logger).Log("http.start_time", start.String(), "http.method", fmt.Sprintf("%s %s", r.Method, r.URL), "http.request_id", r.Header.Get("X-Request-ID"), "thanos.method_name", name, "msg", "started call") } func (m *HTTPServerMiddleware) postCall(name string, start time.Time, wrapped *httputil.ResponseWriterWithStatus, r *http.Request) { @@ -68,7 +68,7 @@ func (m *HTTPServerMiddleware) HTTPMiddleware(name string, next http.Handler) ht next.ServeHTTP(w, r) case LogStartAndFinishCall: - m.preCall(start) + m.preCall(name, start, r) next.ServeHTTP(wrapped, r) m.postCall(name, start, wrapped, r)