[MM-60262] Respect config store option when creating platform service (#28038)

* Respect config store option when creating platform service

* Remove ConfigStore from ServiceConfig
Этот коммит содержится в:
Ben Schumacher
2024-08-28 07:02:09 +02:00
коммит произвёл GitHub
родитель 244b7e565b
Коммит 5ff680d20d
5 изменённых файлов: 40 добавлений и 35 удалений

Просмотреть файл

@@ -1542,9 +1542,8 @@ func TestPushNotificationRace(t *testing.T) {
} }
var err error var err error
s.platform, err = platform.New( s.platform, err = platform.New(
platform.ServiceConfig{ platform.ServiceConfig{},
ConfigStore: memoryStore, platform.ConfigStore(memoryStore),
},
platform.SetFileStore(&fmocks.FileBackend{}), platform.SetFileStore(&fmocks.FileBackend{}),
platform.SetExportFileStore(&fmocks.FileBackend{}), platform.SetExportFileStore(&fmocks.FileBackend{}),
platform.StoreOverride(mockStore)) platform.StoreOverride(mockStore))

Просмотреть файл

@@ -31,8 +31,7 @@ import (
// The mandatory fields will be checked during the initialization of the service. // The mandatory fields will be checked during the initialization of the service.
type ServiceConfig struct { type ServiceConfig struct {
// Mandatory fields // Mandatory fields
ConfigStore *config.Store Store store.Store
Store store.Store
// Optional fields // Optional fields
Cluster einterfaces.ClusterInterface Cluster einterfaces.ClusterInterface
} }

Просмотреть файл

@@ -151,10 +151,12 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
*memoryConfig.MetricsSettings.ListenAddress = "localhost:0" *memoryConfig.MetricsSettings.ListenAddress = "localhost:0"
configStore.Set(memoryConfig) configStore.Set(memoryConfig)
ps, err := New(ServiceConfig{ options = append(options, ConfigStore(configStore))
ConfigStore: configStore,
Store: dbStore, ps, err := New(
}, options...) ServiceConfig{
Store: dbStore,
}, options...)
if err != nil { if err != nil {
panic(err) panic(err)
} }

Просмотреть файл

@@ -117,7 +117,6 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
// ConfigStore is and should be handled on a upper level. // ConfigStore is and should be handled on a upper level.
ps := &PlatformService{ ps := &PlatformService{
Store: sc.Store, Store: sc.Store,
configStore: sc.ConfigStore,
clusterIFace: sc.Cluster, clusterIFace: sc.Cluster,
hashSeed: maphash.MakeSeed(), hashSeed: maphash.MakeSeed(),
goroutineExitSignal: make(chan struct{}, 1), goroutineExitSignal: make(chan struct{}, 1),
@@ -137,6 +136,13 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
// Assume the first user account has not been created yet. A call to the DB will later check if this is really the case. // Assume the first user account has not been created yet. A call to the DB will later check if this is really the case.
ps.isFirstUserAccount.Store(true) ps.isFirstUserAccount.Store(true)
// Apply options, some of the options overrides the default config actually.
for _, option := range options {
if err2 := option(ps); err2 != nil {
return nil, fmt.Errorf("failed to apply option: %w", err2)
}
}
// the config store is not set, we need to create a new one // the config store is not set, we need to create a new one
if ps.configStore == nil { if ps.configStore == nil {
innerStore, err := config.NewFileStore("config.json", true) innerStore, err := config.NewFileStore("config.json", true)
@@ -177,13 +183,6 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
return nil, fmt.Errorf("unable to connect to cache provider: %w", err) return nil, fmt.Errorf("unable to connect to cache provider: %w", err)
} }
// Apply options, some of the options overrides the default config actually.
for _, option := range options {
if err2 := option(ps); err2 != nil {
return nil, fmt.Errorf("failed to apply option: %w", err2)
}
}
// Step 2: Start logging. // Step 2: Start logging.
if err2 := ps.initLogging(); err2 != nil { if err2 := ps.initLogging(); err2 != nil {
return nil, fmt.Errorf("failed to initialize logging: %w", err2) return nil, fmt.Errorf("failed to initialize logging: %w", err2)

Просмотреть файл

@@ -35,9 +35,10 @@ func TestReadReplicaDisabledBasedOnLicense(t *testing.T) {
t.Run("Read Replicas with no License", func(t *testing.T) { t.Run("Read Replicas with no License", func(t *testing.T) {
configStore := config.NewTestMemoryStore() configStore := config.NewTestMemoryStore()
configStore.Set(&cfg) configStore.Set(&cfg)
ps, err := New(ServiceConfig{ ps, err := New(
ConfigStore: configStore, ServiceConfig{},
}) ConfigStore(configStore),
)
require.NoError(t, err) require.NoError(t, err)
require.Same(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetReplicaX()) require.Same(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetReplicaX())
require.Len(t, ps.Config().SqlSettings.DataSourceReplicas, 1) require.Len(t, ps.Config().SqlSettings.DataSourceReplicas, 1)
@@ -46,12 +47,14 @@ func TestReadReplicaDisabledBasedOnLicense(t *testing.T) {
t.Run("Read Replicas With License", func(t *testing.T) { t.Run("Read Replicas With License", func(t *testing.T) {
configStore := config.NewTestMemoryStore() configStore := config.NewTestMemoryStore()
configStore.Set(&cfg) configStore.Set(&cfg)
ps, err := New(ServiceConfig{ ps, err := New(
ConfigStore: configStore, ServiceConfig{},
}, func(ps *PlatformService) error { ConfigStore(configStore),
ps.licenseValue.Store(model.NewTestLicense()) func(ps *PlatformService) error {
return nil ps.licenseValue.Store(model.NewTestLicense())
}) return nil
},
)
require.NoError(t, err) require.NoError(t, err)
require.NotSame(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetReplicaX()) require.NotSame(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetReplicaX())
require.Len(t, ps.Config().SqlSettings.DataSourceReplicas, 1) require.Len(t, ps.Config().SqlSettings.DataSourceReplicas, 1)
@@ -60,9 +63,10 @@ func TestReadReplicaDisabledBasedOnLicense(t *testing.T) {
t.Run("Search Replicas with no License", func(t *testing.T) { t.Run("Search Replicas with no License", func(t *testing.T) {
configStore := config.NewTestMemoryStore() configStore := config.NewTestMemoryStore()
configStore.Set(&cfg) configStore.Set(&cfg)
ps, err := New(ServiceConfig{ ps, err := New(
ConfigStore: configStore, ServiceConfig{},
}) ConfigStore(configStore),
)
require.NoError(t, err) require.NoError(t, err)
require.Same(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetSearchReplicaX()) require.Same(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetSearchReplicaX())
require.Len(t, ps.Config().SqlSettings.DataSourceSearchReplicas, 1) require.Len(t, ps.Config().SqlSettings.DataSourceSearchReplicas, 1)
@@ -71,12 +75,14 @@ func TestReadReplicaDisabledBasedOnLicense(t *testing.T) {
t.Run("Search Replicas With License", func(t *testing.T) { t.Run("Search Replicas With License", func(t *testing.T) {
configStore := config.NewTestMemoryStore() configStore := config.NewTestMemoryStore()
configStore.Set(&cfg) configStore.Set(&cfg)
ps, err := New(ServiceConfig{ ps, err := New(
ConfigStore: configStore, ServiceConfig{},
}, func(ps *PlatformService) error { ConfigStore(configStore),
ps.licenseValue.Store(model.NewTestLicense()) func(ps *PlatformService) error {
return nil ps.licenseValue.Store(model.NewTestLicense())
}) return nil
},
)
require.NoError(t, err) require.NoError(t, err)
require.NotSame(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetSearchReplicaX()) require.NotSame(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetSearchReplicaX())
require.Len(t, ps.Config().SqlSettings.DataSourceSearchReplicas, 1) require.Len(t, ps.Config().SqlSettings.DataSourceSearchReplicas, 1)