Documentation ¶
Index ¶
- Constants
- func HandleSourceError(name SourceName, err error, errCha chan<- error)
- type ConfigDefaults
- type Handler
- type IDMessage
- type Manager
- type MonitorIDsReq
- type MonitorPolicyReq
- type PolicyID
- type Processor
- func (pr *Processor) ApplyPolicyDefaults(p *sdk.ScalingPolicy)
- func (pr *Processor) CanonicalizeAPMQuery(c *sdk.ScalingPolicyCheck, t *sdk.ScalingPolicyTarget)
- func (pr *Processor) CanonicalizeCheck(c *sdk.ScalingPolicyCheck, t *sdk.ScalingPolicyTarget)
- func (pr *Processor) ValidatePolicy(p *sdk.ScalingPolicy) error
- type Source
- type SourceName
Constants ¶
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 ¶
NewHandler returns a new handler for a policy.
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 ¶
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.
type MonitorIDsReq ¶ added in v0.1.0
type MonitorPolicyReq ¶ added in v0.1.0
type MonitorPolicyReq struct { ID PolicyID ErrCh chan<- error ReloadCh <-chan struct{} ResultCh chan<- sdk.ScalingPolicy }
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" )