Skip to content

Commit

Permalink
feat(config): make scylla configs cache update freq configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
karol-kokoszka committed May 8, 2024
1 parent 2ad626a commit a0dcc51
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 17 deletions.
3 changes: 2 additions & 1 deletion pkg/cmd/scylla-manager/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ func (s *server) makeServices(ctx context.Context) error {
}
s.clusterSvc.SetOnChangeListener(s.onClusterChange)

s.configCacheSvc = configcache.NewService(s.clusterSvc, s.clusterSvc.CreateClientNoCache, secretsStore, s.logger)
s.configCacheSvc = configcache.NewService(s.config.ConfigCache, s.clusterSvc, s.clusterSvc.CreateClientNoCache,
secretsStore, s.logger)
s.initConfigCacheSvc(ctx)

s.healthSvc, err = healthcheck.NewService(
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/pkg/errors"
"github.com/scylladb/scylla-manager/v3/pkg/service/configcache"
"github.com/scylladb/scylla-manager/v3/pkg/service/restore"

"github.com/scylladb/scylla-manager/v3/pkg/config"
Expand Down Expand Up @@ -59,6 +60,7 @@ type Config struct {
Database DBConfig `yaml:"database"`
SSL SSLConfig `yaml:"ssl"`
Healthcheck healthcheck.Config `yaml:"healthcheck"`
ConfigCache configcache.Config `yaml:"config_cache"`
Backup backup.Config `yaml:"backup"`
Restore restore.Config `yaml:"restore"`
Repair repair.Config `yaml:"repair"`
Expand Down Expand Up @@ -90,6 +92,7 @@ func DefaultConfig() Config {
Restore: restore.DefaultConfig(),
Repair: repair.DefaultConfig(),
TimeoutConfig: scyllaclient.DefaultTimeoutConfig(),
ConfigCache: configcache.DefaultConfig(),
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/config/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/scylladb/go-log"
"github.com/scylladb/scylla-manager/v3/pkg/service/configcache"
"github.com/scylladb/scylla-manager/v3/pkg/service/restore"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -110,6 +111,9 @@ func TestConfigModification(t *testing.T) {
},
PoolDecayDuration: time.Hour,
},
ConfigCache: configcache.Config{
UpdateFrequency: 5 * time.Minute,
},
}

if diff := cmp.Diff(c, golden, configCmpOpts); diff != "" {
Expand Down
17 changes: 17 additions & 0 deletions pkg/service/configcache/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (C) 2024 ScyllaDB

package configcache

import "time"

// Config specifies the cache service configuration.
type Config struct {
// UpdateFrequency specifies how often to call Scylla for its configuration.
UpdateFrequency time.Duration `yaml:"update_frequency"`
}

func DefaultConfig() Config {
return Config{
UpdateFrequency: 5 * time.Minute,
}
}
19 changes: 5 additions & 14 deletions pkg/service/configcache/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ import (
"github.com/scylladb/scylla-manager/v3/pkg/util/uuid"
)

// ConnectionType defines an enum for different types of configuration.
type ConnectionType int

const (
// CQL defines cql connection type.
CQL ConnectionType = iota
// Alternator defines alternator connection type.
Alternator

updateFrequency = 5 * time.Minute
)

// ConfigCacher is the interface defining the cache behavior.
type ConfigCacher interface {
// Read returns either the host configuration that is currently stored in the cache,
Expand All @@ -51,6 +39,8 @@ type ConfigCacher interface {
// Use svc.Read(clusterID, host) to read the configuration of particular host in given cluster.
// Use svc.Run() to let the cache update itself periodically with the current configuration.
type Service struct {
svcConfig Config

clusterSvc cluster.Servicer
scyllaClient scyllaclient.ProviderFunc
secretsStore store.Store
Expand All @@ -60,8 +50,9 @@ type Service struct {
}

// NewService is the constructor for the cluster config cache service.
func NewService(clusterSvc cluster.Servicer, client scyllaclient.ProviderFunc, secretsStore store.Store, logger log.Logger) ConfigCacher {
func NewService(config Config, clusterSvc cluster.Servicer, client scyllaclient.ProviderFunc, secretsStore store.Store, logger log.Logger) ConfigCacher {
return &Service{
svcConfig: config,
clusterSvc: clusterSvc,
scyllaClient: client,
secretsStore: secretsStore,
Expand Down Expand Up @@ -96,7 +87,7 @@ func (svc *Service) Read(clusterID uuid.UUID, host string) (NodeConfig, error) {

// Run starts the infinity loop responsible for updating the clusters configuration periodically.
func (svc *Service) Run(ctx context.Context) {
freq := time.NewTicker(updateFrequency)
freq := time.NewTicker(svc.svcConfig.UpdateFrequency)

for {
// make sure to shut down when the context is cancelled
Expand Down
2 changes: 2 additions & 0 deletions pkg/service/configcache/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func TestService_Read(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
// Given
svc := Service{
svcConfig: DefaultConfig(),
clusterSvc: &mockClusterServicer{},
scyllaClient: mockProviderFunc,
secretsStore: &mockStore{},
Expand Down Expand Up @@ -109,6 +110,7 @@ func TestService_Read(t *testing.T) {
func TestService_Run(t *testing.T) {
t.Run("validate context cancellation handling", func(t *testing.T) {
svc := Service{
svcConfig: DefaultConfig(),
clusterSvc: &mockClusterServicer{},
scyllaClient: mockProviderFunc,
secretsStore: &mockStore{},
Expand Down
5 changes: 3 additions & 2 deletions pkg/service/healthcheck/service_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestStatus_Ping_Independent_From_REST_Integration(t *testing.T) {
t.Fatal(err)
}

configCacheSvc := configcache.NewService(clusterSvc, scyllaClientProvider, s, logger.Named("config-cache"))
configCacheSvc := configcache.NewService(configcache.DefaultConfig(), clusterSvc, scyllaClientProvider, s, logger.Named("config-cache"))
configCacheSvc.Init(context.Background())

defaultConfigForHealthcheck := DefaultConfig()
Expand Down Expand Up @@ -223,7 +223,8 @@ func testStatusIntegration(t *testing.T, clusterID uuid.UUID, clusterSvc cluster
sc.Transport = hrt
return scyllaclient.NewClient(sc, logger.Named("scylla"))
}
configCacheSvc := configcache.NewService(clusterSvc, scyllaClientProvider, secretsStore, logger.Named("config-cache"))
configCacheSvc := configcache.NewService(configcache.DefaultConfig(), clusterSvc, scyllaClientProvider,
secretsStore, logger.Named("config-cache"))
configCacheSvc.Init(context.Background())

s, err := NewService(
Expand Down

0 comments on commit a0dcc51

Please sign in to comment.