updates

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

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

Variables

View Source
var DefaultBatchSize = runtime.GOMAXPROCS(0)

Functions

func NewLocalLockSource added in v1.1.0

func NewLocalLockSource() *localLockSource

NewLocalLockSource provides locks backed by local concurrency primitives.

Types

type Configs

type Configs map[string]driver.ConfigUnmarshaler

type LockSource added in v0.4.2

type LockSource interface {
	TryLock(context.Context, string) (context.Context, context.CancelFunc)
	Lock(context.Context, string) (context.Context, context.CancelFunc)
}

LockSource abstracts over how locks are implemented.

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

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 added in v0.4.2

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

Notes

Bugs

  • The API provided by localLockSource does not respect the parent context cancellation when waiting for a lock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL