mirror of
https://github.com/pgsty/minio.git
synced 2026-07-21 05:00:22 +03:00
Avoid ListBuckets() call instead rely on simple HTTP GET (#8475)
This is to avoid making calls to backend and requiring gateways to allow permissions for ListBuckets() operation just for Liveness checks, we can avoid this and make our liveness checks to be more performant.
This commit is contained in:
committed by
kannappanr
parent
d28bcb4f84
commit
07a556a10b
@@ -17,8 +17,10 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio/cmd/config"
|
||||
xhttp "github.com/minio/minio/cmd/http"
|
||||
@@ -286,6 +288,28 @@ func ToMinioClientCompleteParts(parts []CompletePart) []minio.CompletePart {
|
||||
return mparts
|
||||
}
|
||||
|
||||
// IsBackendOnline - verifies if the backend is reachable
|
||||
// by performing a GET request on the URL. returns 'true'
|
||||
// if backend is reachable.
|
||||
func IsBackendOnline(ctx context.Context, clnt *http.Client, urlStr string) bool {
|
||||
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// never follow redirects
|
||||
clnt.CheckRedirect = func(*http.Request, []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, urlStr, nil)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if _, err = clnt.Do(req); err != nil {
|
||||
return !xnet.IsNetworkOrHostDown(err)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ErrorRespToObjectError converts MinIO errors to minio object layer errors.
|
||||
func ErrorRespToObjectError(err error, params ...string) error {
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user