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

Query-frontend: add traceID to slow query detected log line #6148

Merged
merged 6 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -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.
fpetkovski marked this conversation as resolved.
Show resolved Hide resolved
- [#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