Move internal/config#Retention to internal/config#RetentionConfig

This commit is contained in:
Eric Lippmann 2024-05-21 11:57:33 +02:00
parent 3072a10c7f
commit 3e63bbd068
2 changed files with 27 additions and 31 deletions

View file

@ -2,7 +2,10 @@ package config
import (
"github.com/icinga/icingadb/pkg/database"
"github.com/icinga/icingadb/pkg/icingadb/history"
"github.com/icinga/icingadb/pkg/logging"
"github.com/pkg/errors"
"time"
)
// Config defines Icinga DB config.
@ -10,7 +13,7 @@ type Config struct {
Database database.Config `yaml:"database"`
Redis Redis `yaml:"redis"`
Logging logging.Config `yaml:"logging"`
Retention Retention `yaml:"retention"`
Retention RetentionConfig `yaml:"retention"`
}
// Validate checks constraints in the supplied configuration and returns an error if they are violated.
@ -38,3 +41,26 @@ type Flags struct {
// Config is the path to the config file
Config string `short:"c" long:"config" description:"path to config file" required:"true" default:"/etc/icingadb/config.yml"`
}
// RetentionConfig defines configuration for history retention.
type RetentionConfig struct {
HistoryDays uint64 `yaml:"history-days"`
SlaDays uint64 `yaml:"sla-days"`
Interval time.Duration `yaml:"interval" default:"1h"`
Count uint64 `yaml:"count" default:"5000"`
Options history.RetentionOptions `yaml:"options"`
}
// Validate checks constraints in the supplied retention configuration and
// returns an error if they are violated.
func (r *RetentionConfig) Validate() error {
if r.Interval <= 0 {
return errors.New("retention interval must be positive")
}
if r.Count == 0 {
return errors.New("count must be greater than zero")
}
return r.Options.Validate()
}

View file

@ -1,30 +0,0 @@
package config
import (
"github.com/icinga/icingadb/pkg/icingadb/history"
"github.com/pkg/errors"
"time"
)
// Retention defines configuration for history retention.
type Retention struct {
HistoryDays uint64 `yaml:"history-days"`
SlaDays uint64 `yaml:"sla-days"`
Interval time.Duration `yaml:"interval" default:"1h"`
Count uint64 `yaml:"count" default:"5000"`
Options history.RetentionOptions `yaml:"options"`
}
// Validate checks constraints in the supplied retention configuration and
// returns an error if they are violated.
func (r *Retention) Validate() error {
if r.Interval <= 0 {
return errors.New("retention interval must be positive")
}
if r.Count == 0 {
return errors.New("count must be greater than zero")
}
return r.Options.Validate()
}