mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
API: change HTTP status code tracked in metrics form 503/422 to 499 if a request is canceled
Signed-off-by: Marco Pracucci <marco@pracucci.com>
This commit is contained in:
parent
ae597cac62
commit
3db77b4491
|
@ -63,6 +63,10 @@ type status string
|
||||||
const (
|
const (
|
||||||
statusSuccess status = "success"
|
statusSuccess status = "success"
|
||||||
statusError status = "error"
|
statusError status = "error"
|
||||||
|
|
||||||
|
// Non-standard status code (originally introduced by nginx) for the case when a client closes
|
||||||
|
// the connection while the server is still processing the request.
|
||||||
|
statusClientClosedConnection = 499
|
||||||
)
|
)
|
||||||
|
|
||||||
type errorType string
|
type errorType string
|
||||||
|
@ -593,6 +597,10 @@ func returnAPIError(err error) *apiError {
|
||||||
return &apiError{errorInternal, err}
|
return &apiError{errorInternal, err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if errors.Is(err, context.Canceled) {
|
||||||
|
return &apiError{errorCanceled, err}
|
||||||
|
}
|
||||||
|
|
||||||
return &apiError{errorExec, err}
|
return &apiError{errorExec, err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1599,7 +1607,9 @@ func (api *API) respondError(w http.ResponseWriter, apiErr *apiError, data inter
|
||||||
code = http.StatusBadRequest
|
code = http.StatusBadRequest
|
||||||
case errorExec:
|
case errorExec:
|
||||||
code = http.StatusUnprocessableEntity
|
code = http.StatusUnprocessableEntity
|
||||||
case errorCanceled, errorTimeout:
|
case errorCanceled:
|
||||||
|
code = statusClientClosedConnection
|
||||||
|
case errorTimeout:
|
||||||
code = http.StatusServiceUnavailable
|
code = http.StatusServiceUnavailable
|
||||||
case errorInternal:
|
case errorInternal:
|
||||||
code = http.StatusInternalServerError
|
code = http.StatusInternalServerError
|
||||||
|
|
|
@ -58,7 +58,7 @@ func TestApiStatusCodes(t *testing.T) {
|
||||||
"promql.ErrQueryCanceled": {
|
"promql.ErrQueryCanceled": {
|
||||||
err: promql.ErrQueryCanceled("some error"),
|
err: promql.ErrQueryCanceled("some error"),
|
||||||
expectedString: "query was canceled",
|
expectedString: "query was canceled",
|
||||||
expectedCode: http.StatusServiceUnavailable,
|
expectedCode: statusClientClosedConnection,
|
||||||
},
|
},
|
||||||
|
|
||||||
"promql.ErrQueryTimeout": {
|
"promql.ErrQueryTimeout": {
|
||||||
|
@ -76,7 +76,7 @@ func TestApiStatusCodes(t *testing.T) {
|
||||||
"context.Canceled": {
|
"context.Canceled": {
|
||||||
err: context.Canceled,
|
err: context.Canceled,
|
||||||
expectedString: "context canceled",
|
expectedString: "context canceled",
|
||||||
expectedCode: http.StatusUnprocessableEntity,
|
expectedCode: statusClientClosedConnection,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
for k, q := range map[string]storage.SampleAndChunkQueryable{
|
for k, q := range map[string]storage.SampleAndChunkQueryable{
|
||||||
|
|
Loading…
Reference in a new issue