Skip to content

Commit

Permalink
query-frontend+api: add context to start call log
Browse files Browse the repository at this point in the history
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 <aymeric.daurelle@cdiscount.com>
  • Loading branch information
Aymeric committed Oct 15, 2021
1 parent fa476b5 commit 2c475d6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#4663](https://github.com/thanos-io/thanos/pull/4663) Fetcher: Fix discovered data races.
- [#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
- [#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

Expand Down
7 changes: 4 additions & 3 deletions cmd/thanos/query_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
),
),
Expand Down
6 changes: 3 additions & 3 deletions pkg/logging/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 2c475d6

Please sign in to comment.