From 489b0ca367dccfa774ef4688817bfc437b96cdb6 Mon Sep 17 00:00:00 2001 From: Paul Traylor Date: Fri, 24 Feb 2023 18:19:38 +0900 Subject: [PATCH] Add remoteUser (from http basic auth) and remoteAddr to Thanos slow query logs (#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 --- CHANGELOG.md | 1 + internal/cortex/frontend/transport/handler.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b03aa7870..fc62887a59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/internal/cortex/frontend/transport/handler.go b/internal/cortex/frontend/transport/handler.go index e4cad320cc..dc3dc1dd27 100644 --- a/internal/cortex/frontend/transport/handler.go +++ b/internal/cortex/frontend/transport/handler.go @@ -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, @@ -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()) @@ -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,