policyeval

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: 16 Imported by: 0

Documentation

Index

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 NewBroker

func NewBroker(l hclog.Logger, timeout time.Duration, deliveryLimit int) *Broker

NewBroker returns a new Broker object.

func (*Broker) Ack

func (b *Broker) Ack(evalID, token string) error

Ack is used to acknowledge the successful completion of an eval.

func (*Broker) Dequeue

func (b *Broker) Dequeue(ctx context.Context, queue string) (*sdk.ScalingEvaluation, string, error)

Dequeue is used to retrieve an eval from the broker.

func (*Broker) Enqueue

func (b *Broker) Enqueue(eval *sdk.ScalingEvaluation)

Enqueue adds an eval to the broker.

func (*Broker) Nack

func (b *Broker) Nack(evalID, token string) error

Nack is used to mark an eval as not completed.

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

Jump to

Keyboard shortcuts

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