policy

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0 Imports: 23 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// NonePolicy is the name of our no-op policy.
	NonePolicy = "none"
	// DefaultPolicy is the name of our default policy.
	DefaultPolicy = NonePolicy
	// ConfigPath is the configuration module path for the generic policy layer.
	ConfigPath = "policy"
)
View Source
const (
	// ExportedResources is the basename of the file container resources are exported to.
	ExportedResources = "resources.sh"
	// ExportSharedCPUs is the shell variable used to export shared container CPUs.
	ExportSharedCPUs = "SHARED_CPUS"
	// ExportIsolatedCPUs is the shell variable used to export isolated container CPUs.
	ExportIsolatedCPUs = "ISOLATED_CPUS"
	// ExportExclusiveCPUs is the shell variable used to export exclusive container CPUs.
	ExportExclusiveCPUs = "EXCLUSIVE_CPUS"
)

Variables

This section is empty.

Functions

func ActivePolicy

func ActivePolicy() string

ActivePolicy returns the name of the policy to be activated.

func ConstraintToString

func ConstraintToString(value Constraint) string

ConstraintToString returns the given constraint as a string.

func Register

func Register(name, description string, create CreateFn) error

Register registers a policy backend.

Types

type AvailablePolicy

type AvailablePolicy struct {
	// Name is the name of the policy.
	Name string
	// Description is a short description of the policy.
	Description string
}

AvailablePolicy describes an available policy.

func AvailablePolicies

func AvailablePolicies() []*AvailablePolicy

AvailablePolicies returns the available policies and their descriptions.

type Backend

type Backend interface {
	// Name gets the well-known name of this policy.
	Name() string
	// Description gives a verbose description about the policy implementation.
	Description() string
	// Start up and sycnhronizes the policy, using the given cache and resource constraints.
	Start([]cache.Container, []cache.Container) error
	// Sync synchronizes the policy, allocating/releasing the given containers.
	Sync([]cache.Container, []cache.Container) error
	// AllocateResources allocates resources to/for a container.
	AllocateResources(cache.Container) error
	// ReleaseResources release resources of a container.
	ReleaseResources(cache.Container) error
	// UpdateResources updates resource allocations of a container.
	UpdateResources(cache.Container) error
	// Rebalance tries an optimal allocation of resources for the current container.
	Rebalance() (bool, error)
	// HandleEvent processes the given event. The returned boolean indicates whether
	// changes have been made to any of the containers while handling the event.
	HandleEvent(*events.Policy) (bool, error)
	// ExportResourceData provides resource data to export for the container.
	ExportResourceData(cache.Container) map[string]string
	// Introspect provides data for external introspection.
	Introspect(*introspect.State)
	// DescribeMetrics generates policy-specific prometheus metrics data descriptors.
	DescribeMetrics() []*prometheus.Desc
	// PollMetrics provides policy metrics for monitoring.
	PollMetrics() Metrics
	// CollectMetrics generates prometheus metrics from cached/polled policy-specific metrics data.
	CollectMetrics(Metrics) ([]prometheus.Metric, error)
}

Backend is the policy (decision making logic) interface exposed by implementations.

A backends operates in a set of policy domains. Currently each policy domain corresponds to some particular hardware resource (CPU, memory, cache, etc).

type BackendOptions

type BackendOptions struct {
	// System provides system/HW/topology information
	System system.System
	// System state/cache
	Cache cache.Cache
	// Resource availibility constraint
	Available ConstraintSet
	// Resource reservation constraint
	Reserved ConstraintSet
	// Client interface to cri-resmgr agent
	AgentCli agent.Interface
	// SendEvent is the function for delivering events up to the resource manager.
	SendEvent SendEventFn
}

BackendOptions describes the options for a policy backend instance

type Constraint

type Constraint interface{}

Constraint describes constraint of one hardware domain

type ConstraintSet

type ConstraintSet map[Domain]Constraint

ConstraintSet describes, per hardware domain, the resources available for a policy.

func (ConstraintSet) MarshalJSON

func (cs ConstraintSet) MarshalJSON() ([]byte, error)

MarshalJSON implements JSON marshalling for ConstraintSets.

func (*ConstraintSet) String

func (cs *ConstraintSet) String() string

func (*ConstraintSet) UnmarshalJSON

func (cs *ConstraintSet) UnmarshalJSON(raw []byte) error

UnmarshalJSON implements JSON unmarshalling for ConstraintSets.

type CreateFn

type CreateFn func(*BackendOptions) Backend

CreateFn is the type for functions used to create a policy instance.

type Domain

type Domain string

Domain represents a hardware resource domain that can be policied by a backend.

const (
	// DomainCPU is the CPU resource domain.
	DomainCPU Domain = "CPU"
	// DomainMemory is the memory resource domain.
	DomainMemory Domain = "Memory"
	// DomainHugePage is the hugepages resource domain.
	DomainHugePage Domain = "HugePages"
	// DomainCache is the CPU cache resource domain.
	DomainCache Domain = "Cache"
	// DomainMemoryBW is the memory resource bandwidth.
	DomainMemoryBW Domain = "MBW"
)

type Metrics added in v0.7.0

type Metrics interface{}

type Options

type Options struct {
	// Client interface to cri-resmgr agent
	AgentCli agent.Interface
	// SendEvent is the function for delivering events back to the resource manager.
	SendEvent SendEventFn
}

Options describes policy options

type Policy

type Policy interface {
	// Start starts up policy, prepare for serving resource management requests.
	Start([]cache.Container, []cache.Container) error
	// Sync synchronizes the state of the active policy.
	Sync([]cache.Container, []cache.Container) error
	// AllocateResources allocates resources to a container.
	AllocateResources(cache.Container) error
	// ReleaseResources releases resources of a container.
	ReleaseResources(cache.Container) error
	// UpdateResources updates resource allocations of a container.
	UpdateResources(cache.Container) error
	// Rebalance tries to find an optimal allocation of resources for the current containers.
	Rebalance() (bool, error)
	// HandleEvent passes on the given event to the active policy. The returned boolean
	// indicates whether changes have been made to any of the containers while handling
	// the event.
	HandleEvent(*events.Policy) (bool, error)
	// ExportResourceData exports/updates resource data for the container.
	ExportResourceData(cache.Container)
	// Introspect provides data for external introspection.
	Introspect() *introspect.State
	// DescribeMetrics generates policy-specific prometheus metrics data descriptors.
	DescribeMetrics() []*prometheus.Desc
	// PollMetrics provides policy metrics for monitoring.
	PollMetrics() Metrics
	// CollectMetrics generates prometheus metrics from cached/polled policy-specific metrics data.
	CollectMetrics(Metrics) ([]prometheus.Metric, error)
}

Policy is the exposed interface for container resource allocations decision making.

func NewPolicy

func NewPolicy(cache cache.Cache, o *Options) (Policy, error)

NewPolicy creates a policy instance using the selected backend.

type SendEventFn added in v0.4.0

type SendEventFn func(interface{}) error

SendEventFn is the type for a function to send events back to the resource manager.

Directories

Path Synopsis
builtin

Jump to

Keyboard shortcuts

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