diff --git a/cmd/common-main.go b/cmd/common-main.go index 9091e230f..d2fb7dd23 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -74,21 +74,23 @@ func checkUpdate(mode string) { // Load logger targets based on user's configuration func loadLoggers() { + loggerUserAgent := getUserAgent(getMinioMode()) + auditEndpoint, ok := os.LookupEnv("MINIO_AUDIT_LOGGER_HTTP_ENDPOINT") if ok { // Enable audit HTTP logging through ENV. - logger.AddAuditTarget(http.New(auditEndpoint, NewCustomHTTPTransport())) + logger.AddAuditTarget(http.New(auditEndpoint, loggerUserAgent, NewCustomHTTPTransport())) } loggerEndpoint, ok := os.LookupEnv("MINIO_LOGGER_HTTP_ENDPOINT") if ok { // Enable HTTP logging through ENV. - logger.AddTarget(http.New(loggerEndpoint, NewCustomHTTPTransport())) + logger.AddTarget(http.New(loggerEndpoint, loggerUserAgent, NewCustomHTTPTransport())) } else { for _, l := range globalServerConfig.Logger.HTTP { if l.Enabled { // Enable http logging - logger.AddTarget(http.New(l.Endpoint, NewCustomHTTPTransport())) + logger.AddTarget(http.New(l.Endpoint, loggerUserAgent, NewCustomHTTPTransport())) } } } diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index bc83a9f96..6d1365f93 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -106,6 +106,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) { logger.Disable = true // Validate if we have access, secret set through environment. + globalGatewayName = gw.Name() gatewayName := gw.Name() if ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, gatewayName, 1) diff --git a/cmd/globals.go b/cmd/globals.go index ff04aa31e..b5d8636fb 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -118,6 +118,9 @@ var ( // Indicates if the running minio is in gateway mode. globalIsGateway = false + // Name of gateway server, e.g S3, GCS, Azure, etc + globalGatewayName = "" + // This flag is set to 'true' by default globalIsBrowserEnabled = true diff --git a/cmd/logger/target/http/http.go b/cmd/logger/target/http/http.go index 803b1d9ef..a61287fd1 100644 --- a/cmd/logger/target/http/http.go +++ b/cmd/logger/target/http/http.go @@ -37,7 +37,9 @@ type Target struct { // HTTP(s) endpoint endpoint string - client gohttp.Client + // User-Agent to be set on each log request sent to the `endpoint` + userAgent string + client gohttp.Client } func (h *Target) startHTTPLogger() { @@ -56,6 +58,10 @@ func (h *Target) startHTTPLogger() { } req.Header.Set(xhttp.ContentType, "application/json") + // Set user-agent to indicate MinIO release + // version to the configured log endpoint + req.Header.Set("User-Agent", h.userAgent) + resp, err := h.client.Do(req) if err != nil { continue @@ -69,9 +75,10 @@ func (h *Target) startHTTPLogger() { // New initializes a new logger target which // sends log over http to the specified endpoint -func New(endpoint string, transport *gohttp.Transport) *Target { +func New(endpoint, userAgent string, transport *gohttp.Transport) *Target { h := Target{ - endpoint: endpoint, + endpoint: endpoint, + userAgent: userAgent, client: gohttp.Client{ Transport: transport, }, diff --git a/cmd/server-main.go b/cmd/server-main.go index 9728c8128..a6053b698 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -237,13 +237,7 @@ func serverMain(ctx *cli.Context) { if !globalCLIContext.Quiet { // Check for new updates from dl.min.io. - mode := globalMinioModeFS - if globalIsDistXL { - mode = globalMinioModeDistXL - } else if globalIsXL { - mode = globalMinioModeXL - } - checkUpdate(mode) + checkUpdate(getMinioMode()) } // FIXME: This code should be removed in future releases and we should have mandatory diff --git a/cmd/utils.go b/cmd/utils.go index c5823d490..996013177 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -508,3 +508,16 @@ func lcp(l []string) string { // are equal, min is the answer ("foo" < "foobar"). return min } + +// Returns the mode in which MinIO is running +func getMinioMode() string { + mode := globalMinioModeFS + if globalIsDistXL { + mode = globalMinioModeDistXL + } else if globalIsXL { + mode = globalMinioModeXL + } else if globalIsGateway { + mode = globalMinioModeGatewayPrefix + globalGatewayName + } + return mode +} diff --git a/cmd/utils_test.go b/cmd/utils_test.go index a86950bb9..e5d2a13cd 100644 --- a/cmd/utils_test.go +++ b/cmd/utils_test.go @@ -500,5 +500,25 @@ func TestLCP(t *testing.T) { t.Fatalf("Test %d: Common prefix found: `%v`, expected: `%v`", i+1, foundPrefix, test.commonPrefix) } } +} + +func TestGetMinioMode(t *testing.T) { + testMinioMode := func(expected string) { + if mode := getMinioMode(); mode != expected { + t.Fatalf("Expected %s got %s", expected, mode) + } + } + globalIsDistXL = true + testMinioMode(globalMinioModeDistXL) + + globalIsDistXL = false + globalIsXL = true + testMinioMode(globalMinioModeXL) + + globalIsDistXL, globalIsXL = false, false + testMinioMode(globalMinioModeFS) + + globalIsGateway, globalGatewayName = true, "azure" + testMinioMode(globalMinioModeGatewayPrefix + globalGatewayName) }