Add User-Agent header with MinIO release details in http logs (#7843)

This would allow http log target server to distinguish between log
messages across different versions of MinIO deployments.
master
Krishnan Parthasarathi 5 years ago committed by Harshavardhana
parent 1cd801b2e9
commit bbb56739bd
  1. 8
      cmd/common-main.go
  2. 1
      cmd/gateway-main.go
  3. 3
      cmd/globals.go
  4. 9
      cmd/logger/target/http/http.go
  5. 8
      cmd/server-main.go
  6. 13
      cmd/utils.go
  7. 20
      cmd/utils_test.go

@ -74,21 +74,23 @@ func checkUpdate(mode string) {
// Load logger targets based on user's configuration // Load logger targets based on user's configuration
func loadLoggers() { func loadLoggers() {
loggerUserAgent := getUserAgent(getMinioMode())
auditEndpoint, ok := os.LookupEnv("MINIO_AUDIT_LOGGER_HTTP_ENDPOINT") auditEndpoint, ok := os.LookupEnv("MINIO_AUDIT_LOGGER_HTTP_ENDPOINT")
if ok { if ok {
// Enable audit HTTP logging through ENV. // 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") loggerEndpoint, ok := os.LookupEnv("MINIO_LOGGER_HTTP_ENDPOINT")
if ok { if ok {
// Enable HTTP logging through ENV. // Enable HTTP logging through ENV.
logger.AddTarget(http.New(loggerEndpoint, NewCustomHTTPTransport())) logger.AddTarget(http.New(loggerEndpoint, loggerUserAgent, NewCustomHTTPTransport()))
} else { } else {
for _, l := range globalServerConfig.Logger.HTTP { for _, l := range globalServerConfig.Logger.HTTP {
if l.Enabled { if l.Enabled {
// Enable http logging // Enable http logging
logger.AddTarget(http.New(l.Endpoint, NewCustomHTTPTransport())) logger.AddTarget(http.New(l.Endpoint, loggerUserAgent, NewCustomHTTPTransport()))
} }
} }
} }

@ -106,6 +106,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
logger.Disable = true logger.Disable = true
// Validate if we have access, secret set through environment. // Validate if we have access, secret set through environment.
globalGatewayName = gw.Name()
gatewayName := gw.Name() gatewayName := gw.Name()
if ctx.Args().First() == "help" { if ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, gatewayName, 1) cli.ShowCommandHelpAndExit(ctx, gatewayName, 1)

@ -118,6 +118,9 @@ var (
// Indicates if the running minio is in gateway mode. // Indicates if the running minio is in gateway mode.
globalIsGateway = false globalIsGateway = false
// Name of gateway server, e.g S3, GCS, Azure, etc
globalGatewayName = ""
// This flag is set to 'true' by default // This flag is set to 'true' by default
globalIsBrowserEnabled = true globalIsBrowserEnabled = true

@ -37,6 +37,8 @@ type Target struct {
// HTTP(s) endpoint // HTTP(s) endpoint
endpoint string endpoint string
// User-Agent to be set on each log request sent to the `endpoint`
userAgent string
client gohttp.Client client gohttp.Client
} }
@ -56,6 +58,10 @@ func (h *Target) startHTTPLogger() {
} }
req.Header.Set(xhttp.ContentType, "application/json") 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) resp, err := h.client.Do(req)
if err != nil { if err != nil {
continue continue
@ -69,9 +75,10 @@ func (h *Target) startHTTPLogger() {
// New initializes a new logger target which // New initializes a new logger target which
// sends log over http to the specified endpoint // 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{ h := Target{
endpoint: endpoint, endpoint: endpoint,
userAgent: userAgent,
client: gohttp.Client{ client: gohttp.Client{
Transport: transport, Transport: transport,
}, },

@ -237,13 +237,7 @@ func serverMain(ctx *cli.Context) {
if !globalCLIContext.Quiet { if !globalCLIContext.Quiet {
// Check for new updates from dl.min.io. // Check for new updates from dl.min.io.
mode := globalMinioModeFS checkUpdate(getMinioMode())
if globalIsDistXL {
mode = globalMinioModeDistXL
} else if globalIsXL {
mode = globalMinioModeXL
}
checkUpdate(mode)
} }
// FIXME: This code should be removed in future releases and we should have mandatory // FIXME: This code should be removed in future releases and we should have mandatory

@ -508,3 +508,16 @@ func lcp(l []string) string {
// are equal, min is the answer ("foo" < "foobar"). // are equal, min is the answer ("foo" < "foobar").
return min 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
}

@ -500,5 +500,25 @@ func TestLCP(t *testing.T) {
t.Fatalf("Test %d: Common prefix found: `%v`, expected: `%v`", i+1, foundPrefix, test.commonPrefix) 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)
} }

Loading…
Cancel
Save