Skip to content

Commit

Permalink
[CHORE] adding user agent
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Takashi <nicolas.tcs@hotmail.com>
  • Loading branch information
nicolastakashi committed Apr 15, 2024
1 parent 968899f commit 2782499
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -33,6 +33,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#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.
- [#7233](https://github.com/thanos-io/thanos/pull/7233): UI: Showing Block Size Stats
- [#7280](https://github.com/thanos-io/thanos/pull/7281): Adding User-Agent to request logs

### Changed

Expand Down
19 changes: 16 additions & 3 deletions pkg/logging/http.go
Expand Up @@ -25,13 +25,26 @@ 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.user_agent", r.Header.Get("User-Agent"),
"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")
Expand Down

0 comments on commit 2782499

Please sign in to comment.