From a356c10c4a9e14ebea559eeb53bbefef1b993eb6 Mon Sep 17 00:00:00 2001 From: Nicolas Takashi Date: Mon, 15 Apr 2024 15:43:09 +0100 Subject: [PATCH] [CHORE] adding user agent Signed-off-by: Nicolas Takashi --- CHANGELOG.md | 1 + pkg/logging/http.go | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2e10303280..d4b973b114b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#7175](https://github.com/thanos-io/thanos/pull/7175): Query: Add `--query.mode=distributed` which enables the new distributed mode of the Thanos query engine. - [#7199](https://github.com/thanos-io/thanos/pull/7199): Reloader: Add support for watching and decompressing Prometheus configuration directories - [#7200](https://github.com/thanos-io/thanos/pull/7175): Query: Add `--selector.relabel-config` and `--selector.relabel-config-file` flags which allows scoping the Querier to a subset of matched TSDBs. +- [#7280](https://github.com/thanos-io/thanos/pull/7281) ### Changed diff --git a/pkg/logging/http.go b/pkg/logging/http.go index 36c4395f763..9da51ff018f 100644 --- a/pkg/logging/http.go +++ b/pkg/logging/http.go @@ -25,13 +25,25 @@ type HTTPServerMiddleware struct { 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(), "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") + 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"), + "http.user_agent", r.Header.Get("User-Agent"), + "thanos.method_name", name, + "msg", "started call", + ) } func (m *HTTPServerMiddleware) postCall(name string, start time.Time, wrapped *httputil.ResponseWriterWithStatus, r *http.Request) { status := wrapped.Status() - logger := log.With(m.logger, "http.method", fmt.Sprintf("%s %s", r.Method, r.URL), "http.request_id", r.Header.Get("X-Request-ID"), "http.status_code", fmt.Sprintf("%d", status), - "http.time_ms", fmt.Sprintf("%v", durationToMilliseconds(time.Since(start))), "http.remote_addr", r.RemoteAddr, "thanos.method_name", name) + logger := log.With(m.logger, + "http.method", fmt.Sprintf("%s %s", r.Method, r.URL), + "http.request_id", r.Header.Get("X-Request-ID"), + "http.status_code", fmt.Sprintf("%d", status), + "http.time_ms", fmt.Sprintf("%v", durationToMilliseconds(time.Since(start))), + "http.remote_addr", r.RemoteAddr, + "thanos.method_name", name) logger = m.opts.filterLog(logger) m.opts.levelFunc(logger, status).Log("msg", "finished call")