Browse Source
liveness returns "busy" if queued requests > available capacity (#16719)
pull/16723/head
Harshavardhana
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
26 additions and
3 deletions
-
cmd/api-errors.go
-
cmd/apierrorcode_string.go
-
cmd/handler-api.go
-
cmd/healthcheck-handler.go
-
cmd/http-stats.go
|
|
@ -1520,7 +1520,7 @@ var errorCodes = errorCodeMap{ |
|
|
|
HTTPStatusCode: http.StatusBadRequest, |
|
|
|
}, |
|
|
|
ErrBusy: { |
|
|
|
Code: "Busy", |
|
|
|
Code: "ServerBusy", |
|
|
|
Description: "The service is unavailable. Please retry.", |
|
|
|
HTTPStatusCode: http.StatusServiceUnavailable, |
|
|
|
}, |
|
|
|
|
|
@ -227,6 +227,13 @@ func (t *apiConfig) getClusterDeadline() time.Duration { |
|
|
|
return t.clusterDeadline |
|
|
|
} |
|
|
|
|
|
|
|
func (t *apiConfig) getRequestsPoolCapacity() int { |
|
|
|
t.mu.RLock() |
|
|
|
defer t.mu.RUnlock() |
|
|
|
|
|
|
|
return cap(t.requestsPool) |
|
|
|
} |
|
|
|
|
|
|
|
func (t *apiConfig) getRequestsPool() (chan struct{}, time.Duration) { |
|
|
|
t.mu.RLock() |
|
|
|
defer t.mu.RUnlock() |
|
|
|
|
|
@ -106,6 +106,17 @@ func LivenessCheckHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.Header().Set(xhttp.MinIOServerStatus, unavailable) |
|
|
|
} |
|
|
|
|
|
|
|
if int(globalHTTPStats.loadRequestsInQueue()) > globalAPIConfig.getRequestsPoolCapacity() { |
|
|
|
apiErr := getAPIError(ErrBusy) |
|
|
|
switch r.Method { |
|
|
|
case http.MethodHead: |
|
|
|
writeResponse(w, apiErr.HTTPStatusCode, nil, mimeNone) |
|
|
|
case http.MethodGet: |
|
|
|
writeErrorResponse(r.Context(), w, apiErr, r.URL) |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// Verify if KMS is reachable if its configured
|
|
|
|
if GlobalKMS != nil { |
|
|
|
ctx, cancel := context.WithTimeout(r.Context(), time.Minute) |
|
|
|
|
|
@ -255,6 +255,10 @@ type HTTPStats struct { |
|
|
|
totalS3Canceled HTTPAPIStats |
|
|
|
} |
|
|
|
|
|
|
|
func (st *HTTPStats) loadRequestsInQueue() int32 { |
|
|
|
return atomic.LoadInt32(&st.s3RequestsInQueue) |
|
|
|
} |
|
|
|
|
|
|
|
func (st *HTTPStats) addRequestsInQueue(i int32) { |
|
|
|
atomic.AddInt32(&st.s3RequestsInQueue, i) |
|
|
|
} |
|
|
|