mirror of
https://github.com/minio/minio.git
synced 2025-04-27 13:24:52 -04:00
fix: check for gateway backend online without http request (#10924)
fixes #10921
This commit is contained in:
parent
d778d9493f
commit
0f9e125cf3
@ -18,6 +18,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -254,25 +255,18 @@ func ToMinioClientCompleteParts(parts []CompletePart) []minio.CompletePart {
|
|||||||
// IsBackendOnline - verifies if the backend is reachable
|
// IsBackendOnline - verifies if the backend is reachable
|
||||||
// by performing a GET request on the URL. returns 'true'
|
// by performing a GET request on the URL. returns 'true'
|
||||||
// if backend is reachable.
|
// if backend is reachable.
|
||||||
func IsBackendOnline(ctx context.Context, clnt *http.Client, urlStr string) bool {
|
func IsBackendOnline(ctx context.Context, host string) bool {
|
||||||
|
var d net.Dialer
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
|
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// never follow redirects
|
conn, err := d.DialContext(ctx, "tcp", host)
|
||||||
clnt.CheckRedirect = func(*http.Request, []*http.Request) error {
|
|
||||||
return http.ErrUseLastResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, urlStr, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
resp, err := clnt.Do(req)
|
|
||||||
if err != nil {
|
conn.Close()
|
||||||
clnt.CloseIdleConnections()
|
|
||||||
return !xnet.IsNetworkOrHostDown(err, false)
|
|
||||||
}
|
|
||||||
xhttp.DrainBody(resp.Body)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ func (g *Azure) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, erro
|
|||||||
client := azblob.NewServiceURL(*endpointURL, pipeline)
|
client := azblob.NewServiceURL(*endpointURL, pipeline)
|
||||||
|
|
||||||
return &azureObjects{
|
return &azureObjects{
|
||||||
endpoint: endpointURL.String(),
|
endpoint: endpointURL,
|
||||||
httpClient: httpClient,
|
httpClient: httpClient,
|
||||||
client: client,
|
client: client,
|
||||||
metrics: metrics,
|
metrics: metrics,
|
||||||
@ -424,7 +424,7 @@ func azurePropertiesToS3Meta(meta azblob.Metadata, props azblob.BlobHTTPHeaders,
|
|||||||
// azureObjects - Implements Object layer for Azure blob storage.
|
// azureObjects - Implements Object layer for Azure blob storage.
|
||||||
type azureObjects struct {
|
type azureObjects struct {
|
||||||
minio.GatewayUnsupported
|
minio.GatewayUnsupported
|
||||||
endpoint string
|
endpoint *url.URL
|
||||||
httpClient *http.Client
|
httpClient *http.Client
|
||||||
metrics *minio.Metrics
|
metrics *minio.Metrics
|
||||||
client azblob.ServiceURL // Azure sdk client
|
client azblob.ServiceURL // Azure sdk client
|
||||||
@ -553,7 +553,11 @@ func (a *azureObjects) Shutdown(ctx context.Context) error {
|
|||||||
// StorageInfo - Not relevant to Azure backend.
|
// StorageInfo - Not relevant to Azure backend.
|
||||||
func (a *azureObjects) StorageInfo(ctx context.Context, _ bool) (si minio.StorageInfo, _ []error) {
|
func (a *azureObjects) StorageInfo(ctx context.Context, _ bool) (si minio.StorageInfo, _ []error) {
|
||||||
si.Backend.Type = minio.BackendGateway
|
si.Backend.Type = minio.BackendGateway
|
||||||
si.Backend.GatewayOnline = minio.IsBackendOnline(ctx, a.httpClient, a.endpoint)
|
host := a.endpoint.Host
|
||||||
|
if a.endpoint.Port() == "" {
|
||||||
|
host = a.endpoint.Host + ":" + a.endpoint.Scheme
|
||||||
|
}
|
||||||
|
si.Backend.GatewayOnline = minio.IsBackendOnline(ctx, host)
|
||||||
return si, nil
|
return si, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ func (l *gcsGateway) Shutdown(ctx context.Context) error {
|
|||||||
// StorageInfo - Not relevant to GCS backend.
|
// StorageInfo - Not relevant to GCS backend.
|
||||||
func (l *gcsGateway) StorageInfo(ctx context.Context, _ bool) (si minio.StorageInfo, _ []error) {
|
func (l *gcsGateway) StorageInfo(ctx context.Context, _ bool) (si minio.StorageInfo, _ []error) {
|
||||||
si.Backend.Type = minio.BackendGateway
|
si.Backend.Type = minio.BackendGateway
|
||||||
si.Backend.GatewayOnline = minio.IsBackendOnline(ctx, l.httpClient, "https://storage.googleapis.com")
|
si.Backend.GatewayOnline = minio.IsBackendOnline(ctx, "storage.googleapis.com:443")
|
||||||
return si, nil
|
return si, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,11 @@ func (l *s3Objects) Shutdown(ctx context.Context) error {
|
|||||||
// StorageInfo is not relevant to S3 backend.
|
// StorageInfo is not relevant to S3 backend.
|
||||||
func (l *s3Objects) StorageInfo(ctx context.Context, _ bool) (si minio.StorageInfo, _ []error) {
|
func (l *s3Objects) StorageInfo(ctx context.Context, _ bool) (si minio.StorageInfo, _ []error) {
|
||||||
si.Backend.Type = minio.BackendGateway
|
si.Backend.Type = minio.BackendGateway
|
||||||
si.Backend.GatewayOnline = minio.IsBackendOnline(ctx, l.HTTPClient, l.Client.EndpointURL().String())
|
host := l.Client.EndpointURL().Host
|
||||||
|
if l.Client.EndpointURL().Port() == "" {
|
||||||
|
host = l.Client.EndpointURL().Host + ":" + l.Client.EndpointURL().Scheme
|
||||||
|
}
|
||||||
|
si.Backend.GatewayOnline = minio.IsBackendOnline(ctx, host)
|
||||||
return si, nil
|
return si, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user