limesresources

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 9 Imported by: 5

Documentation

Overview

Package limesresources contains data structures that appear on the Limes resource API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseQuotaOverrides added in v1.11.0

func ParseQuotaOverrides(buf []byte, getUnit func(limes.ServiceType, ResourceName) (limes.Unit, error)) (result map[string]map[string]map[limes.ServiceType]map[ResourceName]uint64, errs []error)

ParseQuotaOverrides parses the contents of a quota-overrides.json file. This is the format expected by Limes at $LIMES_QUOTA_OVERRIDES_PATH. This code lives here because it is also used in `limesctl validate-quota-overrides`.

Types

type ClusterAZResourceReport added in v1.10.0

type ClusterAZResourceReport struct {
	Capacity    uint64 `json:"capacity"`
	RawCapacity uint64 `json:"raw_capacity,omitempty"`
	// Usage is what the backend reports. This is only shown if the backend does indeed report a summarized cluster-wide usage level.
	//TODO: rename this to "backend_usage" in v2
	Usage *uint64 `json:"usage,omitempty"`
	// ProjectsUsage is the aggregate of the usage across all projects, as reported by the backend on the project level.
	//TODO: rename this to "usage" in v2 (to be consistent with domain and project level)
	ProjectsUsage uint64 `json:"projects_usage,omitempty"`
	// The keys for these maps must be commitment durations as accepted
	// by func ParseCommitmentDuration. We cannot use type CommitmentDuration
	// directly here because Go does not allow struct types as map keys.
	Committed          map[string]uint64 `json:"committed,omitempty"`
	UnusedCommitments  uint64            `json:"unused_commitments,omitempty"`
	PendingCommitments map[string]uint64 `json:"pending_commitments,omitempty"`
	PlannedCommitments map[string]uint64 `json:"planned_commitments,omitempty"`
	// UncommittedUsage can also be derived as Usage - (Committed.Values().Sum() - UnusedCommitments),
	// so this is only reported for convenience purposes.
	UncommittedUsage uint64 `json:"uncommitted_usage,omitempty"`
	// PhysicalUsage is collected per project and then aggregated, same as ProjectsUsage.
	PhysicalUsage *uint64         `json:"physical_usage,omitempty"`
	Subcapacities json.RawMessage `json:"subcapacities,omitempty"`
}

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

This type is part of the v2 API feature preview.

type ClusterAZResourceReports added in v1.10.0

type ClusterAZResourceReports map[limes.AvailabilityZone]*ClusterAZResourceReport

ClusterAZResourceReport is a substructure of ClusterResourceReport that breaks down capacity and usage data for a single resource by availability zone.

type ClusterAvailabilityZoneReport

type ClusterAvailabilityZoneReport struct {
	Name        limes.AvailabilityZone `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[limes.AvailabilityZone]*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)

func (*ClusterAvailabilityZoneReports) UnmarshalJSON

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

type ClusterReport

type ClusterReport struct {
	limes.ClusterInfo
	Services     ClusterServiceReports  `json:"services"`
	MaxScrapedAt *limes.UnixEncodedTime `json:"max_scraped_at,omitempty"`
	MinScrapedAt *limes.UnixEncodedTime `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
	QuotaDistributionModel QuotaDistributionModel   `json:"quota_distribution_model,omitempty"`
	CommitmentConfig       *CommitmentConfiguration `json:"commitment_config,omitempty"`
	Capacity               *uint64                  `json:"capacity,omitempty"`
	RawCapacity            *uint64                  `json:"raw_capacity,omitempty"`
	// PerAZ is only rendered by Limes when the v2 API feature preview is enabled.
	// In this case, CapacityPerAZ will be omitted.
	PerAZ         ClusterAZResourceReports       `json:"per_az,omitempty"`
	CapacityPerAZ ClusterAvailabilityZoneReports `json:"per_availability_zone,omitempty"`
	DomainsQuota  *uint64                        `json:"domains_quota,omitempty"`
	Usage         uint64                         `json:"usage"`
	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[ResourceName]*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)

func (*ClusterResourceReports) UnmarshalJSON

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

type ClusterServiceReport

type ClusterServiceReport struct {
	limes.ServiceInfo
	Resources    ClusterResourceReports `json:"resources"`
	MaxScrapedAt *limes.UnixEncodedTime `json:"max_scraped_at,omitempty"`
	MinScrapedAt *limes.UnixEncodedTime `json:"min_scraped_at,omitempty"`
}

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

type ClusterServiceReports

type ClusterServiceReports map[limes.ServiceType]*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)

func (*ClusterServiceReports) UnmarshalJSON

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

type Commitment added in v1.9.0

type Commitment struct {
	ID               int64                  `json:"id"`
	ServiceType      limes.ServiceType      `json:"service_type"`
	ResourceName     ResourceName           `json:"resource_name"`
	AvailabilityZone limes.AvailabilityZone `json:"availability_zone"`
	Amount           uint64                 `json:"amount"`
	Unit             limes.Unit             `json:"unit,omitempty"`
	Duration         CommitmentDuration     `json:"duration"`
	CreatedAt        limes.UnixEncodedTime  `json:"created_at"`
	// CreatorUUID and CreatorName identify the user who created this commitment.
	// CreatorName is in the format `fmt.Sprintf("%s@%s", userName, userDomainName)`
	// and intended for informational displays only. API access should always use the UUID.
	CreatorUUID string `json:"creator_uuid,omitempty"`
	CreatorName string `json:"creator_name,omitempty"`
	// CanBeDeleted will be true if the commitment can be deleted by the same user
	// who saw this object in response to a GET query.
	CanBeDeleted bool `json:"can_be_deleted,omitempty"`
	// ConfirmBy is only filled if it was set in the CommitmentRequest.
	ConfirmBy *limes.UnixEncodedTime `json:"confirm_by,omitempty"`
	// ConfirmedAt is only filled after the commitment was confirmed.
	ConfirmedAt *limes.UnixEncodedTime `json:"confirmed_at,omitempty"`
	ExpiresAt   limes.UnixEncodedTime  `json:"expires_at,omitempty"`
	// TransferStatus and TransferToken are only filled while the commitment is marked for transfer.
	TransferStatus CommitmentTransferStatus `json:"transfer_status,omitempty"`
	TransferToken  string                   `json:"transfer_token,omitempty"`
}

Commitment is the API representation of an *existing* commitment as reported by Limes.

type CommitmentConfiguration added in v1.9.0

type CommitmentConfiguration struct {
	// Allowed durations for commitments on this resource.
	Durations []CommitmentDuration `json:"durations"`
	// If shown, commitments must be created with `confirm_by` at or after this timestamp.
	MinConfirmBy *limes.UnixEncodedTime `json:"min_confirm_by,omitempty"`
}

CommitmentConfiguration describes how commitments are configured for a given resource.

This appears as a field on resource reports, if the respective resource allows commitments.

type CommitmentDuration added in v1.9.0

type CommitmentDuration struct {
	//NOTE: this does not use uint etc. because time.Time.AddDate() wants int
	Years  int
	Months int
	Days   int
	Short  time.Duration // represents durations of hours, minutes and seconds
}

CommitmentDuration is the parsed representation of a commitment duration.

The behavior of this type is similar to time.Duration or limesrates.Window for short durations (which are commonly used in automated tests for convenience and clarity), but also allows large durations with calendar-compatible calculations (e.g. "1y" is actually one year and not just 365 days).

func ParseCommitmentDuration added in v1.9.0

func ParseCommitmentDuration(input string) (CommitmentDuration, error)

ParseCommitmentDuration parses the string representation of a CommitmentDuration. Acceptable inputs include "5 hours" and "1year,2 \t months, 3days".

func (CommitmentDuration) AddTo added in v1.9.0

func (d CommitmentDuration) AddTo(t time.Time) time.Time

AddTo adds this duration to the given time.

func (CommitmentDuration) MarshalJSON added in v1.9.0

func (d CommitmentDuration) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (CommitmentDuration) MarshalYAML added in v1.9.0

func (d CommitmentDuration) MarshalYAML() (any, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*CommitmentDuration) Scan added in v1.9.0

func (d *CommitmentDuration) Scan(src any) (err error)

Scan implements the sql.Scanner interface.

func (CommitmentDuration) String added in v1.9.0

func (d CommitmentDuration) String() string

String returns the canonical string representation of this duration.

func (*CommitmentDuration) UnmarshalJSON added in v1.9.0

func (d *CommitmentDuration) UnmarshalJSON(input []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*CommitmentDuration) UnmarshalYAML added in v1.9.0

func (d *CommitmentDuration) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (CommitmentDuration) Value added in v1.9.0

func (d CommitmentDuration) Value() (driver.Value, error)

Value implements the sql/driver.Valuer interface.

type CommitmentRequest added in v1.9.0

type CommitmentRequest struct {
	ServiceType      limes.ServiceType      `json:"service_type"`
	ResourceName     ResourceName           `json:"resource_name"`
	AvailabilityZone limes.AvailabilityZone `json:"availability_zone"`
	Amount           uint64                 `json:"amount"`
	Duration         CommitmentDuration     `json:"duration"`
	ConfirmBy        *limes.UnixEncodedTime `json:"confirm_by,omitempty"`
}

CommitmentRequest is the API representation of a *new* commitment as requested by a user.

type CommitmentTransferStatus added in v1.9.0

type CommitmentTransferStatus string

CommitmentTransferStatus is an enum.

const (
	// CommitmentTransferStatusNone is the default transfer status,
	// meaning that the commitment is not marked for transfer.
	CommitmentTransferStatusNone CommitmentTransferStatus = ""

	// CommitmentTransferStatusPublic means that the commitment is marked for transfer,
	// and is visible as such to all other projects.
	CommitmentTransferStatusPublic CommitmentTransferStatus = "public"

	// CommitmentTransferStatusUnlisted means that the commitment is marked for transfer,
	// but the receiver needs to know the commitment's transfer token.
	CommitmentTransferStatusUnlisted CommitmentTransferStatus = "unlisted"
)

type DomainAZResourceReport added in v1.10.7

type DomainAZResourceReport struct {
	Quota *uint64 `json:"quota,omitempty"`
	Usage uint64  `json:"usage"`
	// The keys for these maps must be commitment durations as accepted
	// by func ParseCommitmentDuration. We cannot use type CommitmentDuration
	// directly here because Go does not allow struct types as map keys.
	Committed          map[string]uint64 `json:"committed,omitempty"`
	UnusedCommitments  uint64            `json:"unused_commitments,omitempty"`
	PendingCommitments map[string]uint64 `json:"pending_commitments,omitempty"`
	PlannedCommitments map[string]uint64 `json:"planned_commitments,omitempty"`
	// UncommittedUsage can also be derived as Usage - (Committed.Values().Sum() - UnusedCommitments),
	// so this is only reported for convenience purposes.
	UncommittedUsage uint64 `json:"uncommitted_usage,omitempty"`
}

DomainAZResourceReport is a substructure of DomainResourceReport containing quota and usage data for a single resource in an availability zone.

This type is part of the v2 API feature preview.

type DomainAZResourceReports added in v1.10.7

type DomainAZResourceReports map[limes.AvailabilityZone]*DomainAZResourceReport

DomainAZResourceReport is a substructure of DomainResourceReport that breaks down quota and usage data for a single resource by availability zone.

type DomainReport

type DomainReport struct {
	limes.DomainInfo
	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
	QuotaDistributionModel QuotaDistributionModel   `json:"quota_distribution_model,omitempty"`
	CommitmentConfig       *CommitmentConfiguration `json:"commitment_config,omitempty"`
	// PerAZ is only rendered by Limes when the v2 API feature preview is enabled.
	PerAZ                DomainAZResourceReports `json:"per_az,omitempty"`
	DomainQuota          *uint64                 `json:"quota,omitempty"`
	ProjectsQuota        *uint64                 `json:"projects_quota,omitempty"`
	Usage                uint64                  `json:"usage"`
	PhysicalUsage        *uint64                 `json:"physical_usage,omitempty"`
	BackendQuota         *uint64                 `json:"backend_quota,omitempty"`
	InfiniteBackendQuota *bool                   `json:"infinite_backend_quota,omitempty"`
}

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

type DomainResourceReports

type DomainResourceReports map[ResourceName]*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)

func (*DomainResourceReports) UnmarshalJSON

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

type DomainServiceReport

type DomainServiceReport struct {
	limes.ServiceInfo
	Resources    DomainResourceReports  `json:"resources"`
	MaxScrapedAt *limes.UnixEncodedTime `json:"max_scraped_at,omitempty"`
	MinScrapedAt *limes.UnixEncodedTime `json:"min_scraped_at,omitempty"`
}

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

type DomainServiceReports

type DomainServiceReports map[limes.ServiceType]*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)

func (*DomainServiceReports) UnmarshalJSON

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

type ProjectAZResourceReport added in v1.10.0

type ProjectAZResourceReport struct {
	Quota *uint64 `json:"quota,omitempty"`
	// The keys for these maps must be commitment durations as accepted
	// by func ParseCommitmentDuration. We cannot use type CommitmentDuration
	// directly here because Go does not allow struct types as map keys.
	Committed          map[string]uint64 `json:"committed,omitempty"`
	PendingCommitments map[string]uint64 `json:"pending_commitments,omitempty"`
	PlannedCommitments map[string]uint64 `json:"planned_commitments,omitempty"`
	Usage              uint64            `json:"usage"`
	PhysicalUsage      *uint64           `json:"physical_usage,omitempty"`
	Subresources       json.RawMessage   `json:"subresources,omitempty"`
}

ProjectAZResourceReport is a substructure of ProjectResourceReport containing quota and usage data for a single resource in an availability zone.

This type is part of the v2 API feature preview.

type ProjectAZResourceReports added in v1.10.0

type ProjectAZResourceReports map[limes.AvailabilityZone]*ProjectAZResourceReport

ProjectAZResourceReport is a substructure of ProjectResourceReport that breaks down quota and usage data for a single resource by availability zone.

type ProjectReport

type ProjectReport struct {
	limes.ProjectInfo
	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
	QuotaDistributionModel QuotaDistributionModel   `json:"quota_distribution_model,omitempty"`
	CommitmentConfig       *CommitmentConfiguration `json:"commitment_config,omitempty"`
	// PerAZ is only rendered by Limes when the v2 API feature preview is enabled.
	PerAZ         ProjectAZResourceReports `json:"per_az,omitempty"`
	Quota         *uint64                  `json:"quota,omitempty"`
	UsableQuota   *uint64                  `json:"usable_quota,omitempty"`
	MaxQuota      *uint64                  `json:"max_quota,omitempty"` // refers to max_quota constraint maintained via API
	Usage         uint64                   `json:"usage"`
	PhysicalUsage *uint64                  `json:"physical_usage,omitempty"`
	BackendQuota  *int64                   `json:"backend_quota,omitempty"`
	Subresources  json.RawMessage          `json:"subresources,omitempty"`
}

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

type ProjectResourceReports

type ProjectResourceReports map[ResourceName]*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)

func (*ProjectResourceReports) UnmarshalJSON

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

type ProjectServiceReport

type ProjectServiceReport struct {
	limes.ServiceInfo
	Resources ProjectResourceReports `json:"resources"`
	ScrapedAt *limes.UnixEncodedTime `json:"scraped_at,omitempty"`
}

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

type ProjectServiceReports

type ProjectServiceReports map[limes.ServiceType]*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)

func (*ProjectServiceReports) UnmarshalJSON

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

type QuotaDistributionModel added in v1.4.1

type QuotaDistributionModel string

QuotaDistributionModel is an enum.

const (
	// HierarchicalQuotaDistribution is the default QuotaDistributionModel,
	// wherein quota is distributed to domains by the cloud admins, and then the
	// projects by the domain admins. Domains and projects start out at zero
	// quota.
	HierarchicalQuotaDistribution QuotaDistributionModel = "hierarchical"
	// AutogrowQuotaDistribution is an alternative QuotaDistributionModel,
	// wherein project quota is automatically distributed ("auto") such that:
	// 1. all active commitments and usage are represented in their respective project quota,
	// 2. there is some space beyond the current commitment/usage ("grow").
	//
	// Domain quota is irrelevant under this model. Project quota never sinks
	// below a certain value (the "base quota") unless capacity is exhausted.
	AutogrowQuotaDistribution QuotaDistributionModel = "autogrow"
)

type ResourceInfo

type ResourceInfo struct {
	Name ResourceName `json:"name"`
	Unit limes.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 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 ResourceName `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 ResourceName added in v1.10.11

type ResourceName string

ResourceName identifies a resource within a service. This type is used to distinguish resource names from other types of string values in function signatures.

Jump to

Keyboard shortcuts

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