policy

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultQueryWindow = time.Minute

DefaultQueryWindow is the value used if `query_window` is not specified in a policy check.

Variables

This section is empty.

Functions

func HandleSourceError added in v0.1.1

func HandleSourceError(name SourceName, err error, errCha chan<- error)

HandleSourceError provides common functionality when a policy source encounters an ephemeral or non-critical error.

Types

type ConfigDefaults added in v0.1.0

type ConfigDefaults struct {
	DefaultEvaluationInterval time.Duration
	DefaultCooldown           time.Duration
}

ConfigDefaults holds default configuration for unspecified values.

type Handler

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

Handler monitors a policy for changes and controls when them are sent for evaluation.

func NewHandler

func NewHandler(ID PolicyID, log hclog.Logger, pm *manager.PluginManager, ps Source) *Handler

NewHandler returns a new handler for a policy.

func (*Handler) Run

func (h *Handler) Run(ctx context.Context, evalCh chan<- *sdk.ScalingEvaluation)

Run starts the handler and periodically sends the policy for evaluation.

This function blocks until the context provided is canceled or the handler is stopped with the Stop() method.

func (*Handler) Stop

func (h *Handler) Stop()

Stop stops the handler and the monitoring Go routine.

type IDMessage added in v0.1.0

type IDMessage struct {
	IDs    []PolicyID
	Source SourceName
}

IDMessage encapsulates the required information that allows the policy manager to launch the correct MonitorPolicy interface function where it needs to handle policies which originate from different sources.

type Manager

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

Manager tracks policies and controls the lifecycle of each policy handler.

func NewManager

func NewManager(log hclog.Logger, ps map[SourceName]Source, pm *manager.PluginManager, mInt time.Duration) *Manager

NewManager returns a new Manager.

func (*Manager) EnforceCooldown

func (m *Manager) EnforceCooldown(id string, t time.Duration)

EnforceCooldown attempts to enforce cooldown on the policy handler representing the passed ID.

func (*Manager) ReloadSources added in v0.1.0

func (m *Manager) ReloadSources()

ReloadSources triggers a reload of all the policy sources.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, evalCh chan<- *sdk.ScalingEvaluation)

Run starts the manager and blocks until the context is canceled. Policies that need to be evaluated are sent in the evalCh.

type MonitorIDsReq added in v0.1.0

type MonitorIDsReq struct {
	ErrCh    chan<- error
	ResultCh chan<- IDMessage
}

type MonitorPolicyReq added in v0.1.0

type MonitorPolicyReq struct {
	ID       PolicyID
	ErrCh    chan<- error
	ReloadCh <-chan struct{}
	ResultCh chan<- sdk.ScalingPolicy
}

type Mutations added in v0.3.4

type Mutations []string

Mutations is a list of human-friendly descriptions of the changes performed by a mutator.

type Mutator added in v0.3.4

type Mutator interface {
	MutatePolicy(*sdk.ScalingPolicy) Mutations
}

Mutator is an interface used to apply changes to a scaling policy.

type NomadAPMMutator added in v0.3.4

type NomadAPMMutator struct{}

NomadAPMMutator handles the special case for zero count cluster scaling since it can't query nodes if there are none running.

func (NomadAPMMutator) MutatePolicy added in v0.3.4

func (m NomadAPMMutator) MutatePolicy(p *sdk.ScalingPolicy) Mutations

type PolicyID

type PolicyID string

PolicyID contains identifying information about a policy, as returned by policy.Source.MonitorIDs()

func (PolicyID) String added in v0.1.0

func (p PolicyID) String() string

String satisfies the Stringer interface.

type Processor added in v0.1.1

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

Processor helps process policies and perform common actions on them when they are discovered from their source.

func NewProcessor added in v0.1.1

func NewProcessor(defaults *ConfigDefaults, apms []string) *Processor

NewProcessor returns a pointer to a new Processor for use.

func (*Processor) ApplyPolicyDefaults added in v0.1.1

func (pr *Processor) ApplyPolicyDefaults(p *sdk.ScalingPolicy)

ApplyPolicyDefaults applies the config defaults to the policy where the operator does not supply the parameter. This can be used for both cluster and task group policies.

func (*Processor) CanonicalizeAPMQuery added in v0.1.1

func (pr *Processor) CanonicalizeAPMQuery(c *sdk.ScalingPolicyCheck, t *sdk.ScalingPolicyTarget)

CanonicalizeAPMQuery takes a short styled Nomad APM check query and creates its fully hydrated internal representation. This is required by the Nomad APM if it is being used as the source. The function can be called without any validation on the check.

func (*Processor) CanonicalizeCheck added in v0.1.1

func (pr *Processor) CanonicalizeCheck(c *sdk.ScalingPolicyCheck, t *sdk.ScalingPolicyTarget)

CanonicalizeCheck sets standardised values on fields.

func (*Processor) ValidatePolicy added in v0.1.1

func (pr *Processor) ValidatePolicy(p *sdk.ScalingPolicy) error

ValidatePolicy performs validation of the policy document returning a list of errors found, if any.

type Source

type Source interface {
	MonitorIDs(ctx context.Context, monitorIDsReq MonitorIDsReq)
	MonitorPolicy(ctx context.Context, monitorPolicyReq MonitorPolicyReq)

	// Name returns the SourceName for the implementation. This helps handlers
	// identify the source implementation which is responsible for policies.
	Name() SourceName

	// ReloadIDsMonitor is used to trigger a reload of the MonitorIDs routine
	// so that config items can be reloaded gracefully without restarting the
	// agent.
	ReloadIDsMonitor()
}

Source is the interface that must be implemented by backends which provide the canonical source for scaling policies.

type SourceName added in v0.1.0

type SourceName string

SourceName differentiates policies from different sources. This allows the policy manager to use the correct Source interface implementation to launch the MonitorPolicy function for the PolicyID.

const (
	// SourceNameNomad is the source for policies that originate from the Nomad
	// scaling policies API.
	SourceNameNomad SourceName = "nomad"

	// SourceNameFile is the source for policies that are loaded from disk.
	SourceNameFile SourceName = "file"

	// SourceNameHA is the source for HA policy sources
	SourceNameHA SourceName = "ha"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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