From 54431b3953c6613a1356b6af400928458186a957 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 24 Dec 2019 11:31:32 -0800 Subject: [PATCH] Change replica set detection for localhost on single endpoint (#8692) --- buildscripts/gateway-tests.sh | 4 +-- cmd/endpoint.go | 57 +++++++++++++++++++++++------------ cmd/main.go | 1 - cmd/storage-rest-common.go | 2 +- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/buildscripts/gateway-tests.sh b/buildscripts/gateway-tests.sh index 128d9eb5e..4bf132457 100755 --- a/buildscripts/gateway-tests.sh +++ b/buildscripts/gateway-tests.sh @@ -46,9 +46,7 @@ function main() gw_pid="$(start_minio_gateway_s3)" SERVER_ENDPOINT=127.0.0.1:24240 ENABLE_HTTPS=0 ACCESS_KEY=minio \ - SECRET_KEY=minio123 MINT_MODE="full" /mint/entrypoint.sh aws-sdk-go \ - aws-sdk-java aws-sdk-php aws-sdk-ruby awscli healthcheck minio-dotnet \ - minio-go minio-java minio-js minio-py + SECRET_KEY=minio123 MINT_MODE="full" /mint/entrypoint.sh rv=$? kill "$sr_pid" diff --git a/cmd/endpoint.go b/cmd/endpoint.go index 52f8a4dd7..1194553b9 100644 --- a/cmd/endpoint.go +++ b/cmd/endpoint.go @@ -18,7 +18,6 @@ package cmd import ( "context" - "errors" "fmt" "net" "net/url" @@ -230,23 +229,25 @@ func (endpoints Endpoints) GetString(i int) string { return endpoints[i].String() } -func (endpoints Endpoints) doAnyHostsResolveToLocalhost() bool { - for _, endpoint := range endpoints { - hostIPs, err := getHostIP(endpoint.Hostname()) - if err != nil { - continue - } - var loopback int - for _, hostIP := range hostIPs.ToSlice() { - if net.ParseIP(hostIP).IsLoopback() { - loopback++ - } - } - if loopback == len(hostIPs) { - return true - } - } - return false +func hostResolveToLocalhost(endpoint Endpoint) bool { + hostIPs, err := getHostIP(endpoint.Hostname()) + if err != nil { + // Log the message to console about the host resolving + reqInfo := (&logger.ReqInfo{}).AppendTags( + "host", + endpoint.Hostname(), + ) + ctx := logger.SetReqInfo(context.Background(), reqInfo) + logger.LogIf(ctx, err, logger.Application) + return false + } + var loopback int + for _, hostIP := range hostIPs.ToSlice() { + if net.ParseIP(hostIP).IsLoopback() { + loopback++ + } + } + return loopback == len(hostIPs) } func (endpoints Endpoints) atleastOneEndpointLocal() bool { @@ -294,8 +295,9 @@ func (endpoints Endpoints) UpdateIsLocal(foundPrevLocal bool) error { endpoints[i].Hostname(), ) - if k8sReplicaSet && endpoints.doAnyHostsResolveToLocalhost() { - err := errors.New("host found resolves to 127.*, DNS incorrectly configured retrying") + if k8sReplicaSet && hostResolveToLocalhost(endpoints[i]) { + err := fmt.Errorf("host %s resolves to 127.*, DNS incorrectly configured retrying", + endpoints[i]) // time elapsed timeElapsed := time.Since(startTime) // log error only if more than 1s elapsed @@ -352,6 +354,21 @@ func (endpoints Endpoints) UpdateIsLocal(foundPrevLocal bool) error { // previous local we continue to wait to look for // atleast one local. resolvedList[i] = false + // time elapsed + err := fmt.Errorf("no endpoint is local to this host: %s", endpoints[i]) + timeElapsed := time.Since(startTime) + // log error only if more than 1s elapsed + if timeElapsed > time.Second { + reqInfo.AppendTags("elapsedTime", + humanize.RelTime(startTime, + startTime.Add(timeElapsed), + "elapsed", + "", + )) + ctx := logger.SetReqInfo(context.Background(), + reqInfo) + logger.LogIf(ctx, err, logger.Application) + } continue } epsResolved++ diff --git a/cmd/main.go b/cmd/main.go index 61f82c032..54527d5c8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -130,7 +130,6 @@ func newApp(name string) *cli.App { app.Usage = "High Performance Object Storage" app.Description = `Build high performance data infrastructure for machine learning, analytics and application data workloads with MinIO` app.Flags = GlobalFlags - app.HideVersion = true // Hide `--version` flag, we already have `minio version`. app.HideHelpCommand = true // Hide `help, h` command, we already have `minio --help`. app.Commands = commands app.CustomAppHelpTemplate = minioHelpTemplate diff --git a/cmd/storage-rest-common.go b/cmd/storage-rest-common.go index 964c81368..fc7458def 100644 --- a/cmd/storage-rest-common.go +++ b/cmd/storage-rest-common.go @@ -17,7 +17,7 @@ package cmd const ( - storageRESTVersion = "v11" + storageRESTVersion = "v12" storageRESTVersionPrefix = SlashSeparator + storageRESTVersion storageRESTPrefix = minioReservedBucketPath + "/storage" )