Skip to content

Commit

Permalink
config: Remove level in console/file loggers (#3938)
Browse files Browse the repository at this point in the history
Also rename fileName field in file logger to filename
  • Loading branch information
vadmeste authored and harshavardhana committed Mar 23, 2017
1 parent 4e92b2e commit 11e15f9
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 86 deletions.
109 changes: 104 additions & 5 deletions cmd/config-migrate.go
Expand Up @@ -82,6 +82,10 @@ func migrateConfig() error {
if err := migrateV14ToV15(); err != nil {
return err
}
// Migration version '15' to '16'.
if err := migrateV15ToV16(); err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -136,11 +140,11 @@ func migrateV2ToV3() error {
// Region needs to be set for AWS Signature V4.
srvConfig.Region = globalMinioDefaultRegion
}
srvConfig.Logger.Console = consoleLogger{
srvConfig.Logger.Console = consoleLoggerV1{
Enable: true,
Level: "fatal",
}
flogger := fileLogger{}
flogger := fileLoggerV1{}
flogger.Level = "error"
if cv2.FileLogger.Filename != "" {
flogger.Enable = true
Expand Down Expand Up @@ -745,7 +749,7 @@ func migrateV12ToV13() error {

// Copy over fields from V12 into V13 config struct
srvConfig := &serverConfigV13{
Logger: &logger{},
Logger: &loggerV7{},
Notify: &notifier{},
}
srvConfig.Version = "13"
Expand Down Expand Up @@ -825,7 +829,7 @@ func migrateV13ToV14() error {

// Copy over fields from V13 into V14 config struct
srvConfig := &serverConfigV14{
Logger: &logger{},
Logger: &loggerV7{},
Notify: &notifier{},
}
srvConfig.Version = "14"
Expand Down Expand Up @@ -910,7 +914,7 @@ func migrateV14ToV15() error {

// Copy over fields from V14 into V15 config struct
srvConfig := &serverConfigV15{
Logger: &logger{},
Logger: &loggerV7{},
Notify: &notifier{},
}
srvConfig.Version = "15"
Expand Down Expand Up @@ -981,3 +985,98 @@ func migrateV14ToV15() error {
console.Printf("Migration from version ‘%s’ to ‘%s’ completed successfully.\n", cv14.Version, srvConfig.Version)
return nil
}

// Version '15' to '16' migration. Remove log level in loggers
// and rename 'fileName' filed in File logger to 'filename'
func migrateV15ToV16() error {
configFile := getConfigFile()

cv15 := &serverConfigV15{}
_, err := quick.Load(configFile, cv15)
if os.IsNotExist(err) {
return nil
} else if err != nil {
return fmt.Errorf("Unable to load config version ‘15’. %v", err)
}
if cv15.Version != "15" {
return nil
}

// Copy over fields from V15 into V16 config struct
srvConfig := &serverConfigV16{
Logger: &logger{},
Notify: &notifier{},
}
srvConfig.Version = "16"
srvConfig.Credential = cv15.Credential
srvConfig.Region = cv15.Region
if srvConfig.Region == "" {
// Region needs to be set for AWS Signature Version 4.
srvConfig.Region = globalMinioDefaultRegion
}

// check and set notifiers config
if len(cv15.Notify.AMQP) == 0 {
srvConfig.Notify.AMQP = make(map[string]amqpNotify)
srvConfig.Notify.AMQP["1"] = amqpNotify{}
} else {
srvConfig.Notify.AMQP = cv15.Notify.AMQP
}
if len(cv15.Notify.ElasticSearch) == 0 {
srvConfig.Notify.ElasticSearch = make(map[string]elasticSearchNotify)
srvConfig.Notify.ElasticSearch["1"] = elasticSearchNotify{}
} else {
srvConfig.Notify.ElasticSearch = cv15.Notify.ElasticSearch
}
if len(cv15.Notify.Redis) == 0 {
srvConfig.Notify.Redis = make(map[string]redisNotify)
srvConfig.Notify.Redis["1"] = redisNotify{}
} else {
srvConfig.Notify.Redis = cv15.Notify.Redis
}
if len(cv15.Notify.PostgreSQL) == 0 {
srvConfig.Notify.PostgreSQL = make(map[string]postgreSQLNotify)
srvConfig.Notify.PostgreSQL["1"] = postgreSQLNotify{}
} else {
srvConfig.Notify.PostgreSQL = cv15.Notify.PostgreSQL
}
if len(cv15.Notify.Kafka) == 0 {
srvConfig.Notify.Kafka = make(map[string]kafkaNotify)
srvConfig.Notify.Kafka["1"] = kafkaNotify{}
} else {
srvConfig.Notify.Kafka = cv15.Notify.Kafka
}
if len(cv15.Notify.NATS) == 0 {
srvConfig.Notify.NATS = make(map[string]natsNotify)
srvConfig.Notify.NATS["1"] = natsNotify{}
} else {
srvConfig.Notify.NATS = cv15.Notify.NATS
}
if len(cv15.Notify.Webhook) == 0 {
srvConfig.Notify.Webhook = make(map[string]webhookNotify)
srvConfig.Notify.Webhook["1"] = webhookNotify{}
} else {
srvConfig.Notify.Webhook = cv15.Notify.Webhook
}
if len(cv15.Notify.MySQL) == 0 {
srvConfig.Notify.MySQL = make(map[string]mySQLNotify)
srvConfig.Notify.MySQL["1"] = mySQLNotify{}
} else {
srvConfig.Notify.MySQL = cv15.Notify.MySQL
}

// Load browser config from existing config in the file.
srvConfig.Browser = cv15.Browser

// Migrate console and file fields
srvConfig.Logger.Console = consoleLogger{Enable: cv15.Logger.Console.Enable}
srvConfig.Logger.File = fileLogger{Enable: cv15.Logger.File.Enable, Filename: cv15.Logger.File.Filename}

if err = quick.Save(configFile, srvConfig); err != nil {
return fmt.Errorf("Failed to migrate config from ‘%s’ to ‘%s’. %v", cv15.Version, srvConfig.Version, err)
}

console.Printf("Migration from version ‘%s’ to ‘%s’ completed successfully.\n", cv15.Version, srvConfig.Version)

return nil
}
12 changes: 9 additions & 3 deletions cmd/config-migrate_test.go
Expand Up @@ -112,10 +112,13 @@ func TestServerConfigMigrateInexistentConfig(t *testing.T) {
if err := migrateV14ToV15(); err != nil {
t.Fatal("migrate v14 to v15 should succeed when no config file is found")
}
if err := migrateV15ToV16(); err != nil {
t.Fatal("migrate v15 to v16 should succeed when no config file is found")
}
}

// Test if a config migration from v2 to v15 is successfully done
func TestServerConfigMigrateV2toV15(t *testing.T) {
// Test if a config migration from v2 to v16 is successfully done
func TestServerConfigMigrateV2toV16(t *testing.T) {
rootPath, err := newTestConfig(globalMinioDefaultRegion)
if err != nil {
t.Fatalf("Init Test config failed")
Expand Down Expand Up @@ -154,7 +157,7 @@ func TestServerConfigMigrateV2toV15(t *testing.T) {
}

// Check the version number in the upgraded config file
expectedVersion := v15
expectedVersion := v16
if serverConfig.Version != expectedVersion {
t.Fatalf("Expect version "+expectedVersion+", found: %v", serverConfig.Version)
}
Expand Down Expand Up @@ -225,4 +228,7 @@ func TestServerConfigMigrateFaultyConfig(t *testing.T) {
if err := migrateV14ToV15(); err == nil {
t.Fatal("migrateConfigV14ToV15() should fail with a corrupted json")
}
if err := migrateV15ToV16(); err == nil {
t.Fatal("migrateConfigV15ToV16() should fail with a corrupted json")
}
}
51 changes: 43 additions & 8 deletions cmd/config-old.go
Expand Up @@ -186,10 +186,22 @@ type configV5 struct {
Logger loggerV5 `json:"logger"`
}

// consoleLogger - default logger if not other logging is enabled.
type consoleLoggerV1 struct {
Enable bool `json:"enable"`
Level string `json:"level"`
}

type fileLoggerV1 struct {
Enable bool `json:"enable"`
Filename string `json:"fileName"`
Level string `json:"level"`
}

type loggerV6 struct {
Console consoleLogger `json:"console"`
File fileLogger `json:"file"`
Syslog syslogLoggerV3 `json:"syslog"`
Console consoleLoggerV1 `json:"console"`
File fileLoggerV1 `json:"file"`
Syslog syslogLoggerV3 `json:"syslog"`
}

// configV6 server configuration version '6'.
Expand Down Expand Up @@ -285,6 +297,12 @@ type serverConfigV9 struct {
rwMutex *sync.RWMutex
}

type loggerV7 struct {
sync.RWMutex
Console consoleLoggerV1 `json:"console"`
File fileLoggerV1 `json:"file"`
}

// serverConfigV10 server configuration version '10' which is like
// version '9' except it drops support of syslog config, and makes the
// RWMutex global (so it does not exist in this struct).
Expand All @@ -296,7 +314,7 @@ type serverConfigV10 struct {
Region string `json:"region"`

// Additional error logging configuration.
Logger logger `json:"logger"`
Logger loggerV7 `json:"logger"`

// Notification queue configuration.
Notify notifierV1 `json:"notify"`
Expand Down Expand Up @@ -324,7 +342,7 @@ type serverConfigV11 struct {
Region string `json:"region"`

// Additional error logging configuration.
Logger logger `json:"logger"`
Logger loggerV7 `json:"logger"`

// Notification queue configuration.
Notify notifierV1 `json:"notify"`
Expand All @@ -340,7 +358,7 @@ type serverConfigV12 struct {
Region string `json:"region"`

// Additional error logging configuration.
Logger logger `json:"logger"`
Logger loggerV7 `json:"logger"`

// Notification queue configuration.
Notify notifierV2 `json:"notify"`
Expand All @@ -356,7 +374,7 @@ type serverConfigV13 struct {
Region string `json:"region"`

// Additional error logging configuration.
Logger *logger `json:"logger"`
Logger *loggerV7 `json:"logger"`

// Notification queue configuration.
Notify *notifier `json:"notify"`
Expand All @@ -373,7 +391,24 @@ type serverConfigV14 struct {
Browser string `json:"browser"`

// Additional error logging configuration.
Logger *logger `json:"logger"`
Logger *loggerV7 `json:"logger"`

// Notification queue configuration.
Notify *notifier `json:"notify"`
}

// serverConfigV15 server configuration version '15' which is like
// version '14' except it adds mysql support
type serverConfigV15 struct {
Version string `json:"version"`

// S3 API configuration.
Credential credential `json:"credential"`
Region string `json:"region"`
Browser string `json:"browser"`

// Additional error logging configuration.
Logger *loggerV7 `json:"logger"`

// Notification queue configuration.
Notify *notifier `json:"notify"`
Expand Down

0 comments on commit 11e15f9

Please sign in to comment.