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

Improve the frontend slow query logs. #2520

Merged
merged 5 commits into from
Apr 24, 2020
Merged
Changes from 1 commit
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
20 changes: 11 additions & 9 deletions pkg/querier/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"path"
"strings"
"sync"
"time"

Expand All @@ -23,6 +24,8 @@ import (
"github.com/weaveworks/common/httpgrpc"
"github.com/weaveworks/common/httpgrpc/server"
"github.com/weaveworks/common/user"

"github.com/cortexproject/cortex/pkg/util"
)

const (
Expand Down Expand Up @@ -152,27 +155,26 @@ func (f *Frontend) Handler() http.Handler {
}

func (f *Frontend) handle(w http.ResponseWriter, r *http.Request) {
userID, err := user.ExtractOrgID(r.Context())
if err != nil {
server.WriteError(w, err)
return
}

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

if f.cfg.LogQueriesLongerThan > 0 && queryResponseTime > f.cfg.LogQueriesLongerThan {
logMessage := []interface{}{"msg", "slow query",
"org_id", userID,
"url", fmt.Sprintf("http://%s", r.Host+r.RequestURI),
logMessage := []interface{}{
"msg", "slow query",
"host", r.Host,
"path", r.URL.Path,
"time_taken", queryResponseTime.String(),
}
for k, v := range r.URL.Query() {
append(logMessage, fmt.Sprintf("qs_%s", k), strings.Join(v, ","))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bug here. logMessage is not updated with the result of append(). I fix it for you.

}
pf := r.PostForm.Encode()
if pf != "" {
logMessage = append(logMessage, "body", pf)
}
level.Info(f.log).Log(logMessage...)
level.Info(util.WithContext(r.Context(), util.Logger)).Log(logMessage...)
pstibrany marked this conversation as resolved.
Show resolved Hide resolved
}

if err != nil {
Expand Down