Skip to content

Commit

Permalink
log query string in QFE before executing query request
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed Hassan <[email protected]>
  • Loading branch information
afhassan committed Dec 2, 2024
1 parent 020cc45 commit 50686ee
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/frontend/transport/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,27 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.Body = io.NopCloser(&buf)
}

// Log request
if f.cfg.QueryStatsEnabled {
queryString = f.parseRequestQueryString(r, buf)
logMessage := append([]interface{}{
"msg", "query request",
"component", "query-frontend",
"method", r.Method,
"path", r.URL.Path,
}, formatQueryString(queryString)...)
level.Info(util_log.WithContext(r.Context(), f.log)).Log(logMessage...)
}

startTime := time.Now()
resp, err := f.roundTripper.RoundTrip(r)
queryResponseTime := time.Since(startTime)

// Check whether we should parse the query string.
// Check if we need to parse the query string to avoid parsing twice.
shouldReportSlowQuery := f.cfg.LogQueriesLongerThan != 0 && queryResponseTime > f.cfg.LogQueriesLongerThan
if shouldReportSlowQuery || f.cfg.QueryStatsEnabled {
if shouldReportSlowQuery && !f.cfg.QueryStatsEnabled {
queryString = f.parseRequestQueryString(r, buf)
}

if shouldReportSlowQuery {
f.reportSlowQuery(r, queryString, queryResponseTime)
}
Expand Down

0 comments on commit 50686ee

Please sign in to comment.