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

Commit

Permalink
Fix deepcopy-gen errors.
Browse files Browse the repository at this point in the history
Signed-off-by: Harkishen-Singh <[email protected]>
  • Loading branch information
Harkishen-Singh committed Dec 16, 2022
1 parent 25f9997 commit b1dff69
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/dataset/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/dataset/deepcopy_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 14 additions & 15 deletions pkg/rollup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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"`
}

Expand All @@ -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"]
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down

0 comments on commit b1dff69

Please sign in to comment.