Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Remove withTimescaleDB option from dataset configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesGuthrie committed Sep 29, 2022
1 parent 5dc588f commit 361b96c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 41 deletions.
16 changes: 3 additions & 13 deletions pkg/dataset/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ var (
type Config struct {
Metrics `yaml:"metrics"`
Traces `yaml:"traces"`

withTimescaleDB bool
}

// Metrics contains dataset configuration options for metrics data.
Expand All @@ -52,11 +50,9 @@ type Traces struct {
RetentionPeriod DayDuration `yaml:"default_retention_period"`
}

// NewConfig creates a new dataset config based on the configuration YAML contents and
// whether or now we are running TimescaleDB (used for determining default compression setting).
func NewConfig(contents string, withTimescaleDB bool) (cfg Config, err error) {
// NewConfig creates a new dataset config based on the configuration YAML contents.
func NewConfig(contents string) (cfg Config, err error) {
err = yaml.Unmarshal([]byte(contents), &cfg)
cfg.withTimescaleDB = withTimescaleDB
return cfg, err
}

Expand Down Expand Up @@ -94,13 +90,7 @@ func (c *Config) applyDefaults() {
c.Metrics.ChunkInterval = DayDuration(defaultMetricChunkInterval)
}
if c.Metrics.Compression == nil {
switch c.withTimescaleDB {
case false:
// No TSDB, no compression.
c.Metrics.Compression = &c.withTimescaleDB
default:
c.Metrics.Compression = &defaultMetricCompressionVar
}
c.Metrics.Compression = &defaultMetricCompressionVar
}
if c.Metrics.HALeaseRefresh <= 0 {
c.Metrics.HALeaseRefresh = DayDuration(defaultMetricHALeaseRefresh)
Expand Down
25 changes: 2 additions & 23 deletions pkg/dataset/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func TestNewConfig(t *testing.T) {
input: `metrics:
default_retention_period: 3d2h`,
cfg: Config{
withTimescaleDB: true,
Metrics: Metrics{
RetentionPeriod: DayDuration(((3 * 24) + 2) * time.Hour),
},
Expand All @@ -61,7 +60,6 @@ func TestNewConfig(t *testing.T) {
traces:
default_retention_period: 15d`,
cfg: Config{
withTimescaleDB: true,
Metrics: Metrics{
ChunkInterval: DayDuration(3 * time.Hour),
Compression: &testCompressionSetting,
Expand All @@ -79,7 +77,7 @@ traces:
for _, c := range testCases {
t.Run(c.name, func(t *testing.T) {

cfg, err := NewConfig(c.input, true)
cfg, err := NewConfig(c.input)

if c.err != "" {
require.EqualError(t, err, c.err)
Expand All @@ -92,13 +90,12 @@ traces:
}

func TestApplyDefaults(t *testing.T) {
c := Config{withTimescaleDB: true}
c := Config{}
c.applyDefaults()

require.Equal(
t,
Config{
withTimescaleDB: true,
Metrics: Metrics{
ChunkInterval: DayDuration(defaultMetricChunkInterval),
Compression: &defaultMetricCompressionVar,
Expand Down Expand Up @@ -130,22 +127,4 @@ func TestApplyDefaults(t *testing.T) {
copyConfig.applyDefaults()

require.Equal(t, untouched, copyConfig)

// No TSDB, no compression by default.
c = Config{withTimescaleDB: false}
noCompression := false
c.applyDefaults()

require.Equal(t, c, Config{
Metrics: Metrics{
ChunkInterval: DayDuration(defaultMetricChunkInterval),
Compression: &noCompression,
HALeaseRefresh: DayDuration(defaultMetricHALeaseRefresh),
HALeaseTimeout: DayDuration(defaultMetricHALeaseTimeout),
RetentionPeriod: DayDuration(defaultMetricRetentionPeriod),
},
Traces: Traces{
RetentionPeriod: DayDuration(defaultTraceRetentionPeriod),
},
})
}
8 changes: 4 additions & 4 deletions pkg/runner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func CreateClient(r prometheus.Registerer, cfg *Config) (*pgclient.Client, error
}
}

isTimescaleDB, isLicenseOSS, err := getDatabaseDetails(conn)
_, isLicenseOSS, err := getDatabaseDetails(conn)
if err != nil {
return nil, fmt.Errorf("fetching license information: %w", err)
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func CreateClient(r prometheus.Registerer, cfg *Config) (*pgclient.Client, error
}

if cfg.DatasetConfig != "" {
err = ApplyDatasetConfig(conn, cfg.DatasetConfig, isTimescaleDB)
err = ApplyDatasetConfig(conn, cfg.DatasetConfig)
if err != nil {
return nil, fmt.Errorf("error applying dataset configuration: %w", err)
}
Expand Down Expand Up @@ -226,8 +226,8 @@ func isBGWLessThanDBs(conn *pgx.Conn) (bool, error) {
return false, nil
}

func ApplyDatasetConfig(conn *pgx.Conn, cfgFilename string, withTimescaleDB bool) error {
cfg, err := dataset.NewConfig(cfgFilename, withTimescaleDB)
func ApplyDatasetConfig(conn *pgx.Conn, cfgFilename string) error {
cfg, err := dataset.NewConfig(cfgFilename)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/end_to_end_tests/config_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestDatasetConfigApply(t *testing.T) {
require.Equal(t, 10*24*time.Hour, getTracesDefaultRetention(t, pgxConn))

// Set to default if chunk interval is not specified.
cfg, err = dataset.NewConfig("", true)
cfg, err = dataset.NewConfig("")
require.NoError(t, err)

err = cfg.Apply(pgxConn)
Expand Down

0 comments on commit 361b96c

Please sign in to comment.