Skip to content

Commit

Permalink
log grafana headers along with query request before query execution (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
yeya24 authored Dec 3, 2024
1 parent 0c1cb3d commit 5e6907d
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions pkg/frontend/transport/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,7 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// 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...)
f.logQueryRequest(r, queryString)
}

startTime := time.Now()
Expand Down Expand Up @@ -306,6 +300,23 @@ func formatGrafanaStatsFields(r *http.Request) []interface{} {
return fields
}

// logQueryRequest logs query request before query execution.
func (f *Handler) logQueryRequest(r *http.Request, queryString url.Values) {
logMessage := []interface{}{
"msg", "query request",
"component", "query-frontend",
"method", r.Method,
"path", r.URL.Path,
}
grafanaFields := formatGrafanaStatsFields(r)
if len(grafanaFields) > 0 {
logMessage = append(logMessage, grafanaFields...)
}
logMessage = append(logMessage, formatQueryString(queryString)...)

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

// reportSlowQuery reports slow queries.
func (f *Handler) reportSlowQuery(r *http.Request, queryString url.Values, queryResponseTime time.Duration) {
logMessage := []interface{}{
Expand Down

0 comments on commit 5e6907d

Please sign in to comment.