Skip to content

Commit

Permalink
config: consolidate and document default values
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Nov 4, 2021
1 parent 7bcfc20 commit cc7d8a3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
3 changes: 0 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"net"
)

// DefaultAddress is used if an http_listen_addr is not provided in the config.
const DefaultAddress = ":6060"

// Config is the configuration object for the commands in
// github.com/quay/clair/v4/cmd/...
type Config struct {
Expand Down
29 changes: 29 additions & 0 deletions config/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package config

import "time"

// These are defaults, used in the documented spots.
const (
// DefaultAddress is used if an "http_listen_addr" is not provided in the config.
DefaultAddress = ":6060"
// DefaultScanLockRetry is the default retry period for attempting locks
// during the indexing process. Its name is a historical accident.
DefaultScanLockRetry = 1
// DefaultMatcherPeriod is the default interval for running updaters.
DefaultMatcherPeriod = 30 * time.Minute
// DefaultUpdateRetention is the number of updates per vulnerability
// database to retain.
DefaultUpdateRetention = 10
// DefaultNotifierPollInterval is the default (and minimum) interval for the
// notifier's change poll interval. The notifier will poll the database for
// updated vulnerability databases at this rate.
DefaultNotifierPollInterval = 5 * time.Second
// DefaultNotifierDeliveryInterval is the default (and minimum) interval for
// the notifier's delivery interval. The notifier will attempt to deliver
// outstanding notifications at this rate.
DefaultNotifierDeliveryInterval = 5 * time.Second
)

// BUG(hank) The DefaultNotifierPollInterval is absurdly low.

// BUG(hank) The DefaultNotifierDeliveryInterval is absurdly low.
7 changes: 1 addition & 6 deletions config/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ type Matcher struct {
DisableUpdaters bool `yaml:"disable_updaters" json:"disable_updaters"`
}

const (
DefaultMatcherPeriod = 30 * time.Minute
DefaultMatcherRetention = 10
)

func (m *Matcher) validate(mode Mode) ([]Warning, error) {
if mode != ComboMode && mode != MatcherMode {
return nil, nil
Expand All @@ -72,7 +67,7 @@ func (m *Matcher) validate(mode Mode) ([]Warning, error) {
m.UpdateRetention = 0
case m.UpdateRetention < 2:
// Anything less than 2 gets the default.
m.UpdateRetention = DefaultMatcherRetention
m.UpdateRetention = DefaultUpdateRetention
}
if m.CacheAge == 0 {
m.CacheAge = m.Period
Expand Down
13 changes: 4 additions & 9 deletions config/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,15 @@ type Notifier struct {
Migrations bool `yaml:"migrations" json:"migrations"`
}

const (
notifierDefaultPollInterval = 5 * time.Second
notifierDefaultDeliveryInterval = 5 * time.Second
)

func (n *Notifier) validate(mode Mode) ([]Warning, error) {
if mode != ComboMode && mode != NotifierMode {
return nil, nil
}
if n.PollInterval < 1*time.Second {
n.PollInterval = notifierDefaultPollInterval
n.PollInterval = DefaultNotifierPollInterval
}
if n.DeliveryInterval < 1*time.Second {
n.DeliveryInterval = notifierDefaultDeliveryInterval
n.DeliveryInterval = DefaultNotifierDeliveryInterval
}
switch mode {
case ComboMode:
Expand Down Expand Up @@ -125,13 +120,13 @@ func (n *Notifier) lint() (ws []Warning, err error) {
})
}

if n.PollInterval < notifierDefaultPollInterval {
if n.PollInterval < DefaultNotifierPollInterval {
ws = append(ws, Warning{
path: ".poll_interval",
msg: "interval is very fast: may result in increased workload",
})
}
if n.DeliveryInterval < notifierDefaultDeliveryInterval {
if n.DeliveryInterval < DefaultNotifierDeliveryInterval {
ws = append(ws, Warning{
path: ".delivery_interval",
msg: "interval is very fast: may result in increased workload",
Expand Down

0 comments on commit cc7d8a3

Please sign in to comment.