Skip to content

Commit

Permalink
Add remoteUser (from http basic auth) and remoteAddr to Thanos slow q…
Browse files Browse the repository at this point in the history
…uery logs (thanos-io#6153)

When tracking where a suspicious query came from, one often needs to
know the remote address or remote user that made the request. Adding these
should help with debugging.

Signed-off-by: Paul Traylor <paul.traylor@linecorp.com>
  • Loading branch information
kfdm authored and Nathaniel Graham committed Apr 17, 2023
1 parent 6880098 commit 489b0ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#6104](https://github.com/thanos-io/thanos/pull/6104) Objstore: Support S3 session token.
- [#5548](https://github.com/thanos-io/thanos/pull/5548) Query: Added experimental support for load balancing across multiple Store endpoints.
- [#6148](https://github.com/thanos-io/thanos/pull/6148) Query-frontend: add traceID to slow query detected log line
- [#6153](https://github.com/thanos-io/thanos/pull/6153) Query-frontend: add remote_user (from http basic auth) and remote_addr to slow query detected log line

### Fixed

Expand Down
7 changes: 7 additions & 0 deletions internal/cortex/frontend/transport/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,15 @@ func (f *Handler) reportSlowQuery(r *http.Request, responseHeaders http.Header,
thanosTraceID = traceID
}

remoteUser, _, _ := r.BasicAuth()

logMessage := append([]interface{}{
"msg", "slow query detected",
"method", r.Method,
"host", r.Host,
"path", r.URL.Path,
"remote_user", remoteUser,
"remote_addr", r.RemoteAddr,
"time_taken", queryResponseTime.String(),
"grafana_dashboard_uid", grafanaDashboardUID,
"grafana_panel_id", grafanaPanelID,
Expand All @@ -200,6 +204,7 @@ func (f *Handler) reportQueryStats(r *http.Request, queryString url.Values, quer
wallTime := stats.LoadWallTime()
numSeries := stats.LoadFetchedSeries()
numBytes := stats.LoadFetchedChunkBytes()
remoteUser, _, _ := r.BasicAuth()

// Track stats.
f.querySeconds.WithLabelValues(userID).Add(wallTime.Seconds())
Expand All @@ -213,6 +218,8 @@ func (f *Handler) reportQueryStats(r *http.Request, queryString url.Values, quer
"component", "query-frontend",
"method", r.Method,
"path", r.URL.Path,
"remote_user", remoteUser,
"remote_addr", r.RemoteAddr,
"response_time", queryResponseTime,
"query_wall_time_seconds", wallTime.Seconds(),
"fetched_series_count", numSeries,
Expand Down

0 comments on commit 489b0ca

Please sign in to comment.