Skip to content

Commit

Permalink
refactor!: Change Database configuration to be single instance (#4308)
Browse files Browse the repository at this point in the history
* refactor!: Change Database configuration to be single instance

BREAKING CHANGE: Database configuration for services has changed from a Map to a single instance

closes #4131

Signed-off-by: Leonard Goodell <leonard.goodell@intel.com>
  • Loading branch information
Lenny Goodell authored Jan 26, 2023
1 parent 228e514 commit a37026e
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 102 deletions.
9 changes: 4 additions & 5 deletions cmd/core-common-config-bootstrapper/res/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ all-services:
Type: "consul"

Databases:
Primary:
Host: "localhost"
Port: 6379
Timeout: 5000
Type: "redisdb"
Host: "localhost"
Port: 6379
Timeout: 5000
Type: "redisdb"

MessageBus:
Protocol: "redis"
Expand Down
13 changes: 6 additions & 7 deletions cmd/core-data/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ Type = "consul"

[Clients] # Core data no longer dependent on "Client" services

[Databases]
[Databases.Primary]
Host = "localhost"
Name = "coredata"
Port = 6379
Timeout = 5000
Type = "redisdb"
[Database]
Host = "localhost"
Name = "coredata"
Port = 6379
Timeout = 5000
Type = "redisdb"

[MessageBus]
Protocol = "redis"
Expand Down
15 changes: 6 additions & 9 deletions cmd/core-metadata/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,12 @@ Type = "consul"
Host = "localhost"
Port = 59860

[Databases]
[Databases.Primary]
Host = "localhost"
Name = "metadata"
Password = "password"
Username = "meta"
Port = 6379
Timeout = 5000
Type = "redisdb"
[Database]
Host = "localhost"
Name = "metadata"
Port = 6379
Timeout = 5000
Type = "redisdb"

[Notifications]
PostDeviceChanges = false
Expand Down
17 changes: 8 additions & 9 deletions cmd/security-bootstrapper/res-bootstrap-redis/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@

LogLevel = "INFO"

[Databases]
[Databases.Primary]
Host = "localhost"
Name = "" ## Unused
Password = "" ## Will be set from value in Vault
Username = "" ## Will be set from value in Vault
Port = 6379
Timeout = 5000
Type = "redisdb"
[Database]
Host = "localhost"
Name = "" ## Unused
Password = "" ## Will be set from value in Vault
Username = "" ## Will be set from value in Vault
Port = 6379
Timeout = 5000
Type = "redisdb"

[DatabaseConfig]
Path = "/path/to/redis/conf/dir"
Expand Down
2 changes: 1 addition & 1 deletion cmd/security-bootstrapper/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LogLevel = "INFO"
[StageGate.SecretStoreSetup.Tokens]
ReadyPort = 54322
[StageGate.Database]
# this is intended to be the same as Database.Primary.Host/.Port for other services
# this is intended to be the same as Database.Host/.Port for other services
Host = "edgex-redis"
Port = 6379
ReadyPort = 54323
Expand Down
17 changes: 8 additions & 9 deletions cmd/security-spiffe-token-provider/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ Host = "localhost"
Port = 8500
Type = "consul"

[Databases]
[Databases.Primary]
Host = "localhost"
Name = "coredata"
Port = 6379
Timeout = 5000
Type = "redisdb"
[Database]
Host = "localhost"
Name = "coredata"
Port = 6379
Timeout = 5000
Type = "redisdb"

[SPIFFE]
EndpointSocket = "/tmp/edgex/secrets/spiffe/public/api.sock"
TrustDomain = "edgexfoundry.org"
EndpointSocket = "/tmp/edgex/secrets/spiffe/public/api.sock"
TrustDomain = "edgexfoundry.org"
13 changes: 6 additions & 7 deletions cmd/support-notifications/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ Host = "localhost"
Port = 8500
Type = "consul"

[Databases]
[Databases.Primary]
Host = "localhost"
Name = "notifications"
Port = 6379
Timeout = 5000
Type = "redisdb"
[Database]
Host = "localhost"
Name = "notifications"
Port = 6379
Timeout = 5000
Type = "redisdb"

[Smtp]
Host = "smtp.gmail.com"
Expand Down
13 changes: 6 additions & 7 deletions cmd/support-scheduler/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ Host = "localhost"
Port = 8500
Type = "consul"

[Databases]
[Databases.Primary]
Host = "localhost"
Name = "scheduler"
Port = 6379
Timeout = 5000
Type = "redisdb"
[Database]
Host = "localhost"
Name = "scheduler"
Port = 6379
Timeout = 5000
Type = "redisdb"

[Intervals]
[Intervals.Midnight]
Expand Down
8 changes: 4 additions & 4 deletions internal/core/data/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ConfigurationStruct struct {
Writable WritableInfo
MessageBus bootstrapConfig.MessageBusInfo
Clients map[string]bootstrapConfig.ClientInfo
Databases map[string]bootstrapConfig.Database
Database bootstrapConfig.Database
Registry bootstrapConfig.RegistryInfo
Service bootstrapConfig.ServiceInfo
MaxEventSize int64
Expand Down Expand Up @@ -89,9 +89,9 @@ func (c *ConfigurationStruct) GetRegistryInfo() bootstrapConfig.RegistryInfo {
return c.Registry
}

// GetDatabaseInfo returns a database information map.
func (c *ConfigurationStruct) GetDatabaseInfo() map[string]bootstrapConfig.Database {
return c.Databases
// GetDatabaseInfo returns a database information.
func (c *ConfigurationStruct) GetDatabaseInfo() bootstrapConfig.Database {
return c.Database
}

// GetInsecureSecrets returns the service's InsecureSecrets.
Expand Down
8 changes: 4 additions & 4 deletions internal/core/metadata/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
type ConfigurationStruct struct {
Writable WritableInfo
Clients map[string]bootstrapConfig.ClientInfo
Databases map[string]bootstrapConfig.Database
Database bootstrapConfig.Database
Notifications NotificationInfo
Registry bootstrapConfig.RegistryInfo
Service bootstrapConfig.ServiceInfo
Expand Down Expand Up @@ -115,9 +115,9 @@ func (c *ConfigurationStruct) GetRegistryInfo() bootstrapConfig.RegistryInfo {
return c.Registry
}

// GetDatabaseInfo returns a database information map.
func (c *ConfigurationStruct) GetDatabaseInfo() map[string]bootstrapConfig.Database {
return c.Databases
// GetDatabaseInfo returns a database information.
func (c *ConfigurationStruct) GetDatabaseInfo() bootstrapConfig.Database {
return c.Database
}

// GetInsecureSecrets returns the service's InsecureSecrets.
Expand Down
5 changes: 2 additions & 3 deletions internal/pkg/bootstrap/handlers/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
bootstrapConfig "github.com/edgexfoundry/go-mod-bootstrap/v3/config"
"github.com/edgexfoundry/go-mod-bootstrap/v3/di"
"github.com/edgexfoundry/go-mod-core-contracts/v3/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v3/common"
)

// httpServer defines the contract used to determine whether or not the http httpServer is running.
Expand Down Expand Up @@ -49,7 +48,7 @@ func NewDatabase(httpServer httpServer, database bootstrapInterfaces.Database, d
func (d Database) newDBClient(
lc logger.LoggingClient,
credentials bootstrapConfig.Credentials) (interfaces.DBClient, error) {
databaseInfo := d.database.GetDatabaseInfo()[common.Primary]
databaseInfo := d.database.GetDatabaseInfo()
switch databaseInfo.Type {
case "redisdb":
return redis.NewClient(
Expand Down Expand Up @@ -79,7 +78,7 @@ func (d Database) BootstrapHandler(
for startupTimer.HasNotElapsed() {
var err error

secrets, err := secretProvider.GetSecret(d.database.GetDatabaseInfo()[common.Primary].Type)
secrets, err := secretProvider.GetSecret(d.database.GetDatabaseInfo().Type)
if err == nil {
credentials = bootstrapConfig.Credentials{
Username: secrets[secret.UsernameKey],
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/bootstrap/interfaces/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ import "github.com/edgexfoundry/go-mod-bootstrap/v3/config"

// Database interface provides an abstraction for obtaining the database configuration information.
type Database interface {
// GetDatabaseInfo returns a database information map.
GetDatabaseInfo() map[string]config.Database
// GetDatabaseInfo returns a database information.
GetDatabaseInfo() config.Database
}
8 changes: 4 additions & 4 deletions internal/security/bootstrapper/redis/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// the runtime extension of the static configuration.
type ConfigurationStruct struct {
LogLevel string
Databases map[string]bootstrapConfig.Database
Database bootstrapConfig.Database
DatabaseConfig DatabaseBootstrapConfigInfo
}

Expand Down Expand Up @@ -74,9 +74,9 @@ func (c *ConfigurationStruct) GetRegistryInfo() bootstrapConfig.RegistryInfo {
return bootstrapConfig.RegistryInfo{}
}

// GetDatabaseInfo returns a database information map.
func (c *ConfigurationStruct) GetDatabaseInfo() map[string]bootstrapConfig.Database {
return c.Databases
// GetDatabaseInfo returns a database information.
func (c *ConfigurationStruct) GetDatabaseInfo() bootstrapConfig.Database {
return c.Database
}

// GetInsecureSecrets returns the service's InsecureSecrets which this service doesn't support
Expand Down
3 changes: 1 addition & 2 deletions internal/security/bootstrapper/redis/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
bootstrapConfig "github.com/edgexfoundry/go-mod-bootstrap/v3/config"
"github.com/edgexfoundry/go-mod-bootstrap/v3/di"
"github.com/edgexfoundry/go-mod-core-contracts/v3/clients/logger"
"github.com/edgexfoundry/go-mod-core-contracts/v3/common"
)

const (
Expand Down Expand Up @@ -68,7 +67,7 @@ func (handler *Handler) GetCredentials(ctx context.Context, _ *sync.WaitGroup, s

for startupTimer.HasNotElapsed() {
// retrieve database credentials from secretstore
secrets, err := secretProvider.GetSecret(config.Databases[common.Primary].Type)
secrets, err := secretProvider.GetSecret(config.Database.Type)
if err == nil {
credentials.Username = secrets[secret.UsernameKey]
credentials.Password = secrets[secret.PasswordKey]
Expand Down
8 changes: 4 additions & 4 deletions internal/security/spiffetokenprovider/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ConfigurationStruct struct {
Writable WritableInfo
MessageBus bootstrapConfig.MessageBusInfo
Clients map[string]bootstrapConfig.ClientInfo
Databases map[string]bootstrapConfig.Database
Database bootstrapConfig.Database
Registry bootstrapConfig.RegistryInfo
Service bootstrapConfig.ServiceInfo
Spiffe SpiffeInfo
Expand Down Expand Up @@ -96,9 +96,9 @@ func (c *ConfigurationStruct) GetRegistryInfo() bootstrapConfig.RegistryInfo {
return c.Registry
}

// GetDatabaseInfo returns a database information map.
func (c *ConfigurationStruct) GetDatabaseInfo() map[string]bootstrapConfig.Database {
return c.Databases
// GetDatabaseInfo returns a database information.
func (c *ConfigurationStruct) GetDatabaseInfo() bootstrapConfig.Database {
return c.Database
}

// GetInsecureSecrets returns the service's InsecureSecrets.
Expand Down
8 changes: 4 additions & 4 deletions internal/support/notifications/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
type ConfigurationStruct struct {
Writable WritableInfo
Clients map[string]bootstrapConfig.ClientInfo
Databases map[string]bootstrapConfig.Database
Database bootstrapConfig.Database
Registry bootstrapConfig.RegistryInfo
Service bootstrapConfig.ServiceInfo
MessageBus bootstrapConfig.MessageBusInfo
Expand Down Expand Up @@ -118,9 +118,9 @@ func (c *ConfigurationStruct) GetRegistryInfo() bootstrapConfig.RegistryInfo {
return c.Registry
}

// GetDatabaseInfo returns a database information map.
func (c *ConfigurationStruct) GetDatabaseInfo() map[string]bootstrapConfig.Database {
return c.Databases
// GetDatabaseInfo returns a database information.
func (c *ConfigurationStruct) GetDatabaseInfo() bootstrapConfig.Database {
return c.Database
}

// GetInsecureSecrets returns the service's InsecureSecrets.
Expand Down
6 changes: 3 additions & 3 deletions internal/support/scheduler/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
type ConfigurationStruct struct {
Writable WritableInfo
Clients map[string]bootstrapConfig.ClientInfo
Databases map[string]bootstrapConfig.Database
Database bootstrapConfig.Database
Registry bootstrapConfig.RegistryInfo
Service bootstrapConfig.ServiceInfo
MessageBus bootstrapConfig.MessageBusInfo
Expand Down Expand Up @@ -143,8 +143,8 @@ func (c *ConfigurationStruct) GetRegistryInfo() bootstrapConfig.RegistryInfo {
}

// GetDatabaseInfo returns a database information map.
func (c *ConfigurationStruct) GetDatabaseInfo() map[string]bootstrapConfig.Database {
return c.Databases
func (c *ConfigurationStruct) GetDatabaseInfo() bootstrapConfig.Database {
return c.Database
}

// GetInsecureSecrets returns the service's InsecureSecrets.
Expand Down
17 changes: 8 additions & 9 deletions openapi/v2/core-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1852,15 +1852,14 @@ paths:
Host: "edgex-core-metadata"
Port: 59881
Protocol: "http"
Databases:
Primary:
Username: "core"
Password: "password"
Type: "redisdb"
Timeout: 5000
Host: "edgex-redis"
Port: 6379
Name: "coredata"
Database:
Username: "core"
Password: "password"
Type: "redisdb"
Timeout: 5000
Host: "edgex-redis"
Port: 6379
Name: "coredata"
Logging:
EnableRemote: false
File: ""
Expand Down
17 changes: 8 additions & 9 deletions openapi/v2/core-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3886,15 +3886,14 @@ paths:
Host: "edgex-support-notifications"
Port: 59860
Protocol: "http"
Databases:
Primary:
Username: "meta"
Password: "password"
Type: "redisdb"
Timeout: 5000
Host: "edgex-redis"
Port: 6379
Name: "metadata"
Database:
Username: "meta"
Password: "password"
Type: "redisdb"
Timeout: 5000
Host: "edgex-redis"
Port: 6379
Name: "metadata"
Notifications:
Content: "Device update: "
Description: "Metadata device notice"
Expand Down

0 comments on commit a37026e

Please sign in to comment.