Documentation ¶
Index ¶
- type BaseWorker
- type Broker
- type PendingEvaluations
- func (p PendingEvaluations) GetEvaluation(evalID string) (int, *sdk.ScalingEvaluation)
- func (p PendingEvaluations) Len() int
- func (p PendingEvaluations) Less(i, j int) bool
- func (p *PendingEvaluations) Pop() interface{}
- func (p *PendingEvaluations) Push(e interface{})
- func (p PendingEvaluations) Swap(i, j int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseWorker ¶
type BaseWorker struct {
// contains filtered or unexported fields
}
Worker is responsible for executing a policy evaluation request.
func NewBaseWorker ¶
func NewBaseWorker(l hclog.Logger, pm *manager.PluginManager, m *policy.Manager, b *Broker, queue string) *BaseWorker
NewBaseWorker returns a new BaseWorker instance.
func (*BaseWorker) Run ¶
func (w *BaseWorker) Run(ctx context.Context)
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker stores, dedups and control access to policy evaluation requests.
A few notes on the inner workings of the broker:
`pendingEvals` has a key for every policy type (queue) and a heap of evals as value.
`enqueuedEvals` has an eval ID as key and a dequeue counter as value.
`enqueuedPolicies` has a policy ID as key and the corresponding eval ID as value.
evals are either in `pendingEvals` or `unack`, but never in both.
evals start in `pendingEvals` and move to `unack` when dequeued.
evals in `unack` are removed when the eval is ACK'd or the delivery limit is reached.
evals in `unack` are moved back to `pendingEvals` if the eval is NACK'd.
the eval is updated if a new eval is enqueued for the same policy.
eval IDs are stored as keys in `enqueuedEvals` when an eval is enqueued.
the eval ID key remains in `enqueuedEvals` until the eval is ACK'd, the delivery limit is reached or a newer eval for the same policy is enqueued.
the value for an entry in `enqueuedEvals` is incremented by one every time the corresponding policy is dequeued.
policy IDs are stored as keys in `enqueuedPolicies` when an eval is enqueued.
the policy ID remains in `enqueuedPolicies` until the eval is ACK'd or the delivery limit is reached.
the value for the policy ID is the ID of the eval that was enqueued.
the value for the policy ID is updated if a newer eval for the policy is enqueued.
func (*Broker) Enqueue ¶
func (b *Broker) Enqueue(eval *sdk.ScalingEvaluation)
Enqueue adds an eval to the broker.
type PendingEvaluations ¶
type PendingEvaluations []*sdk.ScalingEvaluation
PendingEvaluations is a list of waiting evaluations. We implement the container/heap interface so that this is a priority queue
func (PendingEvaluations) GetEvaluation ¶
func (p PendingEvaluations) GetEvaluation(evalID string) (int, *sdk.ScalingEvaluation)
func (PendingEvaluations) Len ¶
func (p PendingEvaluations) Len() int
Len is for the sorting interface
func (PendingEvaluations) Less ¶
func (p PendingEvaluations) Less(i, j int) bool
Less is for the sorting interface. We flip the check so that the "min" in the min-heap is the element with the highest priority
func (*PendingEvaluations) Pop ¶
func (p *PendingEvaluations) Pop() interface{}
Pop is used to remove an evaluation from the slice
func (*PendingEvaluations) Push ¶
func (p *PendingEvaluations) Push(e interface{})
Push is used to add a new evaluation to the slice
func (PendingEvaluations) Swap ¶
func (p PendingEvaluations) Swap(i, j int)
Swap is for the sorting interface