mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
Merge pull request #6840 from pstibrany/context_from_request_should_not_return_error
Don't return error in ContextFromRequest function.
This commit is contained in:
commit
c869e046a5
|
@ -31,12 +31,13 @@ func ContextWithPath(ctx context.Context, path string) context.Context {
|
||||||
return context.WithValue(ctx, pathParam, path)
|
return context.WithValue(ctx, pathParam, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContextFromRequest returns a new context from a requests with identifiers of
|
// ContextFromRequest returns a new context with identifiers of
|
||||||
// the request to be used later when logging the query.
|
// the request to be used later when logging the query.
|
||||||
func ContextFromRequest(ctx context.Context, r *http.Request) (context.Context, error) {
|
func ContextFromRequest(ctx context.Context, r *http.Request) context.Context {
|
||||||
ip, _, err := net.SplitHostPort(r.RemoteAddr)
|
var ip string
|
||||||
if err != nil {
|
if r.RemoteAddr != "" {
|
||||||
return ctx, err
|
// r.RemoteAddr has no defined format, so don't return error if we cannot split it into IP:Port.
|
||||||
|
ip, _, _ = net.SplitHostPort(r.RemoteAddr)
|
||||||
}
|
}
|
||||||
var path string
|
var path string
|
||||||
if v := ctx.Value(pathParam); v != nil {
|
if v := ctx.Value(pathParam); v != nil {
|
||||||
|
@ -48,5 +49,5 @@ func ContextFromRequest(ctx context.Context, r *http.Request) (context.Context,
|
||||||
"method": r.Method,
|
"method": r.Method,
|
||||||
"path": path,
|
"path": path,
|
||||||
},
|
},
|
||||||
}), nil
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,10 +348,7 @@ func (api *API) query(r *http.Request) apiFuncResult {
|
||||||
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, err = httputil.ContextFromRequest(ctx, r)
|
ctx = httputil.ContextFromRequest(ctx, r)
|
||||||
if err != nil {
|
|
||||||
return apiFuncResult{nil, returnAPIError(err), nil, nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
res := qry.Exec(ctx)
|
res := qry.Exec(ctx)
|
||||||
if res.Err != nil {
|
if res.Err != nil {
|
||||||
|
@ -423,10 +420,7 @@ func (api *API) queryRange(r *http.Request) apiFuncResult {
|
||||||
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, err = httputil.ContextFromRequest(ctx, r)
|
ctx = httputil.ContextFromRequest(ctx, r)
|
||||||
if err != nil {
|
|
||||||
return apiFuncResult{nil, returnAPIError(err), nil, nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
res := qry.Exec(ctx)
|
res := qry.Exec(ctx)
|
||||||
if res.Err != nil {
|
if res.Err != nil {
|
||||||
|
|
|
@ -653,11 +653,7 @@ func (h *Handler) consoles(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, err = httputil.ContextFromRequest(ctx, r)
|
ctx = httputil.ContextFromRequest(ctx, r)
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Provide URL parameters as a map for easy use. Advanced users may have need for
|
// Provide URL parameters as a map for easy use. Advanced users may have need for
|
||||||
// parameters beyond the first, so provide RawParams.
|
// parameters beyond the first, so provide RawParams.
|
||||||
|
|
Loading…
Reference in a new issue