From b1dff698eb48ba66ae5677ad455485e5edde66e2 Mon Sep 17 00:00:00 2001 From: Harkishen-Singh Date: Fri, 16 Dec 2022 13:19:47 +0530 Subject: [PATCH] Fix deepcopy-gen errors. Signed-off-by: Harkishen-Singh --- pkg/dataset/config.go | 2 +- pkg/dataset/deepcopy_generated.go | 4 ++++ pkg/rollup/config.go | 29 ++++++++++++++--------------- pkg/runner/client.go | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/pkg/dataset/config.go b/pkg/dataset/config.go index ca0938c360..1079cb3d15 100644 --- a/pkg/dataset/config.go +++ b/pkg/dataset/config.go @@ -68,7 +68,7 @@ func NewConfig(contents string) (cfg Config, err error) { func (c *Config) Apply(ctx context.Context, conn *pgx.Conn) error { c.applyDefaults() - if c.Metrics.Rollups != nil { + if c.Metrics.Rollups.Enabled { if err := c.Metrics.Rollups.Apply(ctx, conn); err != nil { return fmt.Errorf("error applying configuration for downsampling: %w", err) } diff --git a/pkg/dataset/deepcopy_generated.go b/pkg/dataset/deepcopy_generated.go index d018fcd394..c7b9fbb1af 100644 --- a/pkg/dataset/deepcopy_generated.go +++ b/pkg/dataset/deepcopy_generated.go @@ -35,6 +35,10 @@ func (in *Metrics) DeepCopyInto(out *Metrics) { *out = new(bool) **out = **in } + if in.Rollups != nil { + in, out := &in.Rollups, &out.Rollups + *out = (*in).DeepCopy() + } return } diff --git a/pkg/rollup/config.go b/pkg/rollup/config.go index d1794bf3b5..3c86a985aa 100644 --- a/pkg/rollup/config.go +++ b/pkg/rollup/config.go @@ -25,9 +25,7 @@ const ( ) var ( - defaultDownsampleState = false - useDefaultResolution = false - systemResolution = map[string]Definition{ + systemResolution = map[string]Definition{ short: { Resolution: day.Duration(5 * time.Minute), Retention: day.Duration(90 * 24 * time.Hour), @@ -40,8 +38,8 @@ var ( ) type Config struct { - Enabled *bool `yaml:"enabled,omitempty"` - UseDefaultResolution *bool `yaml:"use_default_resolution"` + Enabled bool `yaml:"enabled,omitempty"` + UseDefaultResolution bool `yaml:"use_default_resolution"` Resolutions `yaml:"resolutions,omitempty"` } @@ -54,19 +52,17 @@ type Definition struct { type Resolutions map[string]Definition func (d *Config) Apply(ctx context.Context, conn *pgx.Conn) error { - d.applyDefaults() - if containsSystemResolutions(d.Resolutions) { return fmt.Errorf("'short' and 'long' are system resolutions. These cannot be applied as rollup labels") } - log.Info("msg", fmt.Sprintf("Setting automatic metric downsample to %t", *d.Enabled)) + log.Info("msg", fmt.Sprintf("Setting automatic metric downsample to %t", d.Enabled)) if _, err := conn.Exec(context.Background(), setDefaultDownsampleStateSQL, d.Enabled); err != nil { return err } - if *d.Enabled { - if *d.UseDefaultResolution { + if d.Enabled { + if d.UseDefaultResolution { d.Resolutions["short"] = systemResolution["short"] d.Resolutions["long"] = systemResolution["long"] } @@ -77,13 +73,16 @@ func (d *Config) Apply(ctx context.Context, conn *pgx.Conn) error { return nil } -func (d *Config) applyDefaults() { - if d.Enabled == nil { - d.Enabled = &defaultDownsampleState +func (d *Config) DeepCopy() *Config { + out := Config{ + Enabled: d.Enabled, + UseDefaultResolution: d.UseDefaultResolution, + Resolutions: make(Resolutions, len(d.Resolutions)), } - if d.UseDefaultResolution == nil { - d.UseDefaultResolution = &useDefaultResolution + for k, v := range d.Resolutions { + out.Resolutions[k] = v } + return &out } func containsSystemResolutions(r Resolutions) bool { diff --git a/pkg/runner/client.go b/pkg/runner/client.go index 3f77769859..7f5cae1082 100644 --- a/pkg/runner/client.go +++ b/pkg/runner/client.go @@ -166,7 +166,7 @@ func CreateClient(r prometheus.Registerer, cfg *Config) (*pgclient.Client, error cfg.APICfg.MultiTenancy = multiTenancy } - if (cfg.DatasetCfg != dataset.Config{}) { + if cfg.DatasetCfg != (dataset.Config{}) { if cfg.DatasetConfig != "" { log.Warn("msg", "Ignoring `startup.dataset.config` in favor of the newer `startup.dataset` config option since both were set.") }