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:
Harshavardhana
2019-11-01 16:58:11 -07:00
committed by kannappanr
parent d28bcb4f84
commit 07a556a10b
10 changed files with 80 additions and 24 deletions
+24
View File
@@ -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 {