Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHORE] considering X-Forwarded-For on HTTP Logging #7303

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#7280](https://github.com/thanos-io/thanos/pull/7281): Adding User-Agent to request logs
- [#7219](https://github.com/thanos-io/thanos/pull/7219): Receive: add `--remote-write.client-tls-secure` and `--remote-write.client-tls-skip-verify` flags to stop relying on grpc server config to determine grpc client secure/skipVerify.
- [#7297](https://github.com/thanos-io/thanos/pull/7297): *: mark as not queryable if status is not ready
- [#7302](https://github.com/thanos-io/thanos/pull/7303) Considering the `X-Forwarded-For` header for the remote address in the logs.

### Changed

Expand Down
8 changes: 7 additions & 1 deletion pkg/logging/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ func (m *HTTPServerMiddleware) preCall(name string, start time.Time, r *http.Req

func (m *HTTPServerMiddleware) postCall(name string, start time.Time, wrapped *httputil.ResponseWriterWithStatus, r *http.Request) {
status := wrapped.Status()

remoteAddr := r.Header.Get("X-Forwarded-For")
if remoteAddr == "" {
remoteAddr = r.RemoteAddr
}

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,
"http.remote_addr", remoteAddr,
"thanos.method_name", name)

logger = m.opts.filterLog(logger)
Expand Down
Loading