Skip to content

Commit

Permalink
chore: nest analytical storage backends under top-level storage key
Browse files Browse the repository at this point in the history
  • Loading branch information
yquansah committed Feb 5, 2024
1 parent 5c73f4b commit 561aba4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
11 changes: 8 additions & 3 deletions internal/config/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import (
// AnalyticsConfig defines the configuration for various mechanisms for
// reporting and querying analytical data for Flipt.
type AnalyticsConfig struct {
Storage AnalyticsStorageConfig `json:"storage,omitempty" mapstructure:"storage" yaml:"storage,omitempty"`
Buffer BufferConfig `json:"buffer,omitempty" mapstructure:"buffer" yaml:"buffer,omitempty"`
}

// AnalyticsStorageConfig is a collection of configuration option for storage backends.
type AnalyticsStorageConfig struct {
Clickhouse ClickhouseConfig `json:"clickhouse,omitempty" mapstructure:"clickhouse" yaml:"clickhouse,omitempty"`
Buffer BufferConfig `json:"buffer,omitempty" mapstructure:"buffer" yaml:"buffer,omitempty"`
}

// ClickhouseConfig defines the connection details for connecting Flipt to Clickhouse.
Expand All @@ -24,7 +29,7 @@ type ClickhouseConfig struct {
}

func (a *AnalyticsConfig) Enabled() bool {
return a.Clickhouse.Enabled
return a.Storage.Clickhouse.Enabled
}

func (c *ClickhouseConfig) Auth() clickhouse.Auth {
Expand Down Expand Up @@ -52,7 +57,7 @@ func (a *AnalyticsConfig) setDefaults(v *viper.Viper) error {
}

func (a *AnalyticsConfig) validate() error {
if a.Clickhouse.Enabled && a.Clickhouse.URL == "" {
if a.Storage.Clickhouse.Enabled && a.Storage.Clickhouse.URL == "" {
return errors.New("clickhouse url not provided")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
analytics:
enabled: true
buffer:
flush_period: "5s"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
analytics:
enabled: true
clickhouse:
enabled: true
storage:
clickhouse:
enabled: true
2 changes: 1 addition & 1 deletion internal/server/analytics/clickhouse/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func New(logger *zap.Logger, cfg *config.Config, forceMigrate bool) (*Client, er
return
}

connection, err := connect(cfg.Analytics.Clickhouse)
connection, err := connect(cfg.Analytics.Storage.Clickhouse)
if err != nil {
clickhouseErr = err
return
Expand Down
6 changes: 3 additions & 3 deletions internal/storage/sql/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ func open(cfg config.Config, opts Options) (*sql.DB, Driver, error) {
// openAnalytics is a convenience function of providing a database.sql instance for
// an analytics database.
func openAnalytics(cfg config.Config) (*sql.DB, Driver, error) {
if cfg.Analytics.Clickhouse.Enabled {
if cfg.Analytics.Storage.Clickhouse.Enabled {
db := clickhouse.OpenDB(&clickhouse.Options{
Addr: []string{cfg.Analytics.Clickhouse.URL},
Auth: cfg.Analytics.Clickhouse.Auth(),
Addr: []string{cfg.Analytics.Storage.Clickhouse.URL},
Auth: cfg.Analytics.Storage.Clickhouse.Auth(),
})

return db, Clickhouse, nil
Expand Down

0 comments on commit 561aba4

Please sign in to comment.