updates

package
Version: v0.4.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultInterval = time.Duration(30 * time.Minute)
)

Variables

View Source
var (
	DefaultBatchSize = runtime.NumCPU()
)

Functions

This section is empty.

Types

type Configs

type Configs map[string]driver.ConfigUnmarshaler

type LockSource

type LockSource interface {
	NewLock() distlock.Locker
}

LockSource abstracts over how locks are implemented.

An online system needs distributed locks, offline use cases can use process-local locks.

func LocalLockSource

func LocalLockSource() LockSource

LocalLockSource provides locks backed by local concurrency primitives.

func PoolLockSource

func PoolLockSource(p *pgxpool.Pool, dur time.Duration) (LockSource, error)

PoolLockSource provides locks backed by Postgres advisory locks.

The provided duration is the retry period, as documented in postgres.NewPool.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager oversees the configuration and invocation of vulnstore updaters.

The Manager may be used in a one-shot fashion, configured to run background jobs, or both.

func NewManager

func NewManager(ctx context.Context, store vulnstore.Updater, locks LockSource, client *http.Client, opts ...ManagerOption) (*Manager, error)

NewManager will return a manager ready to have its Start or Run methods called.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

Run constructs updaters from factories, configures them and runs them in batches.

Run is safe to call at anytime, regardless of whether background updaters are running.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start will run updaters at the given interval.

Start is designed to be ran as a goroutine. Cancel the provided Context to end the updater loop.

Start must only be called once between context cancellations.

type ManagerOption

type ManagerOption func(m *Manager)

ManagerOption specify optional configuration for a Manager. Defaults will be used where options are not provided to the constructor.

func WithBatchSize

func WithBatchSize(n int) ManagerOption

WithBatchSize sets the max number of parallel updaters that will run during an update interval.

func WithConfigs

func WithConfigs(cfgs Configs) ManagerOption

WithConfigs tells the Manager to configure each updater where a configuration is provided.

Configuration of individual updaters is delegated to updater/registry.go Note: this option is optimal when ran after WithEnabled option. However, this option has no strict depedency on others.

func WithEnabled

func WithEnabled(enabled []string) ManagerOption

WithEnabled configures the Manager to only run the specified updater sets.

If enabled == nil all default updater sets will run (same as not providing this option to the constructor at all). If len(enabled) == 0 no default updater sets will run. If len(enabled) > 0 only provided updater sets will be ran.

func WithFactories

func WithFactories(f map[string]driver.UpdaterSetFactory) ManagerOption

WithFactories resets UpdaterSetFactories used by the Manager.

func WithGC

func WithGC(retention int) ManagerOption

WithGC instructs the manager to run garbage collection at the end of an update interval.

The provided retention value informs the manager how many update operations to keep.

func WithInterval

func WithInterval(interval time.Duration) ManagerOption

WithInterval configures the interval at which updaters will be ran. The manager runs all configured updaters during an interval. Setting this duration too low may cause missed update intervals.

func WithOutOfTree

func WithOutOfTree(outOfTree []driver.Updater) ManagerOption

WithOutOfTree allows callers to provide their own out-of-tree updaters.

note: currently we will never configure the outOfTree updater factory. if this changes consider making this option a required to avoid missing configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL