Skip to content

Commit

Permalink
[query] Log query errors with query params
Browse files Browse the repository at this point in the history
  • Loading branch information
robskillington committed Mar 24, 2020
1 parent 4e589d5 commit c346552
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/query/api/v1/handler/prometheus/native/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (h *PromReadHandler) ServeHTTPWithEngine(
w http.ResponseWriter,
r *http.Request,
engine executor.Engine,
opts *executor.QueryOptions,
queryOpts *executor.QueryOptions,
fetchOpts *storage.FetchOptions,
) ([]*ts.Series, models.RequestParams, *RespError) {
ctx := context.WithValue(r.Context(), handler.HeaderKey, r.Header)
Expand All @@ -191,21 +191,25 @@ func (h *PromReadHandler) ServeHTTPWithEngine(
}

if params.Debug {
logger.Info("Request params", zap.Any("params", params))
logger.Info("request params", zap.Any("params", params))
}

if err := h.validateRequest(&params); err != nil {
h.promReadMetrics.fetchErrorsClient.Inc(1)
return nil, emptyReqParams, &RespError{Err: err, Code: http.StatusBadRequest}
}

result, err := read(ctx, engine, opts, fetchOpts, h.tagOpts,
result, err := read(ctx, engine, queryOpts, fetchOpts, h.tagOpts,
w, params, h.instrumentOpts)
if err != nil {
sp := xopentracing.SpanFromContextOrNoop(ctx)
sp.LogFields(opentracinglog.Error(err))
opentracingext.Error.Set(sp, true)
logger.Error("unable to fetch data", zap.Error(err))
logger.Error("range query error",
zap.Error(err),
zap.Any("params", params),
zap.Any("queryOpts", queryOpts),
zap.Any("fetchOpts", fetchOpts))
h.promReadMetrics.fetchErrorsServer.Inc(1)
return nil, emptyReqParams, &RespError{Err: err, Code: http.StatusInternalServerError}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ func (h *PromReadInstantHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
result, err := read(ctx, h.engine, queryOpts, fetchOpts,
h.tagOpts, w, params, h.instrumentOpts)
if err != nil {
logger.Error("unable to fetch data", zap.Error(err))
logger.Error("instant query error",
zap.Error(err),
zap.Any("params", params),
zap.Any("queryOpts", queryOpts),
zap.Any("fetchOpts", queryOpts))
xhttp.Error(w, err, http.StatusInternalServerError)
return
}
Expand Down
6 changes: 5 additions & 1 deletion src/query/api/v1/handler/prometheus/remote/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ func (h *PromReadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
readResult, err := h.read(ctx, w, req, timeout, fetchOpts)
if err != nil {
h.promReadMetrics.fetchErrorsServer.Inc(1)
logger.Error("unable to fetch data", zap.Error(err))
logger.Error("remote read query error",
zap.Error(err),
zap.Any("req", req),
zap.Duration("timeout", timeout),
zap.Any("fetchOpts", fetchOpts))
xhttp.Error(w, err, http.StatusInternalServerError)
return
}
Expand Down
9 changes: 6 additions & 3 deletions src/query/api/v1/handler/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ func (h *SearchHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
logger := logging.WithContext(r.Context(), h.instrumentOpts)

query, parseBodyErr := h.parseBody(r)
opts, parseURLParamsErr := h.parseURLParams(r)
fetchOpts, parseURLParamsErr := h.parseURLParams(r)
if err := firstParseError(parseBodyErr, parseURLParamsErr); err != nil {
logger.Error("unable to parse request", zap.Error(err.Inner()))
xhttp.Error(w, err.Inner(), err.Code())
return
}

results, err := h.search(r.Context(), query, opts)
results, err := h.search(r.Context(), query, fetchOpts)
if err != nil {
logger.Error("unable to fetch data", zap.Error(err))
logger.Error("search query error",
zap.Error(err),
zap.Any("query", query),
zap.Any("fetchOpts", fetchOpts))
xhttp.Error(w, err, http.StatusBadRequest)
return
}
Expand Down

0 comments on commit c346552

Please sign in to comment.