limes

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: Apache-2.0 Imports: 7 Imported by: 10

Documentation

Overview

Package limes contains data structures that appear on the Limes API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BurstingMultiplier

type BurstingMultiplier float64

BurstingMultiplier is a multiplier for quota bursting.

func (BurstingMultiplier) ApplyTo

func (m BurstingMultiplier) ApplyTo(quota uint64) uint64

ApplyTo returns the bursted backend quota for the given approved quota.

type ClusterAvailabilityZoneReport

type ClusterAvailabilityZoneReport struct {
	Name        string `json:"name"`
	Capacity    uint64 `json:"capacity"`
	RawCapacity uint64 `json:"raw_capacity,omitempty"`
	Usage       uint64 `json:"usage,omitempty"`
}

ClusterAvailabilityZoneReport is a substructure of ClusterResourceReport containing capacity and usage data for a single resource in an availability zone.

type ClusterAvailabilityZoneReports

type ClusterAvailabilityZoneReports map[string]*ClusterAvailabilityZoneReport

ClusterAvailabilityZoneReports provides fast lookup of availability zones using a map, but serializes to JSON as a list.

func (ClusterAvailabilityZoneReports) MarshalJSON

func (r ClusterAvailabilityZoneReports) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ClusterAvailabilityZoneReports) UnmarshalJSON

func (r *ClusterAvailabilityZoneReports) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type ClusterRateLimitReport

type ClusterRateLimitReport struct {
	RateInfo
	Limit  uint64 `json:"limit,omitempty"`
	Window Window `json:"window,omitempty"`
}

ClusterRateLimitReport is the structure for rate limits per target type URI and their rate limited actions.

type ClusterRateLimitReports

type ClusterRateLimitReports map[string]*ClusterRateLimitReport

ClusterRateLimitReports provides fast lookup of global rate limits using a map, but serializes to JSON as a list.

func (ClusterRateLimitReports) MarshalJSON

func (r ClusterRateLimitReports) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ClusterRateLimitReports) UnmarshalJSON

func (r *ClusterRateLimitReports) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type ClusterReport

type ClusterReport struct {
	ID           string                `json:"id"`
	Services     ClusterServiceReports `json:"services"`
	MaxScrapedAt *int64                `json:"max_scraped_at,omitempty"`
	MinScrapedAt *int64                `json:"min_scraped_at,omitempty"`
}

ClusterReport contains aggregated data about resource usage in a cluster. It is returned by GET endpoints for clusters.

type ClusterResourceReport

type ClusterResourceReport struct {
	//Several fields are pointers to values to enable precise control over which fields are rendered in output.
	ResourceInfo
	Capacity      *uint64                        `json:"capacity,omitempty"`
	RawCapacity   *uint64                        `json:"raw_capacity,omitempty"`
	CapacityPerAZ ClusterAvailabilityZoneReports `json:"per_availability_zone,omitempty"`
	DomainsQuota  *uint64                        `json:"domains_quota,omitempty"`
	Usage         uint64                         `json:"usage"`
	BurstUsage    uint64                         `json:"burst_usage,omitempty"`
	PhysicalUsage *uint64                        `json:"physical_usage,omitempty"`
	Subcapacities json.RawMessage                `json:"subcapacities,omitempty"`
}

ClusterResourceReport is a substructure of ClusterReport containing data for a single resource.

type ClusterResourceReports

type ClusterResourceReports map[string]*ClusterResourceReport

ClusterResourceReports provides fast lookup of resources by resource name, but serializes to JSON as a list.

func (ClusterResourceReports) MarshalJSON

func (r ClusterResourceReports) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ClusterResourceReports) UnmarshalJSON

func (r *ClusterResourceReports) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type ClusterServiceReport

type ClusterServiceReport struct {
	ServiceInfo
	Resources         ClusterResourceReports  `json:"resources"`
	Rates             ClusterRateLimitReports `json:"rates,omitempty"`
	MaxScrapedAt      *int64                  `json:"max_scraped_at,omitempty"`
	MinScrapedAt      *int64                  `json:"min_scraped_at,omitempty"`
	MaxRatesScrapedAt *int64                  `json:"max_rates_scraped_at,omitempty"`
	MinRatesScrapedAt *int64                  `json:"min_rates_scraped_at,omitempty"`
}

ClusterServiceReport is a substructure of ClusterReport containing data for a single backend service.

type ClusterServiceReports

type ClusterServiceReports map[string]*ClusterServiceReport

ClusterServiceReports provides fast lookup of services by service type, but serializes to JSON as a list.

func (ClusterServiceReports) MarshalJSON

func (s ClusterServiceReports) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ClusterServiceReports) UnmarshalJSON

func (s *ClusterServiceReports) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type DomainReport

type DomainReport struct {
	UUID     string               `json:"id"`
	Name     string               `json:"name"`
	Services DomainServiceReports `json:"services"`
}

DomainReport contains aggregated data about resource usage in a domain. It is returned by GET requests on domains.

type DomainResourceReport

type DomainResourceReport struct {
	//Several fields are pointers to values to enable precise control over which fields are rendered in output.
	ResourceInfo
	DomainQuota          *uint64          `json:"quota,omitempty"`
	ProjectsQuota        *uint64          `json:"projects_quota,omitempty"`
	Usage                uint64           `json:"usage"`
	BurstUsage           uint64           `json:"burst_usage,omitempty"`
	PhysicalUsage        *uint64          `json:"physical_usage,omitempty"`
	BackendQuota         *uint64          `json:"backend_quota,omitempty"`
	InfiniteBackendQuota *bool            `json:"infinite_backend_quota,omitempty"`
	Scaling              *ScalingBehavior `json:"scales_with,omitempty"`
	//Annotations may contain arbitrary metadata that was configured for this
	//resource in this scope by Limes' operator.
	Annotations map[string]interface{} `json:"annotations,omitempty"`
}

DomainResourceReport is a substructure of DomainReport containing data for a single resource.

type DomainResourceReports

type DomainResourceReports map[string]*DomainResourceReport

DomainResourceReports provides fast lookup of resources using a map, but serializes to JSON as a list.

func (DomainResourceReports) MarshalJSON

func (r DomainResourceReports) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*DomainResourceReports) UnmarshalJSON

func (r *DomainResourceReports) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type DomainServiceReport

type DomainServiceReport struct {
	ServiceInfo
	Resources         DomainResourceReports `json:"resources"`
	MaxScrapedAt      *int64                `json:"max_scraped_at,omitempty"`
	MinScrapedAt      *int64                `json:"min_scraped_at,omitempty"`
	MaxRatesScrapedAt *int64                `json:"max_rates_scraped_at,omitempty"`
	MinRatesScrapedAt *int64                `json:"min_rates_scraped_at,omitempty"`
}

DomainServiceReport is a substructure of DomainReport containing data for a single backend service.

type DomainServiceReports

type DomainServiceReports map[string]*DomainServiceReport

DomainServiceReports provides fast lookup of services using a map, but serializes to JSON as a list.

func (DomainServiceReports) MarshalJSON

func (s DomainServiceReports) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*DomainServiceReports) UnmarshalJSON

func (s *DomainServiceReports) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type FractionalValueError

type FractionalValueError struct {
	Source ValueWithUnit
	Target Unit
}

FractionalValueError is returned by ValueWithUnit.ConvertTo() when the conversion would yield a fractional value in the target unit.

func (FractionalValueError) Error

func (e FractionalValueError) Error() string

Error implements the error interface.

type IncompatibleUnitsError

type IncompatibleUnitsError struct {
	Source Unit
	Target Unit
}

IncompatibleUnitsError is returned by ValueWithUnit.ConvertTo() when the original and target unit are incompatible and cannot be converted into each other.

func (IncompatibleUnitsError) Error

func (e IncompatibleUnitsError) Error() string

Error implements the error interface.

type ProjectBurstingInfo

type ProjectBurstingInfo struct {
	Enabled    bool               `json:"enabled"`
	Multiplier BurstingMultiplier `json:"multiplier"`
}

ProjectBurstingInfo is a substructure of ProjectReport containing information about quota bursting. (It is omitted if bursting is not supported for the project's cluster.)

type ProjectRateLimitReport

type ProjectRateLimitReport struct {
	RateInfo
	//NOTE: Both Window fields must have pointer types because omitempty does not
	//work directly on json.Marshaler-implementing types.
	Limit         uint64  `json:"limit,omitempty"`
	Window        *Window `json:"window,omitempty"`
	DefaultLimit  uint64  `json:"default_limit,omitempty"`
	DefaultWindow *Window `json:"default_window,omitempty"`
	UsageAsBigint string  `json:"usage_as_bigint,omitempty"`
}

ProjectRateLimitReport is the structure for rate limits per target type URI and their rate limited actions.

type ProjectRateLimitReports

type ProjectRateLimitReports map[string]*ProjectRateLimitReport

ProjectRateLimitReports provides fast lookup of resources using a map, but serializes to JSON as a list.

func (ProjectRateLimitReports) MarshalJSON

func (r ProjectRateLimitReports) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ProjectRateLimitReports) UnmarshalJSON

func (r *ProjectRateLimitReports) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type ProjectReport

type ProjectReport struct {
	UUID       string                `json:"id"`
	Name       string                `json:"name"`
	ParentUUID string                `json:"parent_id"`
	Bursting   *ProjectBurstingInfo  `json:"bursting,omitempty"`
	Services   ProjectServiceReports `json:"services"`
}

ProjectReport contains all data about resource usage in a project.

type ProjectResourceReport

type ProjectResourceReport struct {
	//Several fields are pointers to values to enable precise control over which fields are rendered in output.
	ResourceInfo
	Quota         *uint64          `json:"quota,omitempty"`
	UsableQuota   *uint64          `json:"usable_quota,omitempty"`
	Usage         uint64           `json:"usage"`
	BurstUsage    uint64           `json:"burst_usage,omitempty"`
	PhysicalUsage *uint64          `json:"physical_usage,omitempty"`
	BackendQuota  *int64           `json:"backend_quota,omitempty"`
	Subresources  json.RawMessage  `json:"subresources,omitempty"`
	Scaling       *ScalingBehavior `json:"scales_with,omitempty"`
	//Annotations may contain arbitrary metadata that was configured for this
	//resource in this scope by Limes' operator.
	Annotations map[string]interface{} `json:"annotations,omitempty"`
}

ProjectResourceReport is a substructure of ProjectReport containing data for a single resource.

type ProjectResourceReports

type ProjectResourceReports map[string]*ProjectResourceReport

ProjectResourceReports provides fast lookup of resources using a map, but serializes to JSON as a list.

func (ProjectResourceReports) MarshalJSON

func (r ProjectResourceReports) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ProjectResourceReports) UnmarshalJSON

func (r *ProjectResourceReports) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type ProjectServiceReport

type ProjectServiceReport struct {
	ServiceInfo
	Resources      ProjectResourceReports  `json:"resources"`
	Rates          ProjectRateLimitReports `json:"rates,omitempty"`
	ScrapedAt      *int64                  `json:"scraped_at,omitempty"`
	RatesScrapedAt *int64                  `json:"rates_scraped_at,omitempty"`
}

ProjectServiceReport is a substructure of ProjectReport containing data for a single backend service.

type ProjectServiceReports

type ProjectServiceReports map[string]*ProjectServiceReport

ProjectServiceReports provides fast lookup of services using a map, but serializes to JSON as a list.

func (ProjectServiceReports) MarshalJSON

func (s ProjectServiceReports) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ProjectServiceReports) UnmarshalJSON

func (s *ProjectServiceReports) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type QuotaRequest

type QuotaRequest map[string]ServiceQuotaRequest

QuotaRequest contains new quota values for resources in multiple services. The map key is the service type. This type is used to serialize JSON request bodies in PUT requests on domains and projects.

func (QuotaRequest) MarshalJSON

func (r QuotaRequest) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*QuotaRequest) UnmarshalJSON

func (r *QuotaRequest) UnmarshalJSON(input []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type RateInfo

type RateInfo struct {
	Name string `json:"name"`
	Unit Unit   `json:"unit,omitempty"`
}

RateInfo contains the metadata for a rate (i.e. some type of event that can be rate-limited and for which there may a way to retrieve a count of past events from a backend service).

type RateLimitRequest

type RateLimitRequest struct {
	Limit  uint64
	Window Window
}

RateLimitRequest contains new values for a single rate limit. It appears in type RateLimitRequests.

type ResourceInfo

type ResourceInfo struct {
	Name string `json:"name"`
	Unit Unit   `json:"unit,omitempty"`
	//Category is an optional hint that UIs can use to group resources of one
	//service into subgroups. If it is used, it should be set on all
	//ResourceInfos reported by the same QuotaPlugin.
	Category string `json:"category,omitempty"`
	//If AutoApproveInitialQuota is non-zero, when a new project is scraped for
	//the first time, a backend quota equal to this value will be approved
	//automatically (i.e. Quota will be set equal to BackendQuota).
	AutoApproveInitialQuota uint64 `json:"-"`
	//If ExternallyManaged is true, quota cannot be set via the API. The quota
	//value reported by the QuotaPlugin is always authoritative.
	ExternallyManaged bool `json:"externally_managed,omitempty"`
	//If NoQuota is true, quota is not tracked at all for this resource. The
	//resource will only report usage. This field is not shown in API responses.
	//Check `res.Quota == nil` instead.
	NoQuota bool `json:"-"`
	//ContainedIn is an optional hint that UIs can use to group resources. If non-empty,
	//this resource is semantically contained within the resource with that name
	//in the same service.
	ContainedIn string `json:"contained_in,omitempty"`
}

ResourceInfo contains the metadata for a resource (i.e. some thing for which quota and usage values can be retrieved from a backend service).

type ResourceQuotaRequest

type ResourceQuotaRequest map[string]ValueWithUnit

ResourceQuotaRequest contains new quota values for resources. The map key is the resource name.

type ScalingBehavior

type ScalingBehavior struct {
	ScalesWithResourceName string  `json:"resource_name"`
	ScalesWithServiceType  string  `json:"service_type"`
	ScalingFactor          float64 `json:"factor"`
}

ScalingBehavior appears in type DomainResourceReport and type ProjectResourceReport and describes the scaling behavior of a single resource.

type ServiceInfo

type ServiceInfo struct {
	//Type returns the service type that the backend service for this
	//plugin implements. This string must be identical to the type string from
	//the Keystone service catalog.
	Type string `json:"type"`
	//ProductName returns the name of the product that is the reference
	//implementation for this service. For example, ProductName = "nova" for
	//Type = "compute".
	ProductName string `json:"-"`
	//Area is a hint that UIs can use to group similar services.
	Area string `json:"area"`
}

ServiceInfo contains the metadata for a backend service.

type ServiceQuotaRequest

type ServiceQuotaRequest struct {
	Resources ResourceQuotaRequest
	Rates     map[string]RateLimitRequest // key = rate name
}

ServiceQuotaRequest contains new quota values for the resources or rate limits in a single service. This type appears in type QuotaRequest.

type Unit

type Unit string

Unit enumerates allowed values for the unit a resource's quota/usage is measured in.

const (
	//UnitNone is used for countable (rather than measurable) resources.
	UnitNone Unit = ""
	//UnitBytes is exactly that.
	UnitBytes Unit = "B"
	//UnitKibibytes is exactly that.
	UnitKibibytes Unit = "KiB"
	//UnitMebibytes is exactly that.
	UnitMebibytes Unit = "MiB"
	//UnitGibibytes is exactly that.
	UnitGibibytes Unit = "GiB"
	//UnitTebibytes is exactly that.
	UnitTebibytes Unit = "TiB"
	//UnitPebibytes is exactly that.
	UnitPebibytes Unit = "PiB"
	//UnitExbibytes is exactly that.
	UnitExbibytes Unit = "EiB"
	//UnitUnspecified is used as a placeholder when the unit is not known.
	UnitUnspecified Unit = "UNSPECIFIED"
)

func (Unit) Base

func (u Unit) Base() (Unit, uint64)

Base returns the base unit of this unit. For units defined as a multiple of another unit, that unit is the base unit. Otherwise, the same unit and a multiple of 1 is returned.

func (Unit) Parse

func (u Unit) Parse(str string) (uint64, error)

Parse parses the string representation of a value with this unit (or any unit that can be converted to it).

UnitMebibytes.Parse("10 MiB") -> 10
UnitMebibytes.Parse("10 GiB") -> 10240
UnitMebibytes.Parse("10 KiB") -> returns FractionalValueError
UnitMebibytes.Parse("10")     -> returns syntax error (missing unit)
UnitNone.Parse("42")          -> 42
UnitNone.Parse("42 MiB")      -> returns syntax error (unexpected unit)

func (*Unit) UnmarshalYAML

func (u *Unit) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface. This method validates that units in the config file actually exist.

type ValueWithUnit

type ValueWithUnit struct {
	Value uint64 `json:"value" yaml:"value"`
	Unit  Unit   `json:"unit"  yaml:"unit"`
}

ValueWithUnit is used to represent values with units in subresources.

func (ValueWithUnit) ConvertTo

func (v ValueWithUnit) ConvertTo(u Unit) (ValueWithUnit, error)

ConvertTo returns an equal value in the given Unit. IncompatibleUnitsError is returned if the source unit cannot be converted into the target unit. FractionalValueError is returned if the conversion does not yield an integer value in the new unit.

func (ValueWithUnit) String

func (v ValueWithUnit) String() string

String appends the unit (if any) to the given value. This should only be used for error messages; actual UIs should be more clever about formatting values (e.g. ValueWithUnit{1048576,UnitMebibytes}.String() returns "1048576 MiB" where "1 TiB" would be more appropriate).

type Window

type Window uint64

Window is the size (in nanoseconds) of the time window that is considered when enforcing a rate limit. For example, a rate limit of "10 per second" has a limit of 10 and a window of 1 second.

This type is very similar to time.Duration, but does not allow negative values and uses a different parsing logic that does not allow phrases with multiple units like time.Duration does (e.g. "2h30m").

const (
	//WindowMilliseconds is a Window unit.
	WindowMilliseconds Window = 1000 * 1000
	//WindowSeconds is a Window unit.
	WindowSeconds Window = 1000 * WindowMilliseconds
	//WindowMinutes is a Window unit.
	WindowMinutes Window = 60 * WindowSeconds
	//WindowHours is a Window unit.
	WindowHours Window = 60 * WindowMinutes
)

func MustParseWindow

func MustParseWindow(input string) Window

MustParseWindow is like ParseWindow, but panics on error. This should only be used for compile-time constants.

func ParseWindow

func ParseWindow(input string) (Window, error)

ParseWindow parses a string representation like "1s" or "5m".

func (Window) MarshalJSON

func (w Window) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Window) String

func (w Window) String() string

String returns the optimal string representation for this window.

func (*Window) UnmarshalJSON

func (w *Window) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Window) UnmarshalYAML

func (w *Window) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface. This method validates that windows in the config file are valid.

Jump to

Keyboard shortcuts

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