Skip to content

Commit

Permalink
Merge pull request #6148 from abaguas/traceid-on-slow-queries
Browse files Browse the repository at this point in the history
Query-frontend: add traceID to `slow query detected` log line
  • Loading branch information
fpetkovski authored Feb 21, 2023
2 parents 64235a7 + d2a5cd8 commit 36ce9cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#6074](https://github.com/thanos-io/thanos/pull/6074) *: Allow configuring series and sample limits per `Series` request for all Stores.
- [#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

### Fixed

Expand Down
9 changes: 7 additions & 2 deletions internal/cortex/frontend/transport/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

if shouldReportSlowQuery {
f.reportSlowQuery(r, queryString, queryResponseTime)
f.reportSlowQuery(r, hs, queryString, queryResponseTime)
}
if f.cfg.QueryStatsEnabled {
f.reportQueryStats(r, queryString, queryResponseTime, stats)
}
}

// reportSlowQuery reports slow queries.
func (f *Handler) reportSlowQuery(r *http.Request, queryString url.Values, queryResponseTime time.Duration) {
func (f *Handler) reportSlowQuery(r *http.Request, responseHeaders http.Header, queryString url.Values, queryResponseTime time.Duration) {
// NOTE(GiedriusS): see https://github.com/grafana/grafana/pull/60301 for more info.
grafanaDashboardUID := "-"
if dashboardUID := r.Header.Get("X-Dashboard-Uid"); dashboardUID != "" {
Expand All @@ -172,6 +172,10 @@ func (f *Handler) reportSlowQuery(r *http.Request, queryString url.Values, query
if panelID := r.Header.Get("X-Panel-Id"); panelID != "" {
grafanaPanelID = panelID
}
thanosTraceID := "-"
if traceID := responseHeaders.Get("X-Thanos-Trace-Id"); traceID != "" {
thanosTraceID = traceID
}

logMessage := append([]interface{}{
"msg", "slow query detected",
Expand All @@ -181,6 +185,7 @@ func (f *Handler) reportSlowQuery(r *http.Request, queryString url.Values, query
"time_taken", queryResponseTime.String(),
"grafana_dashboard_uid", grafanaDashboardUID,
"grafana_panel_id", grafanaPanelID,
"trace_id", thanosTraceID,
}, formatQueryString(queryString)...)

level.Info(util_log.WithContext(r.Context(), f.log)).Log(logMessage...)
Expand Down

0 comments on commit 36ce9cb

Please sign in to comment.