kubecost

package
v0.0.0-...-8b28c38 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AllocationNilProp            string = ""
	AllocationClusterProp        string = "cluster"
	AllocationNodeProp           string = "node"
	AllocationContainerProp      string = "container"
	AllocationControllerProp     string = "controller"
	AllocationControllerKindProp string = "controllerKind"
	AllocationNamespaceProp      string = "namespace"
	AllocationPodProp            string = "pod"
	AllocationProviderIDProp     string = "providerID"
	AllocationServiceProp        string = "service"
	AllocationLabelProp          string = "label"
	AllocationAnnotationProp     string = "annotation"
	AllocationDeploymentProp     string = "deployment"
	AllocationStatefulSetProp    string = "statefulset"
	AllocationDaemonSetProp      string = "daemonset"
	AllocationJobProp            string = "job"
	AllocationDepartmentProp     string = "department"
	AllocationEnvironmentProp    string = "environment"
	AllocationOwnerProp          string = "owner"
	AllocationProductProp        string = "product"
	AllocationTeamProp           string = "team"
)
View Source
const (
	DiffAdded   DiffKind = "added"
	DiffRemoved          = "removed"
	DiffChanged          = "changed"
)
View Source
const (
	ListCostMetric         string = "ListCost"
	NetCostMetric          string = "NetCost"
	AmortizedNetCostMetric string = "AmortizedNetCost"
	InvoicedCostMetric     string = "InvoicedCost"
	AmortizedCostMetric    string = "AmortizedCost"
)
View Source
const (
	CloudCostInvoiceEntityIDProp string = "invoiceEntityID"
	CloudCostAccountIDProp       string = "accountID"
	CloudCostProviderProp        string = "provider"
	CloudCostProviderIDProp      string = "providerID"
	CloudCostCategoryProp        string = "category"
	CloudCostServiceProp         string = "service"
	CloudCostLabelProp           string = "label"
)
View Source
const (
	// CloudCostClusterManagementCategory describes CloudCost representing Hosted Kubernetes Fees
	CloudCostClusterManagementCategory string = "Cluster Management"

	// CloudCostDiskCategory describes CloudCost representing Disk usage
	CloudCostDiskCategory string = "Disk"

	// CloudCostLoadBalancerCategory describes CloudCost representing Load Balancer usage
	CloudCostLoadBalancerCategory string = "Load Balancer"

	// CloudCostNetworkCategory describes CloudCost representing Network usage
	CloudCostNetworkCategory string = "Network"

	// CloudCostVirtualMachineCategory describes CloudCost representing VM usage
	CloudCostVirtualMachineCategory string = "Virtual Machine"

	// CloudCostOtherCategory describes CloudCost that do not belong to a defined category
	CloudCostOtherCategory string = "Other"
)
View Source
const (
	// DefaultCodecVersion is used for any resources listed in the Default version set
	DefaultCodecVersion uint8 = 17

	// AssetsCodecVersion is used for any resources listed in the Assets version set
	AssetsCodecVersion uint8 = 21

	// AllocationCodecVersion is used for any resources listed in the Allocation version set
	AllocationCodecVersion uint8 = 20

	// CloudCostCodecVersion is used for any resources listed in the CloudCost version set
	CloudCostCodecVersion uint8 = 2
)
View Source
const AKSNodepoolLabel = "kubernetes.azure.com/agentpool"

describes how Azure labels nodepool nodes

View Source
const AWSProvider = "AWS"

AWSProvider describes the provider AWS

View Source
const AzureProvider = "Azure"

AzureProvider describes the provider Azure

View Source
const (
	// BinaryTagStringTable is written and/or read prior to the existence of a string
	// table (where each index is encoded as a string entry in the resource
	BinaryTagStringTable string = "BGST"
)

BinaryTags represent the formatting tag used for specific optimization features

View Source
const CSVProvider = "CSV"

CSVProvider describes the provider a CSV

View Source
const ComputeCategory = "Compute"

ComputeCategory signifies the Compute Category

View Source
const CustomProvider = "custom"

CustomProvider describes a custom provider

View Source
const EKSNodepoolLabel = "eks.amazonaws.com/nodegroup"

describes how AWS labels nodepool nodes

View Source
const ExternalSuffix = "__external__"

ExternalSuffix indicates an external allocation

View Source
const GCPProvider = "GCP"

GCPProvider describes the provider GCP

View Source
const GKENodePoolLabel = "cloud.google.com/gke-nodepool"

describes how nodepool nodes are labeled in GKE

View Source
const (
	// GeneratorPackageName is the package the generator is targetting
	GeneratorPackageName string = "kubecost"
)
View Source
const IdleSuffix = "__idle__"

IdleSuffix indicates an idle allocation property

View Source
const KubernetesService = "Kubernetes"
View Source
const LocalStorageClass = "__local__"

LocalStorageClass is used to assign storage class of local disks.

View Source
const ManagementCategory = "Management"

ManagementCategory signifies the Management Category

View Source
const NetworkCategory = "Network"

NetworkCategory signifies the Network Category

View Source
const NilProvider = "-"

NilProvider describes unknown provider

View Source
const OtherCategory = "Other"

OtherCategory signifies an unassigned Category

View Source
const ScalewayProvider = "Scaleway"

ScalewayProvider describes the provider Scaleway

View Source
const ShareEven = "__even__"

ShareEven indicates that a shared resource should be shared evenly across all remaining allocations.

View Source
const ShareNone = "__none__"

ShareNone indicates that a shareable resource should not be shared

View Source
const ShareWeighted = "__weighted__"

ShareWeighted indicates that a shared resource should be shared as a proportion of the cost of the remaining allocations.

View Source
const SharedCategory = "Shared"

SharedCategory signifies an unassigned Category

View Source
const SharedSuffix = "__shared__"

SharedSuffix indicates an shared allocation property

View Source
const StorageCategory = "Storage"

StorageCategory signifies the Storage Category

View Source
const UnallocatedSuffix = "__unallocated__"

UnallocatedSuffix indicates an unallocated allocation property

View Source
const UndefinedKey = "__undefined__"

UndefinedKey is used in composing Asset group keys if the group does not have that property defined. E.g. if aggregating on Cluster, Assets in the AssetSet where Asset has no cluster will be grouped under key "__undefined__"

View Source
const UnknownStorageClass = "__unknown__"

UnknownStorageClass is used to assign storage class of persistent volume whose information is unable to be traced.

View Source
const UnmountedSuffix = "__unmounted__"

UnmountedSuffix indicated allocation to an unmounted resource (PV or LB)

Variables

This section is empty.

Functions

func ComputeAllocationTotals

func ComputeAllocationTotals(as *AllocationSet, prop string) map[string]*AllocationTotals

ComputeAllocationTotals totals the resource costs of the given AllocationSet using the given property, i.e. cluster or node, where "node" really means to use the fully-qualified (cluster, node) tuple.

func ComputeAssetTotals

func ComputeAssetTotals(as *AssetSet, byAsset bool) map[string]*AssetTotals

ComputeAssetTotals totals the resource costs of the given AssetSet, using the given property, i.e. cluster or node, where "node" really means to use the fully-qualified (cluster, node) tuple. NOTE: we're not capturing LoadBalancers here yet, but only because we don't yet need them. They could be added.

func ComputeIdleCoefficients

func ComputeIdleCoefficients(shareSplit, key string, cpuCost, gpuCost, ramCost float64, allocationTotals map[string]*AllocationTotals) (float64, float64, float64)

ComputeIdleCoefficients returns the idle coefficients for CPU, GPU, and RAM (in that order) for the given resource costs and totals.

func ComputePercentages

func ComputePercentages(toInsert *ProportionalAssetResourceCost)

func DiffAsset

func DiffAsset(before, after *AssetSet, ratioCostChange float64) (map[string]Diff[Asset], error)

DiffAsset takes two AssetSets and returns a map of keys to Diffs by checking the keys of each AssetSet. If a key is not found or is found with a different total cost, a Diff is generated and added to the map. A found asset will only be added to the map if the new total cost is greater than ratioCostChange * the old total cost

func GetAssetKey

func GetAssetKey(a Asset, aggregateBy []string) (string, error)

func GetNodePoolName

func GetNodePoolName(provider string, labels map[string]string) string

func NewAllocationAliasPass

func NewAllocationAliasPass(config LabelConfig) transform.CompilerPass

NewAliasPass creates a compiler pass that converts alias nodes to logically-equivalent label/annotation nodes based on the label config.

Due to the special alias logic that combines label and annotation behavior when filtering on alias, an alias filter is logically equivalent to the following expression:

(or

(and (contains labels <parseraliaskey>)
     (<op> labels[<parseraliaskey>] <filtervalue>))
(and (not (contains labels <parseraliaskey>))
     (and (contains annotations departmentkey)
          (<op> annotations[<parseraliaskey>] <filtervalue>))))

func NewAllocationMatchCompiler

func NewAllocationMatchCompiler(labelConfig *LabelConfig) *matcher.MatchCompiler[*Allocation]

NewAllocationMatchCompiler creates a new instance of a matcher.MatchCompiler[*Allocation] which can be used to compile filter.Filter ASTs into matcher.Matcher[*Allocation] implementations.

If the label config is nil, the compiler will fail to compile alias filters if any are present in the AST.

If storage interfaces every support querying natively by alias (e.g. if a data store contained a "product" attribute on an Allocation row), that should be handled by a purpose-built AST compiler.

func NewAssetMatchCompiler

func NewAssetMatchCompiler() *matcher.MatchCompiler[Asset]

NewAssetMatchCompiler creates a new instance of a matcher.MatchCompiler[Asset] which can be used to compile filter.Filter ASTs into matcher.Matcher[Asset] implementations.

If the label config is nil, the compiler will fail to compile alias filters if any are present in the AST.

If storage interfaces every support querying natively by alias (e.g. if a data store contained a "product" attribute on an Asset row), that should be handled by a purpose-built AST compiler.

func NewCloudCostMatchCompiler

func NewCloudCostMatchCompiler() *matcher.MatchCompiler[*CloudCost]

NewCloudCostMatchCompiler creates a new instance of a matcher.MatchCompiler[*CloudCost] which can be used to compile filter.Filter ASTs into matcher.Matcher[*CloudCost] implementations.

If storage interfaces every support querying natively by alias (e.g. if a data store contained a "product" attribute on an CloudCost row), that should be handled by a purpose-built AST compiler.

func ParseProperty

func ParseProperty(text string) (string, error)

func ParseProvider

func ParseProvider(str string) string

ParseProvider attempts to parse and return a known provider, given a string

func QueryAllocationAsync

func QueryAllocationAsync(allocationQuerier AllocationQuerier, start, end time.Time, opts *AllocationQueryOptions) (chan *AllocationSetRange, chan error)

QueryAllocationAsync provide a functions for retrieving results from any AllocationQuerier Asynchronously

func QueryAssetAsync

func QueryAssetAsync(assetQuerier AssetQuerier, start, end time.Time, opts *AssetQueryOptions) (chan *AssetSetRange, chan error)

QueryAsseetAsync provide a functions for retrieving results from any AssetQuerier Asynchronously

func QueryCloudUsageAsync

func QueryCloudUsageAsync(cloudUsageQuerier CloudUsageQuerier, start, end time.Time, opts *CloudUsageQueryOptions) (chan *CloudUsageSetRange, chan error)

QueryCloudUsageAsync provide a functions for retrieving results from any CloudUsageQuerier Asynchronously

func QuerySummaryAllocationAsync

func QuerySummaryAllocationAsync(summaryAllocationQuerier SummaryAllocationQuerier, start, end time.Time, opts *AllocationQueryOptions) (chan *SummaryAllocationSetRange, chan error)

QuerySummaryAllocationAsync provide a functions for retrieving results from any SummaryAllocationQuerier Asynchronously

func RoundBack

func RoundBack(t time.Time, resolution time.Duration) time.Time

RoundBack rounds the given time back to a multiple of the given resolution in the given time's timezone. e.g. 2020-01-01T12:37:48-0700, 24h = 2020-01-01T00:00:00-0700

func RoundForward

func RoundForward(t time.Time, resolution time.Duration) time.Time

RoundForward rounds the given time forward to a multiple of the given resolution in the given time's timezone. e.g. 2020-01-01T12:37:48-0700, 24h = 2020-01-02T00:00:00-0700

Types

type AccumulateOption

type AccumulateOption string
const (
	AccumulateOptionNone    AccumulateOption = ""
	AccumulateOptionAll     AccumulateOption = "all"
	AccumulateOptionHour    AccumulateOption = "hour"
	AccumulateOptionDay     AccumulateOption = "day"
	AccumulateOptionWeek    AccumulateOption = "week"
	AccumulateOptionMonth   AccumulateOption = "month"
	AccumulateOptionQuarter AccumulateOption = "quarter"
)

type Allocation

type Allocation struct {
	Name                       string                `json:"name"`
	Properties                 *AllocationProperties `json:"properties,omitempty"`
	Window                     Window                `json:"window"`
	Start                      time.Time             `json:"start"`
	End                        time.Time             `json:"end"`
	CPUCoreHours               float64               `json:"cpuCoreHours"`
	CPUCoreRequestAverage      float64               `json:"cpuCoreRequestAverage"`
	CPUCoreUsageAverage        float64               `json:"cpuCoreUsageAverage"`
	CPUCost                    float64               `json:"cpuCost"`
	CPUCostAdjustment          float64               `json:"cpuCostAdjustment"`
	GPUHours                   float64               `json:"gpuHours"`
	GPUCost                    float64               `json:"gpuCost"`
	GPUCostAdjustment          float64               `json:"gpuCostAdjustment"`
	NetworkTransferBytes       float64               `json:"networkTransferBytes"`
	NetworkReceiveBytes        float64               `json:"networkReceiveBytes"`
	NetworkCost                float64               `json:"networkCost"`
	NetworkCrossZoneCost       float64               `json:"networkCrossZoneCost"`   // @bingen:field[version=16]
	NetworkCrossRegionCost     float64               `json:"networkCrossRegionCost"` // @bingen:field[version=16]
	NetworkInternetCost        float64               `json:"networkInternetCost"`    // @bingen:field[version=16]
	NetworkCostAdjustment      float64               `json:"networkCostAdjustment"`
	LoadBalancerCost           float64               `json:"loadBalancerCost"`
	LoadBalancerCostAdjustment float64               `json:"loadBalancerCostAdjustment"`
	PVs                        PVAllocations         `json:"pvs"`
	PVCostAdjustment           float64               `json:"pvCostAdjustment"`
	RAMByteHours               float64               `json:"ramByteHours"`
	RAMBytesRequestAverage     float64               `json:"ramByteRequestAverage"`
	RAMBytesUsageAverage       float64               `json:"ramByteUsageAverage"`
	RAMCost                    float64               `json:"ramCost"`
	RAMCostAdjustment          float64               `json:"ramCostAdjustment"`
	SharedCost                 float64               `json:"sharedCost"`
	ExternalCost               float64               `json:"externalCost"`
	// RawAllocationOnly is a pointer so if it is not present it will be
	// marshalled as null rather than as an object with Go default values.
	RawAllocationOnly *RawAllocationOnlyData `json:"rawAllocationOnly"`
	// ProportionalAssetResourceCost represents the per-resource costs of the
	// allocation as a percentage of the per-resource total cost of the
	// asset on which the allocation was run. It is optionally computed
	// and appended to an Allocation, and so by default is is nil.
	ProportionalAssetResourceCosts ProportionalAssetResourceCosts `json:"proportionalAssetResourceCosts"` //@bingen:field[ignore]
	SharedCostBreakdown            SharedCostBreakdowns           `json:"sharedCostBreakdown"`            //@bingen:field[ignore]
	LoadBalancers                  LbAllocations                  `json:"LoadBalancers"`                  // @bingen:field[version=18]
	// UnmountedPVCost is used to track how much of the cost in PVs is for an
	// unmounted PV. It is not additive of PVCost() and need not be sent in API
	// responses.
	UnmountedPVCost float64 `json:"-"`
}

Allocation is a unit of resource allocation and cost for a given window of time and for a given kubernetes construct with its associated set of properties. TODO:CLEANUP consider dropping name in favor of just Allocation and an Assets-style key() function for AllocationSet.

func AssetToExternalAllocation

func AssetToExternalAllocation(asset Asset, aggregateBy []string, labelConfig *LabelConfig) (*Allocation, error)

AssetToExternalAllocation converts the given asset to an Allocation, given the Properties to use to aggregate, and the mapping from Allocation property to Asset label. For example, consider this asset:

CURRENT: Asset ETL stores its data ALREADY MAPPED from label to k8s concept. This isn't ideal-- see the TODO.

  Cloud {
	   TotalCost: 10.00,
	   Labels{
      "kubernetes_namespace":"monitoring",
	     "env":"prod"
	   }
  }

Given the following parameters, we expect to return:

  1. single-prop full match aggregateBy = ["namespace"] => Allocation{Name: "monitoring", ExternalCost: 10.00, TotalCost: 10.00}, nil

  2. multi-prop full match aggregateBy = ["namespace", "label:env"] allocationPropertyLabels = {"namespace":"kubernetes_namespace"} => Allocation{Name: "monitoring/env=prod", ExternalCost: 10.00, TotalCost: 10.00}, nil

  3. multi-prop partial match aggregateBy = ["namespace", "label:foo"] => Allocation{Name: "monitoring/__unallocated__", ExternalCost: 10.00, TotalCost: 10.00}, nil

  4. no match aggregateBy = ["cluster"] => nil, err

TODO:

  Cloud {
	   TotalCost: 10.00,
	   Labels{
      "kubernetes_namespace":"monitoring",
	     "env":"prod"
	   }
  }

Given the following parameters, we expect to return:

  1. single-prop full match aggregateBy = ["namespace"] allocationPropertyLabels = {"namespace":"kubernetes_namespace"} => Allocation{Name: "monitoring", ExternalCost: 10.00, TotalCost: 10.00}, nil

  2. multi-prop full match aggregateBy = ["namespace", "label:env"] allocationPropertyLabels = {"namespace":"kubernetes_namespace"} => Allocation{Name: "monitoring/env=prod", ExternalCost: 10.00, TotalCost: 10.00}, nil

  3. multi-prop partial match aggregateBy = ["namespace", "label:foo"] allocationPropertyLabels = {"namespace":"kubernetes_namespace"} => Allocation{Name: "monitoring/__unallocated__", ExternalCost: 10.00, TotalCost: 10.00}, nil

  4. no match aggregateBy = ["cluster"] allocationPropertyLabels = {"namespace":"kubernetes_namespace"} => nil, err

(See asset_test.go for assertions of these examples and more.)

func NewMockUnitAllocation

func NewMockUnitAllocation(name string, start time.Time, resolution time.Duration, props *AllocationProperties) *Allocation

NewMockUnitAllocation creates an *Allocation with all of its float64 values set to 1 and generic properties if not provided in arg

func (*Allocation) Add

func (a *Allocation) Add(that *Allocation) (*Allocation, error)

Add returns the result of summing the two given Allocations, which sums the summary fields (e.g. costs, resources) and recomputes efficiency. Neither of the two original Allocations are mutated in the process.

func (*Allocation) CPUCores

func (a *Allocation) CPUCores() float64

CPUCores converts the Allocation's CPUCoreHours into average CPUCores

func (*Allocation) CPUEfficiency

func (a *Allocation) CPUEfficiency() float64

CPUEfficiency is the ratio of usage to request. If there is no request and no usage or cost, then efficiency is zero. If there is no request, but there is usage or cost, then efficiency is 100%.

func (*Allocation) CPUTotalCost

func (a *Allocation) CPUTotalCost() float64

CPUTotalCost calculates total CPU cost of Allocation including adjustment

func (*Allocation) Clone

func (a *Allocation) Clone() *Allocation

Clone returns a deep copy of the given Allocation

func (*Allocation) Equal

func (a *Allocation) Equal(that *Allocation) bool

Equal returns true if the values held in the given Allocation precisely match those of the receiving Allocation. nil does not match nil. Floating point values need to match according to util.IsApproximately, which accounts for small, reasonable floating point error margins.

func (*Allocation) GPUTotalCost

func (a *Allocation) GPUTotalCost() float64

GPUTotalCost calculates total GPU cost of Allocation including adjustment

func (*Allocation) GPUs

func (a *Allocation) GPUs() float64

GPUs converts the Allocation's GPUHours into average GPUs

func (*Allocation) GetWindow

func (a *Allocation) GetWindow() Window

GetWindow returns the window of the struct

func (*Allocation) IsAggregated

func (a *Allocation) IsAggregated() bool

IsAggregated is true if the given Allocation has been aggregated, which we define by a lack of AllocationProperties.

func (*Allocation) IsExternal

func (a *Allocation) IsExternal() bool

IsExternal is true if the given Allocation represents external costs.

func (*Allocation) IsIdle

func (a *Allocation) IsIdle() bool

IsIdle is true if the given Allocation represents idle costs.

func (*Allocation) IsUnallocated

func (a *Allocation) IsUnallocated() bool

IsUnallocated is true if the given Allocation represents unallocated costs.

func (*Allocation) IsUnmounted

func (a *Allocation) IsUnmounted() bool

IsUnmounted is true if the given Allocation represents unmounted volume costs.

func (*Allocation) LBTotalCost

func (a *Allocation) LBTotalCost() float64

LBTotalCost calculates total LB cost of Allocation including adjustment TODO deprecate

func (*Allocation) LoadBalancerTotalCost

func (a *Allocation) LoadBalancerTotalCost() float64

LoadBalancerTotalCost calculates total LB cost of Allocation including adjustment

func (*Allocation) MarshalBinary

func (target *Allocation) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this Allocation instance into a byte array

func (*Allocation) MarshalBinaryWithContext

func (target *Allocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this Allocation instance into a byte array leveraging a predefined context.

func (*Allocation) MarshalJSON

func (a *Allocation) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (*Allocation) Minutes

func (a *Allocation) Minutes() float64

Minutes returns the number of minutes the Allocation represents, as defined by the difference between the end and start times.

func (*Allocation) NetworkTotalCost

func (a *Allocation) NetworkTotalCost() float64

NetworkTotalCost calculates total Network cost of Allocation including adjustment

func (*Allocation) PVByteHours

func (a *Allocation) PVByteHours() float64

PVByteHours calculate cumulative ByteHours of all PVs that Allocation is attached to

func (*Allocation) PVBytes

func (a *Allocation) PVBytes() float64

PVBytes converts the Allocation's PVByteHours into average PVBytes

func (*Allocation) PVCost

func (a *Allocation) PVCost() float64

PVCost calculate cumulative cost of all PVs that Allocation is attached to

func (*Allocation) PVTotalCost

func (a *Allocation) PVTotalCost() float64

PVTotalCost calculates total PV cost of Allocation including adjustment

func (*Allocation) RAMBytes

func (a *Allocation) RAMBytes() float64

RAMBytes converts the Allocation's RAMByteHours into average RAMBytes

func (*Allocation) RAMEfficiency

func (a *Allocation) RAMEfficiency() float64

RAMEfficiency is the ratio of usage to request. If there is no request and no usage or cost, then efficiency is zero. If there is no request, but there is usage or cost, then efficiency is 100%.

func (*Allocation) RAMTotalCost

func (a *Allocation) RAMTotalCost() float64

RAMTotalCost calculates total RAM cost of Allocation including adjustment

func (*Allocation) ResetAdjustments

func (a *Allocation) ResetAdjustments()

ResetAdjustments sets all cost adjustment fields to zero

func (*Allocation) Resolution

func (a *Allocation) Resolution() time.Duration

Resolution returns the duration of time covered by the Allocation

func (*Allocation) SanitizeNaN

func (a *Allocation) SanitizeNaN()

func (*Allocation) SetUnmountedPVCost

func (a *Allocation) SetUnmountedPVCost() float64

SetUnmountedPVCost determines if the Allocation is unmounted and, if so, it sets the UnmountedPVCost field appropriately.

func (*Allocation) Share

func (a *Allocation) Share(that *Allocation) (*Allocation, error)

Share adds the TotalCost of the given Allocation to the SharedCost of the receiving Allocation. No Start, End, Window, or AllocationProperties are considered. Neither Allocation is mutated; a new Allocation is always returned.

func (*Allocation) SharedTotalCost

func (a *Allocation) SharedTotalCost() float64

SharedTotalCost calculates total shared cost of Allocation including adjustment

func (*Allocation) String

func (a *Allocation) String() string

String represents the given Allocation as a string

func (*Allocation) StringMapProperty

func (a *Allocation) StringMapProperty(property string) (map[string]string, error)

func (*Allocation) StringProperty

func (a *Allocation) StringProperty(property string) (string, error)

func (*Allocation) StringSliceProperty

func (a *Allocation) StringSliceProperty(property string) ([]string, error)

func (*Allocation) TotalCost

func (a *Allocation) TotalCost() float64

TotalCost is the total cost of the Allocation including adjustments

func (*Allocation) TotalEfficiency

func (a *Allocation) TotalEfficiency() float64

TotalEfficiency is the cost-weighted average of CPU and RAM efficiency. If there is no cost at all, then efficiency is zero.

func (*Allocation) UnmarshalBinary

func (target *Allocation) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the Allocation type

func (*Allocation) UnmarshalBinaryWithContext

func (target *Allocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the Allocation type

func (*Allocation) UnmarshalJSON

func (a *Allocation) UnmarshalJSON(b []byte) error

UnmarshalJSON prevent nil pointer on PVAllocations

type AllocationAggregationOptions

type AllocationAggregationOptions struct {
	AllocationTotalsStore                 AllocationTotalsStore
	Filter                                filter21.Filter
	IdleByNode                            bool
	IncludeProportionalAssetResourceCosts bool
	LabelConfig                           *LabelConfig
	MergeUnallocated                      bool
	Reconcile                             bool
	ReconcileNetwork                      bool
	Share                                 filter21.Filter
	SharedNamespaces                      []string
	SharedLabels                          map[string][]string
	ShareIdle                             string
	ShareSplit                            string
	SharedHourlyCosts                     map[string]float64
	IncludeSharedCostBreakdown            bool
	SplitIdle                             bool
	IncludeAggregatedMetadata             bool
}

AllocationAggregationOptions provide advanced functionality to AggregateBy, including filtering results and sharing allocations. FilterFuncs are a list of match functions such that, if any function fails, the allocation is ignored. ShareFuncs are a list of match functions such that, if any function succeeds, the allocation is marked as a shared resource. ShareIdle is a simple flag for sharing idle resources.

type AllocationAnnotations

type AllocationAnnotations map[string]string

AllocationAnnotations is a schema-free mapping of key/value pairs that can be attributed to an Allocation

type AllocationJSON

type AllocationJSON struct {
	Name                           string                          `json:"name"`
	Properties                     *AllocationProperties           `json:"properties"`
	Window                         Window                          `json:"window"`
	Start                          string                          `json:"start"`
	End                            string                          `json:"end"`
	Minutes                        *float64                        `json:"minutes"`
	CPUCores                       *float64                        `json:"cpuCores"`
	CPUCoreRequestAverage          *float64                        `json:"cpuCoreRequestAverage"`
	CPUCoreUsageAverage            *float64                        `json:"cpuCoreUsageAverage"`
	CPUCoreHours                   *float64                        `json:"cpuCoreHours"`
	CPUCost                        *float64                        `json:"cpuCost"`
	CPUCostAdjustment              *float64                        `json:"cpuCostAdjustment"`
	CPUEfficiency                  *float64                        `json:"cpuEfficiency"`
	GPUCount                       *float64                        `json:"gpuCount"`
	GPUHours                       *float64                        `json:"gpuHours"`
	GPUCost                        *float64                        `json:"gpuCost"`
	GPUCostAdjustment              *float64                        `json:"gpuCostAdjustment"`
	NetworkTransferBytes           *float64                        `json:"networkTransferBytes"`
	NetworkReceiveBytes            *float64                        `json:"networkReceiveBytes"`
	NetworkCost                    *float64                        `json:"networkCost"`
	NetworkCrossZoneCost           *float64                        `json:"networkCrossZoneCost"`
	NetworkCrossRegionCost         *float64                        `json:"networkCrossRegionCost"`
	NetworkInternetCost            *float64                        `json:"networkInternetCost"`
	NetworkCostAdjustment          *float64                        `json:"networkCostAdjustment"`
	LoadBalancerCost               *float64                        `json:"loadBalancerCost"`
	LoadBalancerCostAdjustment     *float64                        `json:"loadBalancerCostAdjustment"`
	PVBytes                        *float64                        `json:"pvBytes"`
	PVByteHours                    *float64                        `json:"pvByteHours"`
	PVCost                         *float64                        `json:"pvCost"`
	PVs                            PVAllocations                   `json:"pvs"`
	PVCostAdjustment               *float64                        `json:"pvCostAdjustment"`
	RAMBytes                       *float64                        `json:"ramBytes"`
	RAMByteRequestAverage          *float64                        `json:"ramByteRequestAverage"`
	RAMByteUsageAverage            *float64                        `json:"ramByteUsageAverage"`
	RAMByteHours                   *float64                        `json:"ramByteHours"`
	RAMCost                        *float64                        `json:"ramCost"`
	RAMCostAdjustment              *float64                        `json:"ramCostAdjustment"`
	RAMEfficiency                  *float64                        `json:"ramEfficiency"`
	ExternalCost                   *float64                        `json:"externalCost"`
	SharedCost                     *float64                        `json:"sharedCost"`
	TotalCost                      *float64                        `json:"totalCost"`
	TotalEfficiency                *float64                        `json:"totalEfficiency"`
	RawAllocationOnly              *RawAllocationOnlyData          `json:"rawAllocationOnly,omitempty"`
	ProportionalAssetResourceCosts *ProportionalAssetResourceCosts `json:"proportionalAssetResourceCosts,omitempty"`
	LoadBalancers                  LbAllocations                   `json:"lbAllocations"`
	SharedCostBreakdown            *SharedCostBreakdowns           `json:"sharedCostBreakdown,omitempty"`
}

AllocationJSON exists because there are expected JSON response fields that are calculated values from methods on an annotation

func (*AllocationJSON) BuildFromAllocation

func (aj *AllocationJSON) BuildFromAllocation(a *Allocation)

type AllocationLabels

type AllocationLabels map[string]string

AllocationLabels is a schema-free mapping of key/value pairs that can be attributed to an Allocation

type AllocationMatchFunc

type AllocationMatchFunc func(*Allocation) bool

AllocationMatchFunc is a function that can be used to match Allocations by returning true for any given Allocation if a condition is met.

type AllocationMatcher

type AllocationMatcher matcher.Matcher[*Allocation]

AllocationMatcher is a matcher implementation for Allocation instances, compiled using the matcher.MatchCompiler for allocations.

type AllocationProperties

type AllocationProperties struct {
	Cluster              string                `json:"cluster,omitempty"`
	Node                 string                `json:"node,omitempty"`
	Container            string                `json:"container,omitempty"`
	Controller           string                `json:"controller,omitempty"`
	ControllerKind       string                `json:"controllerKind,omitempty"`
	Namespace            string                `json:"namespace,omitempty"`
	Pod                  string                `json:"pod,omitempty"`
	Services             []string              `json:"services,omitempty"`
	ProviderID           string                `json:"providerID,omitempty"`
	Labels               AllocationLabels      `json:"labels,omitempty"`
	Annotations          AllocationAnnotations `json:"annotations,omitempty"`
	NamespaceLabels      AllocationLabels      `json:"namespaceLabels,omitempty"`      // @bingen:field[version=17]
	NamespaceAnnotations AllocationAnnotations `json:"namespaceAnnotations,omitempty"` // @bingen:field[version=17]
	// When set to true, maintain the intersection of all labels + annotations
	// in the aggregated AllocationProperties object
	AggregatedMetadata bool `json:"-"` //@bingen:field[ignore]
}

AllocationProperties describes a set of Kubernetes objects.

func (*AllocationProperties) Clone

func (*AllocationProperties) Equal

func (*AllocationProperties) GenerateKey

func (p *AllocationProperties) GenerateKey(aggregateBy []string, labelConfig *LabelConfig) string

GenerateKey generates a string that represents the key by which the AllocationProperties should be aggregated, given the properties defined by the aggregateBy parameter and the given label configuration.

func (*AllocationProperties) Intersection

Intersection returns an *AllocationProperties which contains all matching fields between the calling and parameter AllocationProperties nillable slices and maps are left as nil

func (*AllocationProperties) MarshalBinary

func (target *AllocationProperties) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this AllocationProperties instance into a byte array

func (*AllocationProperties) MarshalBinaryWithContext

func (target *AllocationProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this AllocationProperties instance into a byte array leveraging a predefined context.

func (*AllocationProperties) String

func (p *AllocationProperties) String() string

func (*AllocationProperties) UnmarshalBinary

func (target *AllocationProperties) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the AllocationProperties type

func (*AllocationProperties) UnmarshalBinaryWithContext

func (target *AllocationProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the AllocationProperties type

type AllocationQuerier

type AllocationQuerier interface {
	QueryAllocation(start, end time.Time, opts *AllocationQueryOptions) (*AllocationSetRange, error)
}

AllocationQuerier interface defining api for requesting Allocation data

type AllocationQueryOptions

type AllocationQueryOptions struct {
	Accumulate              AccumulateOption
	AggregateBy             []string
	Compute                 bool
	DisableAggregatedStores bool
	Filter                  filter21.Filter
	IdleByNode              bool
	IncludeExternal         bool
	IncludeIdle             bool
	LabelConfig             *LabelConfig
	MergeUnallocated        bool
	Reconcile               bool
	ReconcileNetwork        bool
	ShareFuncs              []AllocationMatchFunc
	SharedHourlyCosts       map[string]float64
	ShareIdle               string
	ShareSplit              string
	ShareTenancyCosts       bool
	SplitIdle               bool
	Step                    time.Duration
}

AllocationQueryOptions defines optional parameters for querying an Allocation Store

type AllocationSet

type AllocationSet struct {
	Allocations  map[string]*Allocation
	ExternalKeys map[string]bool
	IdleKeys     map[string]bool
	FromSource   string // stores the name of the source used to compute the data
	Window       Window
	Warnings     []string
	Errors       []string
}

AllocationSet stores a set of Allocations, each with a unique name, that share a window. An AllocationSet is mutable, so treat it like a threadsafe map.

func GenerateMockAllocationSet

func GenerateMockAllocationSet(start time.Time) *AllocationSet

GenerateMockAllocationSet creates generic allocation set without idle allocations

func GenerateMockAllocationSetClusterIdle

func GenerateMockAllocationSetClusterIdle(start time.Time) *AllocationSet

GenerateMockAllocationSetClusterIdle creates generic allocation set which includes an idle set broken down by cluster

func GenerateMockAllocationSetNodeIdle

func GenerateMockAllocationSetNodeIdle(start time.Time) *AllocationSet

GenerateMockAllocationSetNodeIdle creates generic allocation set which includes an idle set broken down by node

func GenerateMockAllocationSetWithAssetProperties

func GenerateMockAllocationSetWithAssetProperties(start time.Time) *AllocationSet

GenerateMockAllocationSetWithAssetProperties with no idle and connections to Assets in properties

func NewAllocationSet

func NewAllocationSet(start, end time.Time, allocs ...*Allocation) *AllocationSet

NewAllocationSet instantiates a new AllocationSet and, optionally, inserts the given list of Allocations

func (*AllocationSet) Accumulate

func (as *AllocationSet) Accumulate(that *AllocationSet) (*AllocationSet, error)

func (*AllocationSet) AggregateBy

func (as *AllocationSet) AggregateBy(aggregateBy []string, options *AllocationAggregationOptions) error

AggregateBy aggregates the Allocations in the given AllocationSet by the given AllocationProperty. This will only be legal if the AllocationSet is divisible by the given AllocationProperty; e.g. Containers can be divided by Namespace, but not vice-a-versa.

func (*AllocationSet) Clone

func (as *AllocationSet) Clone() *AllocationSet

Clone returns a new AllocationSet with a deep copy of the given AllocationSet's allocations.

func (*AllocationSet) Delete

func (as *AllocationSet) Delete(name string)

Delete removes the allocation with the given name from the set

func (*AllocationSet) End

func (as *AllocationSet) End() time.Time

End returns the End time of the AllocationSet window

func (*AllocationSet) ExternalAllocations

func (as *AllocationSet) ExternalAllocations() map[string]*Allocation

ExternalAllocations returns a map of the external allocations in the set. Returns clones of the actual Allocations, so mutability is not a problem.

func (*AllocationSet) ExternalCost

func (as *AllocationSet) ExternalCost() float64

ExternalCost returns the total aggregated external costs of the set

func (*AllocationSet) Get

func (as *AllocationSet) Get(key string) *Allocation

Get returns the Allocation at the given key in the AllocationSet

func (*AllocationSet) GetUnmountedPVCost

func (as *AllocationSet) GetUnmountedPVCost() float64

GetUnmountedPVCost returns the sum of all UnmountedPVCost fields across all allocations in the set.

func (*AllocationSet) GetWindow

func (as *AllocationSet) GetWindow() Window

GetWindow returns the AllocationSet's window

func (*AllocationSet) IdleAllocations

func (as *AllocationSet) IdleAllocations() map[string]*Allocation

IdleAllocations returns a map of the idle allocations in the AllocationSet. Returns clones of the actual Allocations, so mutability is not a problem.

func (*AllocationSet) Insert

func (as *AllocationSet) Insert(that *Allocation) error

Insert aggregates the current entry in the AllocationSet by the given Allocation, but only if the Allocation is valid, i.e. matches the AllocationSet's window. If there is no existing entry, one is created. Nil error response indicates success.

func (*AllocationSet) IsEmpty

func (as *AllocationSet) IsEmpty() bool

IsEmpty returns true if the AllocationSet is nil, or if it contains zero allocations.

func (*AllocationSet) Length

func (as *AllocationSet) Length() int

Length returns the number of Allocations in the set

func (*AllocationSet) MarshalBinary

func (target *AllocationSet) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this AllocationSet instance into a byte array

func (*AllocationSet) MarshalBinaryWithContext

func (target *AllocationSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this AllocationSet instance into a byte array leveraging a predefined context.

func (*AllocationSet) MarshalJSON

func (as *AllocationSet) MarshalJSON() ([]byte, error)

MarshalJSON JSON-encodes the AllocationSet

func (*AllocationSet) ResetAdjustments

func (as *AllocationSet) ResetAdjustments()

ResetAdjustments sets all cost adjustment fields to zero

func (*AllocationSet) Resolution

func (as *AllocationSet) Resolution() time.Duration

Resolution returns the AllocationSet's window duration

func (*AllocationSet) SanitizeNaN

func (as *AllocationSet) SanitizeNaN()

func (*AllocationSet) Set

func (as *AllocationSet) Set(alloc *Allocation) error

Set uses the given Allocation to overwrite the existing entry in the AllocationSet under the Allocation's name.

func (*AllocationSet) SetUnmountedPVCost

func (as *AllocationSet) SetUnmountedPVCost() float64

SetUnmountedPVCost sets the UnmountedPVCost field for all allocations in the set.

func (*AllocationSet) Start

func (as *AllocationSet) Start() time.Time

Start returns the Start time of the AllocationSet window

func (*AllocationSet) String

func (as *AllocationSet) String() string

String represents the given Allocation as a string

func (*AllocationSet) TotalCost

func (as *AllocationSet) TotalCost() float64

TotalCost returns the sum of all TotalCosts of the allocations contained

func (*AllocationSet) UTCOffset

func (as *AllocationSet) UTCOffset() time.Duration

UTCOffset returns the AllocationSet's configured UTCOffset.

func (*AllocationSet) UnmarshalBinary

func (target *AllocationSet) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the AllocationSet type

func (*AllocationSet) UnmarshalBinaryWithContext

func (target *AllocationSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the AllocationSet type

type AllocationSetRange

type AllocationSetRange struct {
	Allocations []*AllocationSet
	FromStore   string // stores the name of the store used to retrieve the data
}

AllocationSetRange is a thread-safe slice of AllocationSets. It is meant to be used such that the AllocationSets held are consecutive and coherent with respect to using the same aggregation properties, UTC offset, and resolution. However these rules are not necessarily enforced, so use wisely.

func NewAllocationSetRange

func NewAllocationSetRange(allocs ...*AllocationSet) *AllocationSetRange

NewAllocationSetRange instantiates a new range composed of the given AllocationSets in the order provided.

func (*AllocationSetRange) Accumulate

func (asr *AllocationSetRange) Accumulate(accumulateBy AccumulateOption) (*AllocationSetRange, error)

Accumulate sums AllocationSets based on the AccumulateOption (calendar week or calendar month). The accumulated set is determined by the start of the window of the allocation set.

func (*AllocationSetRange) AggregateBy

func (asr *AllocationSetRange) AggregateBy(aggregateBy []string, options *AllocationAggregationOptions) error

AggregateBy aggregates each AllocationSet in the range by the given properties and options.

func (*AllocationSetRange) Append

func (asr *AllocationSetRange) Append(that *AllocationSet)

Append appends the given AllocationSet to the end of the range. It does not validate whether or not that violates window continuity.

func (*AllocationSetRange) Clone

func (asr *AllocationSetRange) Clone() *AllocationSetRange

Clone returns a new AllocationSetRange cloned from the existing ASR

func (*AllocationSetRange) End

func (asr *AllocationSetRange) End() (time.Time, error)

End returns the latest end of all Allocations in the AllocationSetRange. It returns an error if there are no allocations.

func (*AllocationSetRange) Get

func (asr *AllocationSetRange) Get(i int) (*AllocationSet, error)

Get safely retrieves the AllocationSet at the given index of the range.

func (*AllocationSetRange) InsertRange

func (asr *AllocationSetRange) InsertRange(that *AllocationSetRange) error

InsertRange merges the given AllocationSetRange into the receiving one by lining up sets with matching windows, then inserting each allocation from the given ASR into the respective set in the receiving ASR. If the given ASR contains an AllocationSet from a window that does not exist in the receiving ASR, then an error is returned. However, the given ASR does not need to cover the full range of the receiver.

func (*AllocationSetRange) Length

func (asr *AllocationSetRange) Length() int

Length returns the length of the range, which is zero if nil

func (*AllocationSetRange) MarshalBinary

func (target *AllocationSetRange) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this AllocationSetRange instance into a byte array

func (*AllocationSetRange) MarshalBinaryWithContext

func (target *AllocationSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this AllocationSetRange instance into a byte array leveraging a predefined context.

func (*AllocationSetRange) MarshalJSON

func (asr *AllocationSetRange) MarshalJSON() ([]byte, error)

MarshalJSON JSON-encodes the range

func (*AllocationSetRange) Minutes

func (asr *AllocationSetRange) Minutes() float64

Minutes returns the duration, in minutes, between the earliest start and the latest end of all assets in the AllocationSetRange.

func (*AllocationSetRange) Slice

func (asr *AllocationSetRange) Slice() []*AllocationSet

Slice copies the underlying slice of AllocationSets, maintaining order, and returns the copied slice.

func (*AllocationSetRange) Start

func (asr *AllocationSetRange) Start() (time.Time, error)

Start returns the earliest start of all Allocations in the AllocationSetRange. It returns an error if there are no allocations.

func (*AllocationSetRange) StartAndEnd

func (asr *AllocationSetRange) StartAndEnd() (time.Time, time.Time, error)

StartAndEnd iterates over all AssetSets in the AssetSetRange and returns the earliest start and latest end over the entire range

func (*AllocationSetRange) String

func (asr *AllocationSetRange) String() string

String represents the given AllocationSetRange as a string

func (*AllocationSetRange) TotalCost

func (asr *AllocationSetRange) TotalCost() float64

TotalCost returns the sum of all TotalCosts of the allocations contained

func (*AllocationSetRange) UTCOffset

func (asr *AllocationSetRange) UTCOffset() time.Duration

UTCOffset returns the detected UTCOffset of the AllocationSets within the range. Defaults to 0 if the range is nil or empty. Does not warn if there are sets with conflicting UTCOffsets (just returns the first).

func (*AllocationSetRange) UnmarshalBinary

func (target *AllocationSetRange) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the AllocationSetRange type

func (*AllocationSetRange) UnmarshalBinaryWithContext

func (target *AllocationSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the AllocationSetRange type

func (*AllocationSetRange) Window

func (asr *AllocationSetRange) Window() Window

Window returns the full window that the AllocationSetRange spans, from the start of the first AllocationSet to the end of the last one.

type AllocationTotals

type AllocationTotals struct {
	Start                          time.Time `json:"start"`
	End                            time.Time `json:"end"`
	Cluster                        string    `json:"cluster"`
	Node                           string    `json:"node"`
	Count                          int       `json:"count"`
	CPUCost                        float64   `json:"cpuCost"`
	CPUCostAdjustment              float64   `json:"cpuCostAdjustment"`
	GPUCost                        float64   `json:"gpuCost"`
	GPUCostAdjustment              float64   `json:"gpuCostAdjustment"`
	LoadBalancerCost               float64   `json:"loadBalancerCost"`
	LoadBalancerCostAdjustment     float64   `json:"loadBalancerCostAdjustment"`
	NetworkCost                    float64   `json:"networkCost"`
	NetworkCostAdjustment          float64   `json:"networkCostAdjustment"`
	PersistentVolumeCost           float64   `json:"persistentVolumeCost"`
	PersistentVolumeCostAdjustment float64   `json:"persistentVolumeCostAdjustment"`
	RAMCost                        float64   `json:"ramCost"`
	RAMCostAdjustment              float64   `json:"ramCostAdjustment"`
	// UnmountedPVCost is used to track how much of the cost in
	// PersistentVolumeCost is for an unmounted PV. It is not additive of that
	// field, and need not be sent in API responses.
	UnmountedPVCost float64 `json:"-"`
}

AllocationTotals represents aggregate costs of all Allocations for a given cluster or tuple of (cluster, node) between a given start and end time, where the costs are aggregated per-resource. AllocationTotals is designed to be used as a pre-computed intermediate data structure when contextual knowledge is required to carry out a task, but computing totals on-the-fly would be expensive; e.g. idle allocation; sharing coefficients for idle or shared resources, etc.

func (*AllocationTotals) ClearAdjustments

func (art *AllocationTotals) ClearAdjustments()

ClearAdjustments sets all adjustment fields to 0.0

func (*AllocationTotals) Clone

func (art *AllocationTotals) Clone() *AllocationTotals

Clone deep copies the AllocationTotals

func (*AllocationTotals) ToResponse

func (arts *AllocationTotals) ToResponse() *AllocationTotalsResponse

func (*AllocationTotals) TotalCPUCost

func (art *AllocationTotals) TotalCPUCost() float64

TotalCPUCost returns CPU cost with adjustment.

func (*AllocationTotals) TotalCost

func (art *AllocationTotals) TotalCost() float64

TotalCost returns the sum of all costs.

func (*AllocationTotals) TotalGPUCost

func (art *AllocationTotals) TotalGPUCost() float64

TotalGPUCost returns GPU cost with adjustment.

func (*AllocationTotals) TotalLoadBalancerCost

func (art *AllocationTotals) TotalLoadBalancerCost() float64

TotalLoadBalancerCost returns LoadBalancer cost with adjustment.

func (*AllocationTotals) TotalNetworkCost

func (art *AllocationTotals) TotalNetworkCost() float64

TotalNetworkCost returns Network cost with adjustment.

func (*AllocationTotals) TotalPersistentVolumeCost

func (art *AllocationTotals) TotalPersistentVolumeCost() float64

TotalPersistentVolumeCost returns PersistentVolume cost with adjustment.

func (*AllocationTotals) TotalRAMCost

func (art *AllocationTotals) TotalRAMCost() float64

TotalRAMCost returns RAM cost with adjustment.

type AllocationTotalsResponse

type AllocationTotalsResponse struct {
	Start                          time.Time `json:"start"`
	End                            time.Time `json:"end"`
	Cluster                        string    `json:"cluster"`
	Node                           string    `json:"node"`
	Count                          int       `json:"count"`
	CPUCost                        *float64  `json:"cpuCost"`
	CPUCostAdjustment              *float64  `json:"cpuCostAdjustment"`
	GPUCost                        *float64  `json:"gpuCost"`
	GPUCostAdjustment              *float64  `json:"gpuCostAdjustment"`
	LoadBalancerCost               *float64  `json:"loadBalancerCost"`
	LoadBalancerCostAdjustment     *float64  `json:"loadBalancerCostAdjustment"`
	NetworkCost                    *float64  `json:"networkCost"`
	NetworkCostAdjustment          *float64  `json:"networkCostAdjustment"`
	PersistentVolumeCost           *float64  `json:"persistentVolumeCost"`
	PersistentVolumeCostAdjustment *float64  `json:"persistentVolumeCostAdjustment"`
	RAMCost                        *float64  `json:"ramCost"`
	RAMCostAdjustment              *float64  `json:"ramCostAdjustment"`
	TotalCost                      *float64  `json:"totalCost"`
}

type AllocationTotalsResult

type AllocationTotalsResult struct {
	Cluster map[string]*AllocationTotals `json:"cluster"`
	Node    map[string]*AllocationTotals `json:"node"`
}

func (*AllocationTotalsResult) ToResponse

type AllocationTotalsResultResponse

type AllocationTotalsResultResponse struct {
	Cluster map[string]*AllocationTotalsResponse `json:"cluster"`
	Node    map[string]*AllocationTotalsResponse `json:"node"`
}

type AllocationTotalsSet

type AllocationTotalsSet struct {
	Cluster map[string]*AllocationTotals `json:"cluster"`
	Node    map[string]*AllocationTotals `json:"node"`
	Window  Window                       `json:"window"`
}

AllocationTotalsSet represents totals, summed by both "cluster" and "node" for a given window of time.

func NewAllocationTotalsSet

func NewAllocationTotalsSet(window Window, byCluster, byNode map[string]*AllocationTotals) *AllocationTotalsSet

func UpdateAllocationTotalsStore

func UpdateAllocationTotalsStore(arts AllocationTotalsStore, as *AllocationSet) (*AllocationTotalsSet, error)

UpdateAllocationTotalsStore updates an AllocationTotalsStore by totaling the given AllocationSet and saving the totals.

type AllocationTotalsStore

type AllocationTotalsStore interface {
	GetAllocationTotalsByCluster(start, end time.Time) (map[string]*AllocationTotals, bool)
	GetAllocationTotalsByNode(start, end time.Time) (map[string]*AllocationTotals, bool)
	SetAllocationTotalsByCluster(start, end time.Time, rts map[string]*AllocationTotals)
	SetAllocationTotalsByNode(start, end time.Time, rts map[string]*AllocationTotals)
}

AllocationTotalsStore allows for storing (i.e. setting and getting) AllocationTotals by cluster and by node.

type Any

type Any struct {
	Labels     AssetLabels
	Properties *AssetProperties
	Start      time.Time
	End        time.Time
	Window     Window
	Adjustment float64
	Cost       float64
}

Any is the most general Asset, which is usually created as a result of adding two Assets of different types.

func NewAsset

func NewAsset(start, end time.Time, window Window) *Any

NewAsset creates a new Any-type Asset for the given period of time

func (*Any) Add

func (a *Any) Add(that Asset) Asset

Add sums the Asset with the given Asset to produce a new Asset, maintaining as much relevant information as possible (i.e. type, Properties, labels).

func (*Any) Clone

func (a *Any) Clone() Asset

Clone returns a cloned instance of the Asset

func (*Any) Equal

func (a *Any) Equal(that Asset) bool

Equal returns true if the given Asset is an exact match of the receiver

func (*Any) ExpandWindow

func (a *Any) ExpandWindow(window Window)

ExpandWindow expands the Asset's window by the given window

func (*Any) GetAdjustment

func (a *Any) GetAdjustment() float64

Adjustment returns the Asset's cost adjustment

func (*Any) GetEnd

func (a *Any) GetEnd() time.Time

End returns the Asset's end time within the window

func (*Any) GetLabels

func (a *Any) GetLabels() AssetLabels

Labels returns the Asset's labels

func (*Any) GetProperties

func (a *Any) GetProperties() *AssetProperties

Properties returns the Asset's Properties

func (*Any) GetStart

func (a *Any) GetStart() time.Time

Start returns the Asset's start time within the window

func (*Any) GetWindow

func (a *Any) GetWindow() Window

Window returns the Asset's window

func (*Any) InterfaceToAny

func (a *Any) InterfaceToAny(itf interface{}) error

Converts interface{} to Any, carrying over relevant fields

func (*Any) MarshalBinary

func (target *Any) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this Any instance into a byte array

func (*Any) MarshalBinaryWithContext

func (target *Any) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this Any instance into a byte array leveraging a predefined context.

func (*Any) MarshalJSON

func (a *Any) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Any) Minutes

func (a *Any) Minutes() float64

Minutes returns the number of minutes the Asset was active within the window

func (*Any) SanitizeNaN

func (a *Any) SanitizeNaN()

func (*Any) SetAdjustment

func (a *Any) SetAdjustment(adj float64)

SetAdjustment sets the Asset's cost adjustment

func (*Any) SetLabels

func (a *Any) SetLabels(labels AssetLabels)

SetLabels sets the Asset's labels

func (*Any) SetProperties

func (a *Any) SetProperties(props *AssetProperties)

SetProperties sets the Asset's Properties

func (*Any) SetStartEnd

func (a *Any) SetStartEnd(start, end time.Time)

SetStartEnd sets the Asset's Start and End fields

func (*Any) SetWindow

func (a *Any) SetWindow(window Window)

func (*Any) String

func (a *Any) String() string

String implements fmt.Stringer

func (*Any) TotalCost

func (a *Any) TotalCost() float64

TotalCost returns the Asset's TotalCost

func (*Any) Type

func (a *Any) Type() AssetType

Type returns the Asset's type

func (*Any) UnmarshalBinary

func (target *Any) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the Any type

func (*Any) UnmarshalBinaryWithContext

func (target *Any) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the Any type

func (*Any) UnmarshalJSON

func (a *Any) UnmarshalJSON(b []byte) error

type Asset

type Asset interface {
	// Type identifies the kind of Asset, which must always exist and should
	// be defined by the underlying type implementing the interface.
	Type() AssetType

	// GetProperties are a map of predefined traits, which may or may not exist,
	// but must conform to the AssetProperty schema
	GetProperties() *AssetProperties
	SetProperties(*AssetProperties)

	// GetLabels are a map of undefined string-to-string values
	GetLabels() AssetLabels
	SetLabels(AssetLabels)

	// Monetary values
	GetAdjustment() float64
	SetAdjustment(float64)
	TotalCost() float64

	// Temporal values
	GetStart() time.Time
	GetEnd() time.Time
	SetStartEnd(time.Time, time.Time)
	GetWindow() Window
	SetWindow(Window)
	ExpandWindow(Window)
	Minutes() float64

	// Operations and comparisons
	Add(Asset) Asset
	Clone() Asset
	Equal(Asset) bool
	SanitizeNaN()

	// Representations
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	json.Marshaler
	fmt.Stringer
}

Asset defines an entity within a cluster that has a defined cost over a given period of time.

type AssetAPIResponse

type AssetAPIResponse struct {
	Code int                   `json:"code"`
	Data AssetSetRangeResponse `json:"data"`
}

This is a helper type. The Asset API returns a json which cannot be natively unmarshaled into any Asset struct. Therefore, this struct IN COMBINATION WITH DESERIALIZATION LOGIC DEFINED IN asset_json.go can unmarshal a json directly from an Assets API query

type AssetAggregationOptions

type AssetAggregationOptions struct {
	SharedHourlyCosts map[string]float64
	Filter            filter21.Filter
	LabelConfig       *LabelConfig
}

type AssetLabels

type AssetLabels map[string]string

AssetLabels is a schema-free mapping of key/value pairs that can be attributed to an Asset as a flexible a

func (AssetLabels) Append

func (al AssetLabels) Append(newLabels map[string]string, overwrite bool)

Append joins AssetLabels with a given map of labels

func (AssetLabels) Clone

func (al AssetLabels) Clone() AssetLabels

Clone returns a cloned map of labels

func (AssetLabels) Equal

func (al AssetLabels) Equal(that AssetLabels) bool

Equal returns true only if the two set of labels are exact matches

func (AssetLabels) Merge

func (al AssetLabels) Merge(that AssetLabels) AssetLabels

Merge retains only the labels shared with the given AssetLabels

type AssetMatcher

type AssetMatcher matcher.Matcher[Asset]

AssetMatcher is a matcher implementation for Asset instances, compiled using the matcher.MatchCompiler.

type AssetProperties

type AssetProperties struct {
	Category   string `json:"category,omitempty"`
	Provider   string `json:"provider,omitempty"`
	Account    string `json:"account,omitempty"`
	Project    string `json:"project,omitempty"`
	Service    string `json:"service,omitempty"`
	Cluster    string `json:"cluster,omitempty"`
	Name       string `json:"name,omitempty"`
	ProviderID string `json:"providerID,omitempty"`
}

AssetProperties describes all properties assigned to an Asset.

func (*AssetProperties) Clone

func (ap *AssetProperties) Clone() *AssetProperties

Clone returns a cloned instance of the given AssetProperties

func (*AssetProperties) Equal

func (ap *AssetProperties) Equal(that *AssetProperties) bool

Equal returns true only if both AssetProperties are non-nil exact matches

func (*AssetProperties) Keys

func (ap *AssetProperties) Keys(props []AssetProperty) []string

Keys returns the list of string values used to key the Asset based on the list of properties provided.

func (*AssetProperties) MarshalBinary

func (target *AssetProperties) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this AssetProperties instance into a byte array

func (*AssetProperties) MarshalBinaryWithContext

func (target *AssetProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this AssetProperties instance into a byte array leveraging a predefined context.

func (*AssetProperties) Merge

Merge retains only the properties shared with the given AssetProperties

func (*AssetProperties) String

func (ap *AssetProperties) String() string

String represents the properties as a string

func (*AssetProperties) UnmarshalBinary

func (target *AssetProperties) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the AssetProperties type

func (*AssetProperties) UnmarshalBinaryWithContext

func (target *AssetProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the AssetProperties type

type AssetProperty

type AssetProperty string

AssetProperty is a kind of property belonging to an Asset

const (
	// AssetNilProp is the zero-value of AssetProperty
	AssetNilProp AssetProperty = ""

	// AssetAccountProp describes the account of the Asset
	AssetAccountProp AssetProperty = "account"

	// AssetCategoryProp describes the category of the Asset
	AssetCategoryProp AssetProperty = "category"

	// AssetClusterProp describes the cluster of the Asset
	AssetClusterProp AssetProperty = "cluster"

	// AssetNameProp describes the name of the Asset
	AssetNameProp AssetProperty = "name"

	// AssetNodeProp describes the node of the Asset
	AssetNodeProp AssetProperty = "node"

	// AssetProjectProp describes the project of the Asset
	AssetProjectProp AssetProperty = "project"

	// AssetProviderProp describes the provider of the Asset
	AssetProviderProp AssetProperty = "provider"

	// AssetProviderIDProp describes the providerID of the Asset
	AssetProviderIDProp AssetProperty = "providerID"

	// AssetServiceProp describes the service of the Asset
	AssetServiceProp AssetProperty = "service"

	// AssetTypeProp describes the type of the Asset
	AssetTypeProp AssetProperty = "type"

	// AssetDepartmentProp describes the department of the Asset
	AssetDepartmentProp AssetProperty = "department"

	// AssetEnvironmentProp describes the environment of the Asset
	AssetEnvironmentProp AssetProperty = "environment"

	// AssetOwnerProp describes the owner of the Asset
	AssetOwnerProp AssetProperty = "owner"

	// AssetProductProp describes the product of the Asset
	AssetProductProp AssetProperty = "product"

	// AssetTeamProp describes the team of the Asset
	AssetTeamProp AssetProperty = "team"
)

func ParseAssetProperty

func ParseAssetProperty(text string) (AssetProperty, error)

ParseAssetProperty attempts to parse a string into an AssetProperty

type AssetQuerier

type AssetQuerier interface {
	QueryAsset(start, end time.Time, opts *AssetQueryOptions) (*AssetSetRange, error)
}

AssetQuerier interface defining api for requesting Asset data

type AssetQueryOptions

type AssetQueryOptions struct {
	Accumulate              bool
	AggregateBy             []string
	Compute                 bool
	DisableAdjustments      bool
	DisableAggregatedStores bool
	Filter                  filter21.Filter
	IncludeCloud            bool
	SharedHourlyCosts       map[string]float64
	Step                    time.Duration
	LabelConfig             *LabelConfig
}

AssetQueryOptions defines optional parameters for querying an Asset Store

type AssetSet

type AssetSet struct {
	AggregationKeys   []string
	Assets            map[string]Asset
	Any               map[string]*Any               //@bingen:field[ignore]
	Cloud             map[string]*Cloud             //@bingen:field[ignore]
	ClusterManagement map[string]*ClusterManagement //@bingen:field[ignore]
	Disks             map[string]*Disk              //@bingen:field[ignore]
	Network           map[string]*Network           //@bingen:field[ignore]
	Nodes             map[string]*Node              //@bingen:field[ignore]
	LoadBalancers     map[string]*LoadBalancer      //@bingen:field[ignore]
	SharedAssets      map[string]*SharedAsset       //@bingen:field[ignore]
	FromSource        string                        // stores the name of the source used to compute the data
	Window            Window
	Warnings          []string
	Errors            []string
}

AssetSet stores a set of Assets, each with a unique name, that share a window. An AssetSet is mutable, so treat it like a threadsafe map.

func GenerateMockAssetSet

func GenerateMockAssetSet(start time.Time, duration time.Duration) *AssetSet

GenerateMockAssetSet generates the following topology:

| Asset | Cost | Adj | +------------------------------+------+------+

cluster1:
  node1:                        6.00   1.00
  node2:                        4.00   1.50
  node3:                        7.00  -0.50
  disk1:                        2.50   0.00
  disk2:                        1.50   0.00
  clusterManagement1:           3.00   0.00

+------------------------------+------+------+

cluster1 subtotal              24.00   2.00

+------------------------------+------+------+

cluster2:
  node4:                       12.00  -1.00
  disk3:                        2.50   0.00
  disk4:                        1.50   0.00
  clusterManagement2:           0.00   0.00

+------------------------------+------+------+

cluster2 subtotal              16.00  -1.00

+------------------------------+------+------+

cluster3:
  node5:                       17.00   2.00

+------------------------------+------+------+

cluster3 subtotal              17.00   2.00

+------------------------------+------+------+

total                          57.00   3.00

+------------------------------+------+------+

func GenerateMockAssetSets

func GenerateMockAssetSets(start, end time.Time) []*AssetSet

GenerateMockAssetSets creates generic AssetSets

func NewAssetSet

func NewAssetSet(start, end time.Time, assets ...Asset) *AssetSet

NewAssetSet instantiates a new AssetSet and, optionally, inserts the given list of Assets

func (*AssetSet) AggregateBy

func (as *AssetSet) AggregateBy(aggregateBy []string, opts *AssetAggregationOptions) error

AggregateBy aggregates the Assets in the AssetSet by the given list of AssetProperties, such that each asset is binned by a key determined by its relevant property values.

func (*AssetSet) Clone

func (as *AssetSet) Clone() *AssetSet

Clone returns a new AssetSet with a deep copy of the given AssetSet's assets.

func (*AssetSet) End

func (as *AssetSet) End() time.Time

End returns the end time of the AssetSet's window

func (*AssetSet) FindMatch

func (as *AssetSet) FindMatch(query Asset, aggregateBy []string, labelConfig *LabelConfig) (Asset, error)

FindMatch attempts to find a match in the AssetSet for the given Asset on the provided Properties and labels. If a match is not found, FindMatch returns nil and a Not Found error.

func (*AssetSet) Get

func (as *AssetSet) Get(key string) (Asset, bool)

Get returns the Asset in the AssetSet at the given key, or nil and false if no Asset exists for the given key

func (*AssetSet) GetWindow

func (as *AssetSet) GetWindow() Window

func (*AssetSet) Insert

func (as *AssetSet) Insert(asset Asset, labelConfig *LabelConfig) error

Insert inserts the given Asset into the AssetSet, using the AssetSet's configured Properties to determine the key under which the Asset will be inserted.

func (*AssetSet) IsEmpty

func (as *AssetSet) IsEmpty() bool

IsEmpty returns true if the AssetSet is nil, or if it contains zero assets.

func (*AssetSet) Length

func (as *AssetSet) Length() int

func (*AssetSet) MarshalBinary

func (target *AssetSet) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this AssetSet instance into a byte array

func (*AssetSet) MarshalBinaryWithContext

func (target *AssetSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this AssetSet instance into a byte array leveraging a predefined context.

func (*AssetSet) MarshalJSON

func (as *AssetSet) MarshalJSON() ([]byte, error)

MarshalJSON JSON-encodes the AssetSet

func (*AssetSet) ReconciliationMatch

func (as *AssetSet) ReconciliationMatch(query Asset) (Asset, bool, error)

ReconciliationMatch attempts to find an exact match in the AssetSet on (Category, ProviderID). If a match is found, it returns the Asset with the intent to adjust it. If no match exists, it attempts to find one on only (ProviderID). If that match is found, it returns the Asset with the intent to insert the associated Cloud cost.

func (*AssetSet) ReconciliationMatchMap

func (as *AssetSet) ReconciliationMatchMap() map[string]map[string]Asset

ReconciliationMatchMap returns a map of the calling AssetSet's Assets, by provider id and category. This data structure allows for reconciliation matching to be done in constant time and prevents duplicate reconciliation.

func (*AssetSet) Resolution

func (as *AssetSet) Resolution() time.Duration

Resolution returns the AssetSet's window duration

func (*AssetSet) SanitizeNaN

func (as *AssetSet) SanitizeNaN()

func (*AssetSet) Set

func (as *AssetSet) Set(asset Asset, aggregateBy []string, labelConfig *LabelConfig) error

func (*AssetSet) Start

func (as *AssetSet) Start() time.Time

func (*AssetSet) TotalCost

func (as *AssetSet) TotalCost() float64

func (*AssetSet) UTCOffset

func (as *AssetSet) UTCOffset() time.Duration

func (*AssetSet) UnmarshalBinary

func (target *AssetSet) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the AssetSet type

func (*AssetSet) UnmarshalBinaryWithContext

func (target *AssetSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the AssetSet type

type AssetSetRange

type AssetSetRange struct {
	Assets    []*AssetSet
	FromStore string // stores the name of the store used to retrieve the data
}

AssetSetRange is a thread-safe slice of AssetSets. It is meant to be used such that the AssetSets held are consecutive and coherent with respect to using the same aggregation Properties, UTC offset, and resolution. However these rules are not necessarily enforced, so use wisely.

func NewAssetSetRange

func NewAssetSetRange(assets ...*AssetSet) *AssetSetRange

NewAssetSetRange instantiates a new range composed of the given AssetSets in the order provided.

func (*AssetSetRange) Accumulate

func (asr *AssetSetRange) Accumulate(accumulateBy AccumulateOption) (*AssetSetRange, error)

func (*AssetSetRange) AccumulateToAssetSet

func (asr *AssetSetRange) AccumulateToAssetSet() (*AssetSet, error)

func (*AssetSetRange) AggregateBy

func (asr *AssetSetRange) AggregateBy(aggregateBy []string, opts *AssetAggregationOptions) error

func (*AssetSetRange) Append

func (asr *AssetSetRange) Append(that *AssetSet)

func (*AssetSetRange) End

func (asr *AssetSetRange) End() (time.Time, error)

End returns the latest end of all Assets in the AssetSetRange. It returns an error if there are no assets.

func (*AssetSetRange) Get

func (asr *AssetSetRange) Get(i int) (*AssetSet, error)

Get provides bounds checked access into the AssetSetRange's AssetSets.

func (*AssetSetRange) GetWarnings

func (asr *AssetSetRange) GetWarnings() []string

func (*AssetSetRange) HasWarnings

func (asr *AssetSetRange) HasWarnings() bool

func (*AssetSetRange) InsertRange

func (asr *AssetSetRange) InsertRange(that *AssetSetRange) error

InsertRange merges the given AssetSetRange into the receiving one by lining up sets with matching windows, then inserting each asset from the given ASR into the respective set in the receiving ASR. If the given ASR contains an AssetSetRange from a window that does not exist in the receiving ASR, then an error is returned. However, the given ASR does not need to cover the full range of the receiver.

func (*AssetSetRange) IsEmpty

func (asr *AssetSetRange) IsEmpty() bool

IsEmpty returns false if AssetSetRange contains a single AssetSet that is not empty

func (*AssetSetRange) Length

func (asr *AssetSetRange) Length() int

Length returns the total number of AssetSets in the range.

func (*AssetSetRange) MarshalBinary

func (target *AssetSetRange) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this AssetSetRange instance into a byte array

func (*AssetSetRange) MarshalBinaryWithContext

func (target *AssetSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this AssetSetRange instance into a byte array leveraging a predefined context.

func (*AssetSetRange) MarshalJSON

func (asr *AssetSetRange) MarshalJSON() ([]byte, error)

func (*AssetSetRange) Minutes

func (asr *AssetSetRange) Minutes() float64

Minutes returns the duration, in minutes, between the earliest start and the latest end of all assets in the AssetSetRange.

func (*AssetSetRange) Start

func (asr *AssetSetRange) Start() (time.Time, error)

Start returns the earliest start of all Assets in the AssetSetRange. It returns an error if there are no assets

func (*AssetSetRange) StartAndEnd

func (asr *AssetSetRange) StartAndEnd() (time.Time, time.Time, error)

Each iterates over all AssetSets in the AssetSetRange and returns the start and end over the entire range

func (*AssetSetRange) TotalCost

func (asr *AssetSetRange) TotalCost() float64

TotalCost returns the AssetSetRange's total cost

func (*AssetSetRange) UTCOffset

func (asr *AssetSetRange) UTCOffset() time.Duration

func (*AssetSetRange) UnmarshalBinary

func (target *AssetSetRange) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the AssetSetRange type

func (*AssetSetRange) UnmarshalBinaryWithContext

func (target *AssetSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the AssetSetRange type

func (*AssetSetRange) Window

func (asr *AssetSetRange) Window() Window

Window returns the full window that the AssetSetRange spans, from the start of the first AssetSet to the end of the last one.

type AssetSetRangeResponse

type AssetSetRangeResponse struct {
	Assets []*AssetSetResponse
}

As with AssetSet, AssetSetRange does not serialize all its fields, making it impossible to reconstruct the AssetSetRange from its json. Therefore, the type a marshaled AssetSetRange unmarshals to is AssetSetRangeResponse

func (*AssetSetRangeResponse) UnmarshalJSON

func (asrr *AssetSetRangeResponse) UnmarshalJSON(b []byte) error

type AssetSetResponse

type AssetSetResponse struct {
	Assets map[string]Asset
}

This type exists because only the assets map of AssetSet is marshaled to json, which makes it impossible to recreate an AssetSet struct. Thus, the type when unmarshaling a marshaled AssetSet,is AssetSetResponse

func (*AssetSetResponse) RawMessageToAssetSetResponse

func (asr *AssetSetResponse) RawMessageToAssetSetResponse(assetMap map[string]*json.RawMessage) error

func (*AssetSetResponse) UnmarshalJSON

func (asr *AssetSetResponse) UnmarshalJSON(b []byte) error

Unmarshals a marshaled AssetSet json into AssetSetResponse

type AssetTotals

type AssetTotals struct {
	Start                           time.Time `json:"start"`
	End                             time.Time `json:"end"`
	Cluster                         string    `json:"cluster"`
	Node                            string    `json:"node"`
	Count                           int       `json:"count"`
	AttachedVolumeCost              float64   `json:"attachedVolumeCost"`
	AttachedVolumeCostAdjustment    float64   `json:"attachedVolumeCostAdjustment"`
	ClusterManagementCost           float64   `json:"clusterManagementCost"`
	ClusterManagementCostAdjustment float64   `json:"clusterManagementCostAdjustment"`
	CPUCost                         float64   `json:"cpuCost"`
	CPUCostAdjustment               float64   `json:"cpuCostAdjustment"`
	GPUCost                         float64   `json:"gpuCost"`
	GPUCostAdjustment               float64   `json:"gpuCostAdjustment"`
	LoadBalancerCost                float64   `json:"loadBalancerCost"`
	LoadBalancerCostAdjustment      float64   `json:"loadBalancerCostAdjustment"`
	PersistentVolumeCost            float64   `json:"persistentVolumeCost"`
	PersistentVolumeCostAdjustment  float64   `json:"persistentVolumeCostAdjustment"`
	RAMCost                         float64   `json:"ramCost"`
	RAMCostAdjustment               float64   `json:"ramCostAdjustment"`
	PrivateLoadBalancer             bool      `json:"privateLoadBalancer"`
}

AssetTotals represents aggregate costs of all Assets for a given cluster or tuple of (cluster, node) between a given start and end time, where the costs are aggregated per-resource. AssetTotals is designed to be used as a pre-computed intermediate data structure when contextual knowledge is required to carry out a task, but computing totals on-the-fly would be expensive; e.g. idle allocation, shared tenancy costs

func (*AssetTotals) ClearAdjustments

func (art *AssetTotals) ClearAdjustments()

ClearAdjustments sets all adjustment fields to 0.0

func (*AssetTotals) Clone

func (art *AssetTotals) Clone() *AssetTotals

Clone deep copies the AssetTotals

func (*AssetTotals) TotalAttachedVolumeCost

func (art *AssetTotals) TotalAttachedVolumeCost() float64

TotalAttachedVolumeCost returns CPU cost with adjustment.

func (*AssetTotals) TotalCPUCost

func (art *AssetTotals) TotalCPUCost() float64

TotalCPUCost returns CPU cost with adjustment.

func (*AssetTotals) TotalClusterManagementCost

func (art *AssetTotals) TotalClusterManagementCost() float64

TotalClusterManagementCost returns ClusterManagement cost with adjustment.

func (*AssetTotals) TotalCost

func (art *AssetTotals) TotalCost() float64

TotalCost returns the sum of all costs

func (*AssetTotals) TotalGPUCost

func (art *AssetTotals) TotalGPUCost() float64

TotalGPUCost returns GPU cost with adjustment.

func (*AssetTotals) TotalLoadBalancerCost

func (art *AssetTotals) TotalLoadBalancerCost() float64

TotalLoadBalancerCost returns LoadBalancer cost with adjustment.

func (*AssetTotals) TotalPersistentVolumeCost

func (art *AssetTotals) TotalPersistentVolumeCost() float64

TotalPersistentVolumeCost returns PersistentVolume cost with adjustment.

func (*AssetTotals) TotalRAMCost

func (art *AssetTotals) TotalRAMCost() float64

TotalRAMCost returns RAM cost with adjustment.

type AssetTotalsResult

type AssetTotalsResult struct {
	Cluster map[string]*AssetTotals `json:"cluster"`
	Node    map[string]*AssetTotals `json:"node"`
}

type AssetTotalsSet

type AssetTotalsSet struct {
	Cluster map[string]*AssetTotals `json:"cluster"`
	Node    map[string]*AssetTotals `json:"node"`
	Window  Window                  `json:"window"`
}

AssetTotalsSet represents totals, summed by both "cluster" and "node" for a given window of time.

func NewAssetTotalsSet

func NewAssetTotalsSet(window Window, byCluster, byNode map[string]*AssetTotals) *AssetTotalsSet

func UpdateAssetTotalsStore

func UpdateAssetTotalsStore(arts AssetTotalsStore, as *AssetSet) (*AssetTotalsSet, error)

UpdateAssetTotalsStore updates an AssetTotalsStore by totaling the given AssetSet and saving the totals.

type AssetTotalsStore

type AssetTotalsStore interface {
	GetAssetTotalsByCluster(start, end time.Time) (map[string]*AssetTotals, bool)
	GetAssetTotalsByNode(start, end time.Time) (map[string]*AssetTotals, bool)
	SetAssetTotalsByCluster(start, end time.Time, rts map[string]*AssetTotals)
	SetAssetTotalsByNode(start, end time.Time, rts map[string]*AssetTotals)
}

AssetTotalsStore allows for storing (i.e. setting and getting) AssetTotals by cluster and by node.

type AssetType

type AssetType int

AssetType identifies a type of Asset

const (
	// AnyAssetType describes the Any AssetType
	AnyAssetType AssetType = iota

	// CloudAssetType describes the Cloud AssetType
	CloudAssetType

	// ClusterManagementAssetType describes the ClusterManagement AssetType
	ClusterManagementAssetType

	// DiskAssetType describes the Disk AssetType
	DiskAssetType

	// LoadBalancerAssetType describes the LoadBalancer AssetType
	LoadBalancerAssetType

	// NetworkAssetType describes the Network AssetType
	NetworkAssetType

	// NodeAssetType describes the Node AssetType
	NodeAssetType

	// SharedAssetType describes the Shared AssetType
	SharedAssetType
)

func ParseAssetType

func ParseAssetType(text string) (AssetType, error)

ParseAssetType attempts to parse the given string into an AssetType

func (AssetType) String

func (at AssetType) String() string

String converts the given AssetType to a string

type BinDecoder

type BinDecoder interface {
	UnmarshalBinaryWithContext(*DecodingContext) error
}

BinDecoder is a decoding interface which defines a context based unmarshal contract.

type BinEncoder

type BinEncoder interface {
	MarshalBinaryWithContext(*EncodingContext) error
}

BinEncoder is an encoding interface which defines a context based marshal contract.

type BoundaryError

type BoundaryError struct {
	Requested Window
	Supported Window
	Message   string
}

func NewBoundaryError

func NewBoundaryError(req, sup Window, msg string) *BoundaryError

func (*BoundaryError) Error

func (be *BoundaryError) Error() string

func (*BoundaryError) Is

func (be *BoundaryError) Is(target error) bool

type Breakdown

type Breakdown struct {
	Idle   float64 `json:"idle"`
	Other  float64 `json:"other"`
	System float64 `json:"system"`
	User   float64 `json:"user"`
}

Breakdown describes a resource's use as a percentage of various usage types

func (*Breakdown) Clone

func (b *Breakdown) Clone() *Breakdown

Clone returns a cloned instance of the Breakdown

func (*Breakdown) Equal

func (b *Breakdown) Equal(that *Breakdown) bool

Equal returns true if the two Breakdowns are exact matches

func (*Breakdown) MarshalBinary

func (target *Breakdown) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this Breakdown instance into a byte array

func (*Breakdown) MarshalBinaryWithContext

func (target *Breakdown) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this Breakdown instance into a byte array leveraging a predefined context.

func (*Breakdown) SanitizeNaN

func (b *Breakdown) SanitizeNaN()

func (*Breakdown) UnmarshalBinary

func (target *Breakdown) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the Breakdown type

func (*Breakdown) UnmarshalBinaryWithContext

func (target *Breakdown) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the Breakdown type

type Cloud

type Cloud struct {
	Labels     AssetLabels
	Properties *AssetProperties
	Start      time.Time
	End        time.Time
	Window     Window
	Adjustment float64
	Cost       float64
	Credit     float64 // Credit is a negative value representing dollars credited back to a given line-item
}

Cloud describes a cloud asset

func NewCloud

func NewCloud(category, providerID string, start, end time.Time, window Window) *Cloud

NewCloud returns a new Cloud Asset

func (*Cloud) Add

func (ca *Cloud) Add(a Asset) Asset

Add sums the Asset with the given Asset to produce a new Asset, maintaining as much relevant information as possible (i.e. type, Properties, labels).

func (*Cloud) Clone

func (ca *Cloud) Clone() Asset

Clone returns a cloned instance of the Asset

func (*Cloud) Equal

func (ca *Cloud) Equal(a Asset) bool

Equal returns true if the given Asset precisely equals the Asset

func (*Cloud) ExpandWindow

func (ca *Cloud) ExpandWindow(window Window)

ExpandWindow expands the Asset's window by the given window

func (*Cloud) GetAdjustment

func (ca *Cloud) GetAdjustment() float64

Adjustment returns the Asset's adjustment value

func (*Cloud) GetEnd

func (ca *Cloud) GetEnd() time.Time

End returns the Asset's precise end time within the window

func (*Cloud) GetLabels

func (ca *Cloud) GetLabels() AssetLabels

Labels returns the AssetLabels

func (*Cloud) GetProperties

func (ca *Cloud) GetProperties() *AssetProperties

Properties returns the AssetProperties

func (*Cloud) GetStart

func (ca *Cloud) GetStart() time.Time

Start returns the Asset's precise start time within the window

func (*Cloud) GetWindow

func (ca *Cloud) GetWindow() Window

Window returns the window within which the Asset ran

func (*Cloud) InterfaceToCloud

func (ca *Cloud) InterfaceToCloud(itf interface{}) error

Converts interface{} to Cloud, carrying over relevant fields

func (*Cloud) MarshalBinary

func (target *Cloud) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this Cloud instance into a byte array

func (*Cloud) MarshalBinaryWithContext

func (target *Cloud) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this Cloud instance into a byte array leveraging a predefined context.

func (*Cloud) MarshalJSON

func (ca *Cloud) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Cloud) Minutes

func (ca *Cloud) Minutes() float64

Minutes returns the number of Minutes the Asset ran

func (*Cloud) SanitizeNaN

func (ca *Cloud) SanitizeNaN()

func (*Cloud) SetAdjustment

func (ca *Cloud) SetAdjustment(adj float64)

SetAdjustment sets the Asset's adjustment value

func (*Cloud) SetLabels

func (ca *Cloud) SetLabels(labels AssetLabels)

SetLabels sets the Asset's labels

func (*Cloud) SetProperties

func (ca *Cloud) SetProperties(props *AssetProperties)

SetProperties sets the Asset's Properties

func (*Cloud) SetStartEnd

func (ca *Cloud) SetStartEnd(start, end time.Time)

SetStartEnd sets the Asset's Start and End fields

func (*Cloud) SetWindow

func (ca *Cloud) SetWindow(window Window)

func (*Cloud) String

func (ca *Cloud) String() string

String implements fmt.Stringer

func (*Cloud) TotalCost

func (ca *Cloud) TotalCost() float64

TotalCost returns the Asset's total cost

func (*Cloud) Type

func (ca *Cloud) Type() AssetType

Type returns the AssetType

func (*Cloud) UnmarshalBinary

func (target *Cloud) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the Cloud type

func (*Cloud) UnmarshalBinaryWithContext

func (target *Cloud) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the Cloud type

func (*Cloud) UnmarshalJSON

func (ca *Cloud) UnmarshalJSON(b []byte) error

type CloudAssetStatus

type CloudAssetStatus struct {
	Coverage    Window    `json:"coverage"`
	LastRun     time.Time `json:"lastRun"`
	NextRun     time.Time `json:"nextRun"`
	Progress    float64   `json:"progress"`
	RefreshRate string    `json:"refreshRate"`
	Resolution  string    `json:"resolution"`
	StartTime   time.Time `json:"startTime"`
}

CloudAssetStatus describes CloudAsset metadata of a CloudStore

type CloudCost

type CloudCost struct {
	Properties       *CloudCostProperties `json:"properties"`
	Window           Window               `json:"window"`
	ListCost         CostMetric           `json:"listCost"`
	NetCost          CostMetric           `json:"netCost"`
	AmortizedNetCost CostMetric           `json:"amortizedNetCost"`
	InvoicedCost     CostMetric           `json:"invoicedCost"`
	AmortizedCost    CostMetric           `json:"amortizedCost"`
}

CloudCost represents a CUR line item, identifying a cloud resource and its cost over some period of time.

func NewCloudCost

func NewCloudCost(start, end time.Time, ccProperties *CloudCostProperties, kubernetesPercent, listCost, netCost, amortizedNetCost, invoicedCost, amortizedCost float64) *CloudCost

NewCloudCost instantiates a new CloudCost

func (*CloudCost) Clone

func (cc *CloudCost) Clone() *CloudCost

func (*CloudCost) Equal

func (cc *CloudCost) Equal(that *CloudCost) bool

func (*CloudCost) GetCostMetric

func (cc *CloudCost) GetCostMetric(costMetricName string) (CostMetric, error)

func (*CloudCost) MarshalBinary

func (target *CloudCost) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this CloudCost instance into a byte array

func (*CloudCost) MarshalBinaryWithContext

func (target *CloudCost) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this CloudCost instance into a byte array leveraging a predefined context.

func (*CloudCost) StringMapProperty

func (cc *CloudCost) StringMapProperty(property string) (map[string]string, error)

func (*CloudCost) StringProperty

func (cc *CloudCost) StringProperty(prop string) (string, error)

func (*CloudCost) UnmarshalBinary

func (target *CloudCost) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the CloudCost type

func (*CloudCost) UnmarshalBinaryWithContext

func (target *CloudCost) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the CloudCost type

func (*CloudCost) WeightCostMetrics

func (cc *CloudCost) WeightCostMetrics(weightedAverge float64)

WeightCostMetrics weights all the cost metrics with the given weightedAverage

type CloudCostLabels

type CloudCostLabels map[string]string

func (CloudCostLabels) Clone

func (ccl CloudCostLabels) Clone() CloudCostLabels

func (CloudCostLabels) Equal

func (ccl CloudCostLabels) Equal(that CloudCostLabels) bool

func (CloudCostLabels) Intersection

func (ccl CloudCostLabels) Intersection(that CloudCostLabels) CloudCostLabels

Intersection returns the set of labels that have the same key and value in the receiver and arg

type CloudCostMatcher

type CloudCostMatcher matcher.Matcher[*CloudCost]

CloudCostMatcher is a matcher implementation for CloudCost instances, compiled using the matcher.MatchCompiler for cloud costs.

type CloudCostProperties

type CloudCostProperties struct {
	ProviderID      string          `json:"providerID,omitempty"`
	Provider        string          `json:"provider,omitempty"`
	AccountID       string          `json:"accountID,omitempty"`
	InvoiceEntityID string          `json:"invoiceEntityID,omitempty"`
	Service         string          `json:"service,omitempty"`
	Category        string          `json:"category,omitempty"`
	Labels          CloudCostLabels `json:"labels,omitempty"`
}

func (*CloudCostProperties) Clone

func (*CloudCostProperties) Equal

func (ccp *CloudCostProperties) Equal(that *CloudCostProperties) bool

func (*CloudCostProperties) GenerateKey

func (ccp *CloudCostProperties) GenerateKey(props []string) string

func (*CloudCostProperties) Intersection

Intersection ensure the values of two CloudCostAggregateProperties are maintain only if they are equal

func (*CloudCostProperties) MarshalBinary

func (target *CloudCostProperties) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this CloudCostProperties instance into a byte array

func (*CloudCostProperties) MarshalBinaryWithContext

func (target *CloudCostProperties) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this CloudCostProperties instance into a byte array leveraging a predefined context.

func (*CloudCostProperties) UnmarshalBinary

func (target *CloudCostProperties) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the CloudCostProperties type

func (*CloudCostProperties) UnmarshalBinaryWithContext

func (target *CloudCostProperties) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the CloudCostProperties type

type CloudCostSet

type CloudCostSet struct {
	CloudCosts            map[string]*CloudCost `json:"cloudCosts"`
	Window                Window                `json:"window"`
	Integration           string                `json:"-"`
	AggregationProperties []string              `json:"aggregationProperties"`
}

CloudCostSet follows the established set pattern of windowed data types. It has addition metadata types that can be used to preserve data consistency and be used for validation. - Integration is the ID for the integration that a CloudCostSet was sourced from, this value is cleared if when a set is joined with another with a different key - AggregationProperties is set by the Aggregate function and ensures that any additional inserts are keyed correctly

func NewCloudCostSet

func NewCloudCostSet(start, end time.Time, cloudCosts ...*CloudCost) *CloudCostSet

NewCloudCostSet instantiates a new CloudCostSet and, optionally, inserts the given list of CloudCosts

func (*CloudCostSet) Accumulate

func (ccs *CloudCostSet) Accumulate(that *CloudCostSet) (*CloudCostSet, error)

func (*CloudCostSet) Aggregate

func (ccs *CloudCostSet) Aggregate(props []string) (*CloudCostSet, error)

func (*CloudCostSet) Clone

func (ccs *CloudCostSet) Clone() *CloudCostSet

func (*CloudCostSet) Equal

func (ccs *CloudCostSet) Equal(that *CloudCostSet) bool

func (*CloudCostSet) Filter

func (ccs *CloudCostSet) Filter(filters filter.Filter[*CloudCost]) *CloudCostSet

func (*CloudCostSet) Filter21

func (ccs *CloudCostSet) Filter21(filters filter21.Filter) (*CloudCostSet, error)

func (*CloudCostSet) GetWindow

func (ccs *CloudCostSet) GetWindow() Window

func (*CloudCostSet) Insert

func (ccs *CloudCostSet) Insert(cc *CloudCost) error

Insert adds a CloudCost to a CloudCostSet using its AggregationProperties and LabelConfig to determine the key where it will be inserted

func (*CloudCostSet) IsEmpty

func (ccs *CloudCostSet) IsEmpty() bool

func (*CloudCostSet) Length

func (ccs *CloudCostSet) Length() int

func (*CloudCostSet) MarshalBinary

func (target *CloudCostSet) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this CloudCostSet instance into a byte array

func (*CloudCostSet) MarshalBinaryWithContext

func (target *CloudCostSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this CloudCostSet instance into a byte array leveraging a predefined context.

func (*CloudCostSet) Merge

func (ccs *CloudCostSet) Merge(that *CloudCostSet) (*CloudCostSet, error)

func (*CloudCostSet) UnmarshalBinary

func (target *CloudCostSet) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the CloudCostSet type

func (*CloudCostSet) UnmarshalBinaryWithContext

func (target *CloudCostSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the CloudCostSet type

type CloudCostSetRange

type CloudCostSetRange struct {
	CloudCostSets []*CloudCostSet `json:"sets"`
	Window        Window          `json:"window"`
}

func NewCloudCostSetRange

func NewCloudCostSetRange(start time.Time, end time.Time, window time.Duration, integration string) (*CloudCostSetRange, error)

NewCloudCostSetRange create a CloudCostSetRange containing CloudCostSets with windows of equal duration the duration between start and end must be divisible by the window duration argument

func (*CloudCostSetRange) Accumulate

func (ccsr *CloudCostSetRange) Accumulate() (*CloudCostSet, error)

Accumulate sums each CloudCostSet in the given range, returning a single cumulative CloudCostSet for the entire range.

func (*CloudCostSetRange) Clone

func (ccsr *CloudCostSetRange) Clone() *CloudCostSetRange

func (*CloudCostSetRange) IsEmpty

func (ccsr *CloudCostSetRange) IsEmpty() bool

func (*CloudCostSetRange) LoadCloudCost

func (ccsr *CloudCostSetRange) LoadCloudCost(cloudCost *CloudCost)

LoadCloudCost loads CloudCosts into existing CloudCostSets of the CloudCostSetRange. This function service to aggregate and distribute costs over predefined windows are accumulated here so that the resulting CloudCost with the 1d window has the correct price for the entire day. If all or a portion of the window of the CloudCost is outside of the windows of the existing CloudCostSets, that portion of the CloudCost's cost will not be inserted

func (*CloudCostSetRange) MarshalBinary

func (target *CloudCostSetRange) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this CloudCostSetRange instance into a byte array

func (*CloudCostSetRange) MarshalBinaryWithContext

func (target *CloudCostSetRange) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this CloudCostSetRange instance into a byte array leveraging a predefined context.

func (*CloudCostSetRange) UnmarshalBinary

func (target *CloudCostSetRange) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the CloudCostSetRange type

func (*CloudCostSetRange) UnmarshalBinaryWithContext

func (target *CloudCostSetRange) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the CloudCostSetRange type

type CloudStatus

type CloudStatus struct {
	ConnectionStatus string                `json:"cloudConnectionStatus"`
	ProviderType     string                `json:"providerType"`
	CloudUsage       *CloudAssetStatus     `json:"cloudUsage,omitempty"`
	Reconciliation   *ReconciliationStatus `json:"reconciliation,omitempty"`
}

CloudStatus describes CloudStore metadata

type CloudUsage

type CloudUsage = Cloud

CloudUsage is temporarily aliased as the Cloud Asset type until further infrastructure and pages can be built to support its usage

type CloudUsageAggregationOptions

type CloudUsageAggregationOptions = AssetAggregationOptions

CloudUsageAggregationOptions is temporarily aliased as the AssetAggregationOptions until further infrastructure and pages can be built to support its usage

type CloudUsageFilter

type CloudUsageFilter struct {
	Categories  []string            `json:"categories"`
	Providers   []string            `json:"providers"`
	ProviderIDs []string            `json:"providerIDs"`
	Accounts    []string            `json:"accounts"`
	Projects    []string            `json:"projects"`
	Services    []string            `json:"services"`
	Labels      map[string][]string `json:"labels"`
}

type CloudUsageQuerier

type CloudUsageQuerier interface {
	QueryCloudUsage(start, end time.Time, opts *CloudUsageQueryOptions) (*CloudUsageSetRange, error)
}

CloudUsageQuerier interface defining api for requesting CloudUsage data

type CloudUsageQueryOptions

type CloudUsageQueryOptions struct {
	Accumulate   bool
	AggregateBy  []string
	Compute      bool
	Filter       filter21.Filter
	FilterValues CloudUsageFilter
	LabelConfig  *LabelConfig
}

CloudUsageQueryOptions define optional parameters for querying a Store

type CloudUsageSet

type CloudUsageSet = AssetSet

CloudUsageSet is temporarily aliased as the AssetSet until further infrastructure and pages can be built to support its usage

type CloudUsageSetRange

type CloudUsageSetRange = AssetSetRange

CloudUsageSetRange is temporarily aliased as the AssetSetRange until further infrastructure and pages can be built to support its usage

type ClusterManagement

type ClusterManagement struct {
	Labels     AssetLabels
	Properties *AssetProperties
	Window     Window
	Cost       float64
	Adjustment float64 // @bingen:field[version=16]
}

ClusterManagement describes a provider's cluster management fee

func NewClusterManagement

func NewClusterManagement(provider, cluster string, window Window) *ClusterManagement

NewClusterManagement creates and returns a new ClusterManagement instance

func (*ClusterManagement) Add

func (cm *ClusterManagement) Add(a Asset) Asset

Add sums the Asset with the given Asset to produce a new Asset, maintaining as much relevant information as possible (i.e. type, Properties, labels).

func (*ClusterManagement) Clone

func (cm *ClusterManagement) Clone() Asset

Clone returns a cloned instance of the Asset

func (*ClusterManagement) Equal

func (cm *ClusterManagement) Equal(a Asset) bool

Equal returns true if the given Asset exactly matches the Asset

func (*ClusterManagement) ExpandWindow

func (cm *ClusterManagement) ExpandWindow(window Window)

ExpandWindow expands the Asset's window by the given window

func (*ClusterManagement) GetAdjustment

func (cm *ClusterManagement) GetAdjustment() float64

Adjustment does not apply to ClusterManagement

func (*ClusterManagement) GetEnd

func (cm *ClusterManagement) GetEnd() time.Time

End returns the Asset's precise end time within the window

func (*ClusterManagement) GetLabels

func (cm *ClusterManagement) GetLabels() AssetLabels

Labels returns the Asset's labels

func (*ClusterManagement) GetProperties

func (cm *ClusterManagement) GetProperties() *AssetProperties

Properties returns the Asset's Properties

func (*ClusterManagement) GetStart

func (cm *ClusterManagement) GetStart() time.Time

Start returns the Asset's precise start time within the window

func (*ClusterManagement) GetWindow

func (cm *ClusterManagement) GetWindow() Window

Window return the Asset's window

func (*ClusterManagement) InterfaceToClusterManagement

func (cm *ClusterManagement) InterfaceToClusterManagement(itf interface{}) error

Converts interface{} to ClusterManagement, carrying over relevant fields

func (*ClusterManagement) MarshalBinary

func (target *ClusterManagement) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this ClusterManagement instance into a byte array

func (*ClusterManagement) MarshalBinaryWithContext

func (target *ClusterManagement) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this ClusterManagement instance into a byte array leveraging a predefined context.

func (*ClusterManagement) MarshalJSON

func (cm *ClusterManagement) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshler

func (*ClusterManagement) Minutes

func (cm *ClusterManagement) Minutes() float64

Minutes returns the number of minutes the Asset ran

func (*ClusterManagement) SanitizeNaN

func (cm *ClusterManagement) SanitizeNaN()

func (*ClusterManagement) SetAdjustment

func (cm *ClusterManagement) SetAdjustment(adj float64)

SetAdjustment does not apply to ClusterManagement

func (*ClusterManagement) SetLabels

func (cm *ClusterManagement) SetLabels(props AssetLabels)

SetLabels sets the Asset's Properties

func (*ClusterManagement) SetProperties

func (cm *ClusterManagement) SetProperties(props *AssetProperties)

SetProperties sets the Asset's Properties

func (*ClusterManagement) SetStartEnd

func (cm *ClusterManagement) SetStartEnd(start, end time.Time)

SetStartEnd sets the Asset's Start and End fields (not applicable here)

func (*ClusterManagement) SetWindow

func (cm *ClusterManagement) SetWindow(window Window)

func (*ClusterManagement) String

func (cm *ClusterManagement) String() string

String implements fmt.Stringer

func (*ClusterManagement) TotalCost

func (cm *ClusterManagement) TotalCost() float64

TotalCost returns the Asset's total cost

func (*ClusterManagement) Type

func (cm *ClusterManagement) Type() AssetType

Type returns the Asset's type

func (*ClusterManagement) UnmarshalBinary

func (target *ClusterManagement) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the ClusterManagement type

func (*ClusterManagement) UnmarshalBinaryWithContext

func (target *ClusterManagement) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the ClusterManagement type

func (*ClusterManagement) UnmarshalJSON

func (cm *ClusterManagement) UnmarshalJSON(b []byte) error

type CostMetric

type CostMetric struct {
	Cost              float64 `json:"cost"`
	KubernetesPercent float64 `json:"kubernetesPercent"`
}

func (CostMetric) Clone

func (cm CostMetric) Clone() CostMetric

func (CostMetric) Equal

func (cm CostMetric) Equal(that CostMetric) bool

func (*CostMetric) MarshalBinary

func (target *CostMetric) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this CostMetric instance into a byte array

func (*CostMetric) MarshalBinaryWithContext

func (target *CostMetric) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this CostMetric instance into a byte array leveraging a predefined context.

func (*CostMetric) UnmarshalBinary

func (target *CostMetric) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the CostMetric type

func (*CostMetric) UnmarshalBinaryWithContext

func (target *CostMetric) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the CostMetric type

type Coverage

type Coverage struct {
	Window   Window    `json:"window"`
	Type     string    `json:"type"`
	Count    int       `json:"count"`
	Updated  time.Time `json:"updated"`
	Errors   []string  `json:"errors"`
	Warnings []string  `json:"warnings"`
}

Coverage This is a placeholder struct which can be replaced by a more specific implementation later

func (*Coverage) Clone

func (c *Coverage) Clone() *Coverage

func (*Coverage) GetWindow

func (c *Coverage) GetWindow() Window

func (*Coverage) IsEmpty

func (c *Coverage) IsEmpty() bool

func (*Coverage) Key

func (c *Coverage) Key() string

func (*Coverage) MarshalBinary

func (target *Coverage) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this Coverage instance into a byte array

func (*Coverage) MarshalBinaryWithContext

func (target *Coverage) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this Coverage instance into a byte array leveraging a predefined context.

func (*Coverage) UnmarshalBinary

func (target *Coverage) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the Coverage type

func (*Coverage) UnmarshalBinaryWithContext

func (target *Coverage) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the Coverage type

type CoverageSet

type CoverageSet struct {
	Window Window               `json:"window"`
	Items  map[string]*Coverage `json:"items"`
}

Coverage This is a placeholder struct which can be replaced by a more specific implementation later

func NewCoverageSet

func NewCoverageSet(start, end time.Time) *CoverageSet

func (*CoverageSet) Clone

func (cs *CoverageSet) Clone() *CoverageSet

func (*CoverageSet) Filter

func (cs *CoverageSet) Filter(filters filter.Filter[*Coverage]) *CoverageSet

func (*CoverageSet) GetWindow

func (cs *CoverageSet) GetWindow() Window

func (*CoverageSet) Insert

func (cs *CoverageSet) Insert(coverage *Coverage)

func (*CoverageSet) IsEmpty

func (cs *CoverageSet) IsEmpty() bool

func (*CoverageSet) MarshalBinary

func (target *CoverageSet) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this CoverageSet instance into a byte array

func (*CoverageSet) MarshalBinaryWithContext

func (target *CoverageSet) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this CoverageSet instance into a byte array leveraging a predefined context.

func (*CoverageSet) UnmarshalBinary

func (target *CoverageSet) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the CoverageSet type

func (*CoverageSet) UnmarshalBinaryWithContext

func (target *CoverageSet) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the CoverageSet type

type DecodingContext

type DecodingContext struct {
	Buffer *util.Buffer
	Table  []string
}

DecodingContext is a context object passed to the decoders to ensure parent objects reuse as much data as possible

func (*DecodingContext) IsStringTable

func (dc *DecodingContext) IsStringTable() bool

IsStringTable returns true if the table is available

type Diff

type Diff[T any] struct {
	Before T
	After  T
	Kind   DiffKind
}

Diff stores an object and a string that denotes whether that object was added or removed from a set of those objects

type DiffKind

type DiffKind string

type DirectoryStatus

type DirectoryStatus struct {
	Path         string       `json:"path"`
	Size         string       `json:"size"`
	LastModified time.Time    `json:"lastModified"`
	FileCount    int          `json:"fileCount"`
	Files        []FileStatus `json:"files"`
}

DirectoryStatus describes metadata of a directory of files

type Disk

type Disk struct {
	Labels         AssetLabels
	Properties     *AssetProperties
	Start          time.Time
	End            time.Time
	Window         Window
	Adjustment     float64
	Cost           float64
	ByteHours      float64
	Local          float64
	Breakdown      *Breakdown
	StorageClass   string   // @bingen:field[version=17]
	ByteHoursUsed  *float64 // @bingen:field[version=18]
	ByteUsageMax   *float64 // @bingen:field[version=18]
	VolumeName     string   // @bingen:field[version=18]
	ClaimName      string   // @bingen:field[version=18]
	ClaimNamespace string   // @bingen:field[version=18]
}

Disk represents an in-cluster disk Asset

func NewDisk

func NewDisk(name, cluster, providerID string, start, end time.Time, window Window) *Disk

NewDisk creates and returns a new Disk Asset

func (*Disk) Add

func (d *Disk) Add(a Asset) Asset

Add sums the Asset with the given Asset to produce a new Asset, maintaining as much relevant information as possible (i.e. type, Properties, labels).

func (*Disk) Bytes

func (d *Disk) Bytes() float64

Bytes returns the number of bytes belonging to the disk. This could be fractional because it's the number of byte*hours divided by the number of hours running; e.g. the sum of a 100GiB disk running for the first 10 hours and a 30GiB disk running for the last 20 hours of the same 24-hour window would produce:

(100*10 + 30*20) / 24 = 66.667GiB

However, any number of disks running for the full span of a window will report the actual number of bytes of the static disk; e.g. the above scenario for one entire 24-hour window:

(100*24 + 30*24) / 24 = (100 + 30) = 130GiB

func (*Disk) Clone

func (d *Disk) Clone() Asset

Clone returns a cloned instance of the Asset

func (*Disk) Equal

func (d *Disk) Equal(a Asset) bool

Equal returns true if the two Assets match exactly

func (*Disk) ExpandWindow

func (d *Disk) ExpandWindow(window Window)

ExpandWindow expands the Asset's window by the given window

func (*Disk) GetAdjustment

func (d *Disk) GetAdjustment() float64

Adjustment returns the Asset's cost adjustment

func (*Disk) GetEnd

func (d *Disk) GetEnd() time.Time

End returns the precise start time of the Asset within the window

func (*Disk) GetLabels

func (d *Disk) GetLabels() AssetLabels

Labels returns the Asset's labels

func (*Disk) GetProperties

func (d *Disk) GetProperties() *AssetProperties

Properties returns the Asset's Properties

func (*Disk) GetStart

func (d *Disk) GetStart() time.Time

Start returns the precise start time of the Asset within the window

func (*Disk) GetWindow

func (d *Disk) GetWindow() Window

Window returns the window within which the Asset

func (*Disk) InterfaceToDisk

func (d *Disk) InterfaceToDisk(itf interface{}) error

Converts interface{} to Disk, carrying over relevant fields

func (*Disk) MarshalBinary

func (target *Disk) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this Disk instance into a byte array

func (*Disk) MarshalBinaryWithContext

func (target *Disk) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this Disk instance into a byte array leveraging a predefined context.

func (*Disk) MarshalJSON

func (d *Disk) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*Disk) Minutes

func (d *Disk) Minutes() float64

Minutes returns the number of minutes the Asset ran

func (*Disk) SanitizeNaN

func (d *Disk) SanitizeNaN()

func (*Disk) SetAdjustment

func (d *Disk) SetAdjustment(adj float64)

SetAdjustment sets the Asset's cost adjustment

func (*Disk) SetLabels

func (d *Disk) SetLabels(labels AssetLabels)

SetLabels sets the Asset's labels

func (*Disk) SetProperties

func (d *Disk) SetProperties(props *AssetProperties)

SetProperties sets the Asset's Properties

func (*Disk) SetStartEnd

func (d *Disk) SetStartEnd(start, end time.Time)

SetStartEnd sets the Asset's Start and End fields

func (*Disk) SetWindow

func (d *Disk) SetWindow(window Window)

func (*Disk) String

func (d *Disk) String() string

String implements fmt.Stringer

func (*Disk) TotalCost

func (d *Disk) TotalCost() float64

TotalCost returns the Asset's total cost

func (*Disk) Type

func (d *Disk) Type() AssetType

Type returns the AssetType of the Asset

func (*Disk) UnmarshalBinary

func (target *Disk) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the Disk type

func (*Disk) UnmarshalBinaryWithContext

func (target *Disk) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the Disk type

func (*Disk) UnmarshalJSON

func (d *Disk) UnmarshalJSON(b []byte) error

type ETLStatus

type ETLStatus struct {
	Coverage                   Window           `json:"coverage"`
	LastRun                    time.Time        `json:"lastRun"`
	Progress                   float64          `json:"progress"`
	RefreshRate                string           `json:"refreshRate"`
	Resolution                 string           `json:"resolution"`
	MaxPrometheusQueryDuration string           `json:"maxPrometheusQueryDuration"`
	StartTime                  time.Time        `json:"startTime"`
	UTCOffset                  string           `json:"utcOffset"`
	Backup                     *DirectoryStatus `json:"backup,omitempty"`
}

ETLStatus describes ETL metadata

type EncodingContext

type EncodingContext struct {
	Buffer *util.Buffer
	Table  *StringTable
}

EncodingContext is a context object passed to the encoders to ensure reuse of buffer and table data

func (*EncodingContext) IsStringTable

func (ec *EncodingContext) IsStringTable() bool

IsStringTable returns true if the table is available

type FileStatus

type FileStatus struct {
	Name         string            `json:"name"`
	Size         string            `json:"size"`
	LastModified time.Time         `json:"lastModified"`
	IsRepairing  bool              `json:"isRepairing"`
	Details      map[string]string `json:"details,omitempty"`
	Errors       []string          `json:"errors,omitempty"`
	Warnings     []string          `json:"warnings,omitempty"`
}

FileStatus describes the metadata of a single file

type LabelConfig

type LabelConfig struct {
	DepartmentLabel          string `json:"department_label"`
	EnvironmentLabel         string `json:"environment_label"`
	OwnerLabel               string `json:"owner_label"`
	ProductLabel             string `json:"product_label"`
	TeamLabel                string `json:"team_label"`
	ClusterExternalLabel     string `json:"cluster_external_label"`
	NamespaceExternalLabel   string `json:"namespace_external_label"`
	ControllerExternalLabel  string `json:"controller_external_label"`
	DaemonsetExternalLabel   string `json:"daemonset_external_label"`
	DeploymentExternalLabel  string `json:"deployment_external_label"`
	StatefulsetExternalLabel string `json:"statefulset_external_label"`
	ServiceExternalLabel     string `json:"service_external_label"`
	PodExternalLabel         string `json:"pod_external_label"`
	DepartmentExternalLabel  string `json:"department_external_label"`
	EnvironmentExternalLabel string `json:"environment_external_label"`
	OwnerExternalLabel       string `json:"owner_external_label"`
	ProductExternalLabel     string `json:"product_external_label"`
	TeamExternalLabel        string `json:"team_external_label"`
}

LabelConfig is a port of type AnalyzerConfig. We need to be more thoughtful about design at some point, but this is a stop-gap measure, which is required because AnalyzerConfig is defined in package main, so it can't be imported.

func NewLabelConfig

func NewLabelConfig() *LabelConfig

NewLabelConfig creates a new LabelConfig instance with default values.

func (*LabelConfig) GetExternalAllocationName

func (lc *LabelConfig) GetExternalAllocationName(labels map[string]string, aggregateBy string) string

GetExternalAllocationName derives an external allocation name from a set of labels, given an aggregation property. If the aggregation property is, itself, a label (e.g. label:app) then this function looks for a corresponding value under "app" and returns "app=thatvalue". If the aggregation property is not a label but a Kubernetes concept (e.g. namespace) then this function first finds the "external label" configured to represent it (e.g. NamespaceExternalLabel: "kubens") and uses that label to determine an external allocation name. If no label value can be found, return an empty string.

func (*LabelConfig) Map

func (lc *LabelConfig) Map() map[string]string

Map returns the config as a basic string map, with default values if not set

func (*LabelConfig) Sanitize

func (lc *LabelConfig) Sanitize(label string) string

Sanitize returns a sanitized version of the given string, which converts all illegal characters to underscores. Illegal characters are those that Prometheus does not support; i.e. [^a-zA-Z0-9_]

type LbAllocation

type LbAllocation struct {
	Service string  `json:"service"`
	Cost    float64 `json:"cost"`
	Private bool    `json:"private"`
	Ip      string  `json:"ip"` //@bingen:field[version=19]
}

func (*LbAllocation) MarshalBinary

func (target *LbAllocation) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this LbAllocation instance into a byte array

func (*LbAllocation) MarshalBinaryWithContext

func (target *LbAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this LbAllocation instance into a byte array leveraging a predefined context.

func (*LbAllocation) SanitizeNaN

func (lba *LbAllocation) SanitizeNaN()

func (*LbAllocation) UnmarshalBinary

func (target *LbAllocation) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the LbAllocation type

func (*LbAllocation) UnmarshalBinaryWithContext

func (target *LbAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the LbAllocation type

type LbAllocations

type LbAllocations map[string]*LbAllocation

func (LbAllocations) Add

func (thisLbAllocs LbAllocations) Add(thatLbAllocs LbAllocations) LbAllocations

func (LbAllocations) Clone

func (orig LbAllocations) Clone() LbAllocations

func (LbAllocations) SanitizeNaN

func (thisLbAllocs LbAllocations) SanitizeNaN()

type LoadBalancer

type LoadBalancer struct {
	Properties *AssetProperties
	Labels     AssetLabels
	Start      time.Time
	End        time.Time
	Window     Window
	Adjustment float64
	Cost       float64
	Private    bool   // @bingen:field[version=20]
	Ip         string // @bingen:field[version=21]
}

LoadBalancer is an Asset representing a single load balancer in a cluster TODO: add GB of ingress processed, numForwardingRules once we start recording those to prometheus metric

func NewLoadBalancer

func NewLoadBalancer(name, cluster, providerID string, start, end time.Time, window Window, private bool, ip string) *LoadBalancer

NewLoadBalancer instantiates and returns a new LoadBalancer

func (*LoadBalancer) Add

func (lb *LoadBalancer) Add(a Asset) Asset

Add sums the Asset with the given Asset to produce a new Asset, maintaining as much relevant information as possible (i.e. type, Properties, labels).

func (*LoadBalancer) Clone

func (lb *LoadBalancer) Clone() Asset

Clone returns a cloned instance of the given Asset

func (*LoadBalancer) Equal

func (lb *LoadBalancer) Equal(a Asset) bool

Equal returns true if the two Assets match precisely

func (*LoadBalancer) ExpandWindow

func (lb *LoadBalancer) ExpandWindow(w Window)

ExpandWindow expands the Asset's window by the given window

func (*LoadBalancer) GetAdjustment

func (lb *LoadBalancer) GetAdjustment() float64

Adjustment returns the Asset's cost adjustment

func (*LoadBalancer) GetEnd

func (lb *LoadBalancer) GetEnd() time.Time

End returns the preceise end point of the Asset within the window

func (*LoadBalancer) GetLabels

func (lb *LoadBalancer) GetLabels() AssetLabels

Labels returns the Asset's labels

func (*LoadBalancer) GetProperties

func (lb *LoadBalancer) GetProperties() *AssetProperties

Properties returns the Asset's Properties

func (*LoadBalancer) GetStart

func (lb *LoadBalancer) GetStart() time.Time

Start returns the preceise start point of the Asset within the window

func (*LoadBalancer) GetWindow

func (lb *LoadBalancer) GetWindow() Window

Window returns the window within which the Asset ran

func (*LoadBalancer) InterfaceToLoadBalancer

func (lb *LoadBalancer) InterfaceToLoadBalancer(itf interface{}) error

Converts interface{} to LoadBalancer, carrying over relevant fields

func (*LoadBalancer) MarshalBinary

func (target *LoadBalancer) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this LoadBalancer instance into a byte array

func (*LoadBalancer) MarshalBinaryWithContext

func (target *LoadBalancer) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this LoadBalancer instance into a byte array leveraging a predefined context.

func (*LoadBalancer) MarshalJSON

func (lb *LoadBalancer) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshal

func (*LoadBalancer) Minutes

func (lb *LoadBalancer) Minutes() float64

Minutes returns the number of minutes the Asset ran within the window

func (*LoadBalancer) SanitizeNaN

func (lb *LoadBalancer) SanitizeNaN()

func (*LoadBalancer) SetAdjustment

func (lb *LoadBalancer) SetAdjustment(adj float64)

SetAdjustment sets the Asset's cost adjustment

func (*LoadBalancer) SetLabels

func (lb *LoadBalancer) SetLabels(labels AssetLabels)

SetLabels sets the Asset's labels

func (*LoadBalancer) SetProperties

func (lb *LoadBalancer) SetProperties(props *AssetProperties)

SetProperties sets the Asset's Properties

func (*LoadBalancer) SetStartEnd

func (lb *LoadBalancer) SetStartEnd(start, end time.Time)

SetStartEnd sets the Asset's Start and End fields

func (*LoadBalancer) SetWindow

func (lb *LoadBalancer) SetWindow(window Window)

func (*LoadBalancer) String

func (lb *LoadBalancer) String() string

String implements fmt.Stringer

func (*LoadBalancer) TotalCost

func (lb *LoadBalancer) TotalCost() float64

TotalCost returns the total cost of the Asset

func (*LoadBalancer) Type

func (lb *LoadBalancer) Type() AssetType

Type returns the AssetType of the Asset

func (*LoadBalancer) UnmarshalBinary

func (target *LoadBalancer) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the LoadBalancer type

func (*LoadBalancer) UnmarshalBinaryWithContext

func (target *LoadBalancer) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the LoadBalancer type

func (*LoadBalancer) UnmarshalJSON

func (lb *LoadBalancer) UnmarshalJSON(b []byte) error

type MemoryTotalsStore

type MemoryTotalsStore struct {
	// contains filtered or unexported fields
}

MemoryTotalsStore is an in-memory cache TotalsStore

func NewMemoryTotalsStore

func NewMemoryTotalsStore() *MemoryTotalsStore

NewMemoryTotalsStore instantiates a new MemoryTotalsStore, which is composed of four in-memory caches.

func (*MemoryTotalsStore) GetAllocationTotalsByCluster

func (mts *MemoryTotalsStore) GetAllocationTotalsByCluster(start time.Time, end time.Time) (map[string]*AllocationTotals, bool)

GetAllocationTotalsByCluster retrieves the AllocationTotals by cluster for the given start and end times.

func (*MemoryTotalsStore) GetAllocationTotalsByNode

func (mts *MemoryTotalsStore) GetAllocationTotalsByNode(start time.Time, end time.Time) (map[string]*AllocationTotals, bool)

GetAllocationTotalsByNode retrieves the AllocationTotals by node for the given start and end times.

func (*MemoryTotalsStore) GetAssetTotalsByCluster

func (mts *MemoryTotalsStore) GetAssetTotalsByCluster(start time.Time, end time.Time) (map[string]*AssetTotals, bool)

GetAssetTotalsByCluster retrieves the AssetTotals by cluster for the given start and end times.

func (*MemoryTotalsStore) GetAssetTotalsByNode

func (mts *MemoryTotalsStore) GetAssetTotalsByNode(start time.Time, end time.Time) (map[string]*AssetTotals, bool)

GetAssetTotalsByNode retrieves the AssetTotals by node for the given start and end times.

func (*MemoryTotalsStore) SetAllocationTotalsByCluster

func (mts *MemoryTotalsStore) SetAllocationTotalsByCluster(start time.Time, end time.Time, arts map[string]*AllocationTotals)

SetAllocationTotalsByCluster set the per-cluster AllocationTotals to the given values for the given start and end times.

func (*MemoryTotalsStore) SetAllocationTotalsByNode

func (mts *MemoryTotalsStore) SetAllocationTotalsByNode(start time.Time, end time.Time, arts map[string]*AllocationTotals)

SetAllocationTotalsByNode set the per-node AllocationTotals to the given values for the given start and end times.

func (*MemoryTotalsStore) SetAssetTotalsByCluster

func (mts *MemoryTotalsStore) SetAssetTotalsByCluster(start time.Time, end time.Time, arts map[string]*AssetTotals)

SetAssetTotalsByCluster set the per-cluster AssetTotals to the given values for the given start and end times.

func (*MemoryTotalsStore) SetAssetTotalsByNode

func (mts *MemoryTotalsStore) SetAssetTotalsByNode(start time.Time, end time.Time, arts map[string]*AssetTotals)

SetAssetTotalsByNode set the per-node AssetTotals to the given values for the given start and end times.

type Network

type Network struct {
	Properties *AssetProperties
	Labels     AssetLabels
	Start      time.Time
	End        time.Time
	Window     Window
	Adjustment float64
	Cost       float64
}

Network is an Asset representing a single node's network costs

func NewNetwork

func NewNetwork(name, cluster, providerID string, start, end time.Time, window Window) *Network

NewNetwork creates and returns a new Network Asset

func (*Network) Add

func (n *Network) Add(a Asset) Asset

Add sums the Asset with the given Asset to produce a new Asset, maintaining as much relevant information as possible (i.e. type, Properties, labels).

func (*Network) Clone

func (n *Network) Clone() Asset

Clone returns a deep copy of the given Network

func (*Network) Equal

func (n *Network) Equal(a Asset) bool

Equal returns true if the tow Assets match exactly

func (*Network) ExpandWindow

func (n *Network) ExpandWindow(window Window)

ExpandWindow expands the Asset's window by the given window

func (*Network) GetAdjustment

func (n *Network) GetAdjustment() float64

Adjustment returns the Asset's cost adjustment

func (*Network) GetEnd

func (n *Network) GetEnd() time.Time

End returns the precise end time of the Asset within the window

func (*Network) GetLabels

func (n *Network) GetLabels() AssetLabels

Labels returns the Asset's labels

func (*Network) GetProperties

func (n *Network) GetProperties() *AssetProperties

Properties returns the Asset's Properties

func (*Network) GetStart

func (n *Network) GetStart() time.Time

Start returns the precise start time of the Asset within the window

func (*Network) GetWindow

func (n *Network) GetWindow() Window

Window returns the window within which the Asset ran

func (*Network) InterfaceToNetwork

func (n *Network) InterfaceToNetwork(itf interface{}) error

Converts interface{} to Network, carrying over relevant fields

func (*Network) MarshalBinary

func (target *Network) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this Network instance into a byte array

func (*Network) MarshalBinaryWithContext

func (target *Network) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this Network instance into a byte array leveraging a predefined context.

func (*Network) MarshalJSON

func (n *Network) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshal interface

func (*Network) Minutes

func (n *Network) Minutes() float64

Minutes returns the number of minutes the Asset ran within the window

func (*Network) SanitizeNaN

func (n *Network) SanitizeNaN()

func (*Network) SetAdjustment

func (n *Network) SetAdjustment(adj float64)

SetAdjustment sets the Asset's cost adjustment

func (*Network) SetLabels

func (n *Network) SetLabels(labels AssetLabels)

SetLabels sets the Asset's labels

func (*Network) SetProperties

func (n *Network) SetProperties(props *AssetProperties)

SetProperties sets the Asset's Properties

func (*Network) SetStartEnd

func (n *Network) SetStartEnd(start, end time.Time)

SetStartEnd sets the Asset's Start and End fields

func (*Network) SetWindow

func (n *Network) SetWindow(window Window)

func (*Network) String

func (n *Network) String() string

String implements fmt.Stringer

func (*Network) TotalCost

func (n *Network) TotalCost() float64

TotalCost returns the Asset's total cost

func (*Network) Type

func (n *Network) Type() AssetType

Type returns the AssetType of the Asset

func (*Network) UnmarshalBinary

func (target *Network) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the Network type

func (*Network) UnmarshalBinaryWithContext

func (target *Network) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the Network type

func (*Network) UnmarshalJSON

func (n *Network) UnmarshalJSON(b []byte) error

type Node

type Node struct {
	Properties   *AssetProperties
	Labels       AssetLabels
	Start        time.Time
	End          time.Time
	Window       Window
	Adjustment   float64
	NodeType     string
	CPUCoreHours float64
	RAMByteHours float64
	GPUHours     float64
	CPUBreakdown *Breakdown
	RAMBreakdown *Breakdown
	CPUCost      float64
	GPUCost      float64
	GPUCount     float64
	RAMCost      float64
	Discount     float64
	Preemptible  float64
	Overhead     *NodeOverhead // @bingen:field[version=19]
}

Node is an Asset representing a single node in a cluster

func NewNode

func NewNode(name, cluster, providerID string, start, end time.Time, window Window) *Node

NewNode creates and returns a new Node Asset

func (*Node) Add

func (n *Node) Add(a Asset) Asset

Add sums the Asset with the given Asset to produce a new Asset, maintaining as much relevant information as possible (i.e. type, Properties, labels).

func (*Node) CPUCores

func (n *Node) CPUCores() float64

CPUCores returns the number of cores belonging to the node. This could be fractional because it's the number of core*hours divided by the number of hours running; e.g. the sum of a 4-core node running for the first 10 hours and a 3-core node running for the last 20 hours of the same 24-hour window would produce:

(4*10 + 3*20) / 24 = 4.167 cores

However, any number of cores running for the full span of a window will report the actual number of cores of the static node; e.g. the above scenario for one entire 24-hour window:

(4*24 + 3*24) / 24 = (4 + 3) = 7 cores

func (*Node) Clone

func (n *Node) Clone() Asset

Clone returns a deep copy of the given Node

func (*Node) Equal

func (n *Node) Equal(a Asset) bool

Equal returns true if the tow Assets match exactly

func (*Node) ExpandWindow

func (n *Node) ExpandWindow(window Window)

ExpandWindow expands the Asset's window by the given window

func (*Node) GPUs

func (n *Node) GPUs() float64

GPUs returns the amount of GPUs belonging to the node. This could be fractional because it's the number of gpu*hours divided by the number of hours running; e.g. the sum of a 2 gpu node running for the first 10 hours and a 1 gpu node running for the last 20 hours of the same 24-hour window would produce:

(2*10 + 1*20) / 24 = 1.667 GPUs

However, any number of GPUs running for the full span of a window will report the actual number of GPUs of the static node; e.g. the above scenario for one entire 24-hour window:

(2*24 + 1*24) / 24 = (2 + 1) = 3 GPUs

func (*Node) GetAdjustment

func (n *Node) GetAdjustment() float64

Adjustment returns the Asset's cost adjustment

func (*Node) GetEnd

func (n *Node) GetEnd() time.Time

End returns the precise end time of the Asset within the window

func (*Node) GetLabels

func (n *Node) GetLabels() AssetLabels

Labels returns the Asset's labels

func (*Node) GetProperties

func (n *Node) GetProperties() *AssetProperties

Properties returns the Asset's Properties

func (*Node) GetStart

func (n *Node) GetStart() time.Time

Start returns the precise start time of the Asset within the window

func (*Node) GetWindow

func (n *Node) GetWindow() Window

Window returns the window within which the Asset ran

func (*Node) InterfaceToNode

func (n *Node) InterfaceToNode(itf interface{}) error

Converts interface{} to Node, carrying over relevant fields

func (*Node) IsPreemptible

func (n *Node) IsPreemptible() bool

IsPreemptible returns true if the node is 100% preemptible. It's possible to be "partially preemptible" by adding a preemptible node with a non-preemptible node.

func (*Node) MarshalBinary

func (target *Node) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this Node instance into a byte array

func (*Node) MarshalBinaryWithContext

func (target *Node) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this Node instance into a byte array leveraging a predefined context.

func (*Node) MarshalJSON

func (n *Node) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshal interface

func (*Node) Minutes

func (n *Node) Minutes() float64

Minutes returns the number of minutes the Asset ran within the window

func (*Node) RAMBytes

func (n *Node) RAMBytes() float64

RAMBytes returns the amount of RAM belonging to the node. This could be fractional because it's the number of byte*hours divided by the number of hours running; e.g. the sum of a 12GiB-RAM node running for the first 10 hours and a 16GiB-RAM node running for the last 20 hours of the same 24-hour window would produce:

(12*10 + 16*20) / 24 = 18.333GiB RAM

However, any number of bytes running for the full span of a window will report the actual number of bytes of the static node; e.g. the above scenario for one entire 24-hour window:

(12*24 + 16*24) / 24 = (12 + 16) = 28GiB RAM

func (*Node) SanitizeNaN

func (n *Node) SanitizeNaN()

func (*Node) SetAdjustment

func (n *Node) SetAdjustment(adj float64)

SetAdjustment sets the Asset's cost adjustment

func (*Node) SetLabels

func (n *Node) SetLabels(labels AssetLabels)

SetLabels sets the Asset's labels

func (*Node) SetProperties

func (n *Node) SetProperties(props *AssetProperties)

SetProperties sets the Asset's Properties

func (*Node) SetStartEnd

func (n *Node) SetStartEnd(start, end time.Time)

SetStartEnd sets the Asset's Start and End fields

func (*Node) SetWindow

func (n *Node) SetWindow(window Window)

func (*Node) String

func (n *Node) String() string

String implements fmt.Stringer

func (*Node) TotalCost

func (n *Node) TotalCost() float64

TotalCost returns the Asset's total cost

func (*Node) Type

func (n *Node) Type() AssetType

Type returns the AssetType of the Asset

func (*Node) UnmarshalBinary

func (target *Node) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the Node type

func (*Node) UnmarshalBinaryWithContext

func (target *Node) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the Node type

func (*Node) UnmarshalJSON

func (n *Node) UnmarshalJSON(b []byte) error

type NodeOverhead

type NodeOverhead struct {
	CpuOverheadFraction  float64
	RamOverheadFraction  float64
	OverheadCostFraction float64
}

NodeOverhead represents the delta between the allocatable resources of the node and the node nameplate capacity

func (*NodeOverhead) MarshalBinary

func (target *NodeOverhead) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this NodeOverhead instance into a byte array

func (*NodeOverhead) MarshalBinaryWithContext

func (target *NodeOverhead) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this NodeOverhead instance into a byte array leveraging a predefined context.

func (*NodeOverhead) SanitizeNaN

func (n *NodeOverhead) SanitizeNaN()

func (*NodeOverhead) UnmarshalBinary

func (target *NodeOverhead) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the NodeOverhead type

func (*NodeOverhead) UnmarshalBinaryWithContext

func (target *NodeOverhead) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the NodeOverhead type

type PVAllocation

type PVAllocation struct {
	ByteHours  float64 `json:"byteHours"`
	Cost       float64 `json:"cost"`
	ProviderID string  `json:"providerID"` // @bingen:field[version=20]
}

PVAllocation contains the byte hour usage and cost of an Allocation for a single PV

func (*PVAllocation) Equal

func (pva *PVAllocation) Equal(that *PVAllocation) bool

Equal returns true if the two PVAllocation instances contain approximately the same values.

func (*PVAllocation) MarshalBinary

func (target *PVAllocation) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this PVAllocation instance into a byte array

func (*PVAllocation) MarshalBinaryWithContext

func (target *PVAllocation) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this PVAllocation instance into a byte array leveraging a predefined context.

func (*PVAllocation) SanitizeNaN

func (pva *PVAllocation) SanitizeNaN()

func (*PVAllocation) UnmarshalBinary

func (target *PVAllocation) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the PVAllocation type

func (*PVAllocation) UnmarshalBinaryWithContext

func (target *PVAllocation) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the PVAllocation type

type PVAllocations

type PVAllocations map[PVKey]*PVAllocation

PVAllocations is a map of Disk Asset Identifiers to the usage of them by an Allocation as recorded in a PVAllocation

func (PVAllocations) Add

Add adds contents of that to the calling PVAllocations

func (PVAllocations) Clone

func (pv PVAllocations) Clone() PVAllocations

Clone creates a deep copy of a PVAllocations

func (PVAllocations) Equal

func (this PVAllocations) Equal(that PVAllocations) bool

Equal returns true if the two PVAllocations are equal in length and contain the same keys and values.

func (PVAllocations) MarshalJSON

func (pv PVAllocations) MarshalJSON() (b []byte, err error)

MarshalJSON marshals PVAllocation as map[*PVKey]*PVAllocation this allows PVKey to retain its values through marshalling

func (PVAllocations) SanitizeNaN

func (pvs PVAllocations) SanitizeNaN()

type PVKey

type PVKey struct {
	Cluster string `json:"cluster"`
	Name    string `json:"name"`
}

PVKey for identifying Disk type assets

func (*PVKey) FromString

func (pvk *PVKey) FromString(key string) error

FromString populates PVKey fields from string

func (*PVKey) MarshalBinary

func (target *PVKey) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this PVKey instance into a byte array

func (*PVKey) MarshalBinaryWithContext

func (target *PVKey) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this PVKey instance into a byte array leveraging a predefined context.

func (PVKey) MarshalText

func (pvk PVKey) MarshalText() (text []byte, err error)

MarshalText converts PVKey to string to make it compatible with JSON Marshaller as an Object key this function is required to have a value caller for the actual values to be saved

func (*PVKey) String

func (pvk *PVKey) String() string

func (*PVKey) UnmarshalBinary

func (target *PVKey) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the PVKey type

func (*PVKey) UnmarshalBinaryWithContext

func (target *PVKey) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the PVKey type

func (*PVKey) UnmarshalText

func (pvk *PVKey) UnmarshalText(text []byte) error

UnmarshalText converts JSON key string to PVKey it compatible with JSON Unmarshaller from an Object key this function is required to have a pointer caller for values to be pulled into marshalling struct

type Pair

type Pair[T any, U any] struct {
	First  T
	Second U
}

Pair is a generic struct containing a pair of instances, one of each type similar to std::pair

func NewPair

func NewPair[T any, U any](first T, second U) Pair[T, U]

Creates a new pair struct containing the provided parameters. This is useful for creating types capable of representing common paired types (result, error), (result, bool), etc...

type ProportionalAssetResourceCost

type ProportionalAssetResourceCost struct {
	Cluster                      string  `json:"cluster"`
	Name                         string  `json:"name,omitempty"`
	Type                         string  `json:"type,omitempty"`
	ProviderID                   string  `json:"providerID,omitempty"`
	CPUPercentage                float64 `json:"cpuPercentage"`
	GPUPercentage                float64 `json:"gpuPercentage"`
	RAMPercentage                float64 `json:"ramPercentage"`
	LoadBalancerPercentage       float64 `json:"loadBalancerPercentage"`
	PVPercentage                 float64 `json:"pvPercentage"`
	NodeResourceCostPercentage   float64 `json:"nodeResourceCostPercentage"`
	GPUTotalCost                 float64 `json:"-"`
	GPUProportionalCost          float64 `json:"-"`
	CPUTotalCost                 float64 `json:"-"`
	CPUProportionalCost          float64 `json:"-"`
	RAMTotalCost                 float64 `json:"-"`
	RAMProportionalCost          float64 `json:"-"`
	LoadBalancerProportionalCost float64 `json:"-"`
	LoadBalancerTotalCost        float64 `json:"-"`
	PVProportionalCost           float64 `json:"-"`
	PVTotalCost                  float64 `json:"-"`
}

func (ProportionalAssetResourceCost) Key

func (parc ProportionalAssetResourceCost) Key(insertByName bool) string

type ProportionalAssetResourceCosts

type ProportionalAssetResourceCosts map[string]ProportionalAssetResourceCost

func (ProportionalAssetResourceCosts) Add

func (ProportionalAssetResourceCosts) Clone

func (ProportionalAssetResourceCosts) Insert

func (parcs ProportionalAssetResourceCosts) Insert(parc ProportionalAssetResourceCost, insertByName bool)

func (ProportionalAssetResourceCosts) SanitizeNaN

func (parcs ProportionalAssetResourceCosts) SanitizeNaN()

type Querier

Querier is an aggregate interface which has the ability to query each Kubecost store type

type RawAllocationOnlyData

type RawAllocationOnlyData struct {
	CPUCoreUsageMax  float64 `json:"cpuCoreUsageMax"`
	RAMBytesUsageMax float64 `json:"ramByteUsageMax"`
}

RawAllocationOnlyData is information that only belong in "raw" Allocations, those which have not undergone aggregation, accumulation, or any other form of combination to produce a new Allocation from other Allocations.

Max usage data belongs here because computing the overall maximum from two or more Allocations is a non-trivial operation that cannot be defined without maintaining a large amount of state. Consider the following example: _______________________________________________

A1 Using 3 CPU ---- ----- ------ A2 Using 2 CPU ---- ----- ---- A3 Using 1 CPU --- -- _______________________________________________

Time ---->

The logical maximum CPU usage is 5, but this cannot be calculated iteratively, which is how we calculate aggregations and accumulations of Allocations currently. This becomes a problem I could call "maximum sum of overlapping intervals" and is essentially a variant of an interval scheduling algorithm.

If we had types to differentiate between regular Allocations and AggregatedAllocations then this type would be unnecessary and its fields would go into the regular Allocation and not in the AggregatedAllocation.

func (*RawAllocationOnlyData) Clone

Clone returns a deep copy of the given RawAllocationOnlyData

func (*RawAllocationOnlyData) Equal

Equal returns true if the RawAllocationOnlyData is approximately equal

func (*RawAllocationOnlyData) MarshalBinary

func (target *RawAllocationOnlyData) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this RawAllocationOnlyData instance into a byte array

func (*RawAllocationOnlyData) MarshalBinaryWithContext

func (target *RawAllocationOnlyData) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this RawAllocationOnlyData instance into a byte array leveraging a predefined context.

func (*RawAllocationOnlyData) SanitizeNaN

func (r *RawAllocationOnlyData) SanitizeNaN()

func (*RawAllocationOnlyData) UnmarshalBinary

func (target *RawAllocationOnlyData) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the RawAllocationOnlyData type

func (*RawAllocationOnlyData) UnmarshalBinaryWithContext

func (target *RawAllocationOnlyData) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the RawAllocationOnlyData type

type ReconciliationStatus

type ReconciliationStatus struct {
	Coverage    Window    `json:"coverage"`
	LastRun     time.Time `json:"lastRun"`
	NextRun     time.Time `json:"nextRun"`
	Progress    float64   `json:"progress"`
	RefreshRate string    `json:"refreshRate"`
	Resolution  string    `json:"resolution"`
	StartTime   time.Time `json:"startTime"`
}

ReconciliationStatus describes Reconciliation metadata of a CloudStore

type SharedAsset

type SharedAsset struct {
	Properties *AssetProperties
	Labels     AssetLabels
	Window     Window
	Cost       float64
}

SharedAsset is an Asset representing a shared cost

func NewSharedAsset

func NewSharedAsset(name string, window Window) *SharedAsset

NewSharedAsset creates and returns a new SharedAsset

func (*SharedAsset) Add

func (sa *SharedAsset) Add(a Asset) Asset

Add sums the Asset with the given Asset to produce a new Asset, maintaining as much relevant information as possible (i.e. type, Properties, labels).

func (*SharedAsset) Clone

func (sa *SharedAsset) Clone() Asset

Clone returns a deep copy of the given SharedAsset

func (*SharedAsset) Equal

func (sa *SharedAsset) Equal(a Asset) bool

Equal returns true if the two Assets are exact matches

func (*SharedAsset) ExpandWindow

func (sa *SharedAsset) ExpandWindow(w Window)

ExpandWindow expands the Asset's window

func (*SharedAsset) GetAdjustment

func (sa *SharedAsset) GetAdjustment() float64

Adjustment is not relevant to SharedAsset, but required to implement Asset

func (*SharedAsset) GetEnd

func (sa *SharedAsset) GetEnd() time.Time

End returns the end time of the Asset

func (*SharedAsset) GetLabels

func (sa *SharedAsset) GetLabels() AssetLabels

Labels returns the Asset's labels

func (*SharedAsset) GetProperties

func (sa *SharedAsset) GetProperties() *AssetProperties

Properties returns the Asset's Properties

func (*SharedAsset) GetStart

func (sa *SharedAsset) GetStart() time.Time

Start returns the start time of the Asset

func (*SharedAsset) GetWindow

func (sa *SharedAsset) GetWindow() Window

Window returns the window within the SharedAsset ran

func (*SharedAsset) InterfaceToSharedAsset

func (sa *SharedAsset) InterfaceToSharedAsset(itf interface{}) error

Converts interface{} to SharedAsset, carrying over relevant fields

func (*SharedAsset) MarshalBinary

func (target *SharedAsset) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this SharedAsset instance into a byte array

func (*SharedAsset) MarshalBinaryWithContext

func (target *SharedAsset) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this SharedAsset instance into a byte array leveraging a predefined context.

func (*SharedAsset) MarshalJSON

func (sa *SharedAsset) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*SharedAsset) Minutes

func (sa *SharedAsset) Minutes() float64

Minutes returns the number of minutes the SharedAsset ran within the window

func (*SharedAsset) SanitizeNaN

func (sa *SharedAsset) SanitizeNaN()

func (*SharedAsset) SetAdjustment

func (sa *SharedAsset) SetAdjustment(float64)

SetAdjustment is not relevant to SharedAsset, but required to implement Asset

func (*SharedAsset) SetLabels

func (sa *SharedAsset) SetLabels(labels AssetLabels)

SetLabels sets the Asset's labels

func (*SharedAsset) SetProperties

func (sa *SharedAsset) SetProperties(props *AssetProperties)

SetProperties sets the Asset's Properties

func (*SharedAsset) SetStartEnd

func (sa *SharedAsset) SetStartEnd(start, end time.Time)

SetStartEnd sets the Asset's Start and End fields (not applicable here)

func (*SharedAsset) SetWindow

func (sa *SharedAsset) SetWindow(window Window)

func (*SharedAsset) String

func (sa *SharedAsset) String() string

String implements fmt.Stringer

func (*SharedAsset) TotalCost

func (sa *SharedAsset) TotalCost() float64

TotalCost returns the Asset's total cost

func (*SharedAsset) Type

func (sa *SharedAsset) Type() AssetType

Type returns the AssetType of the Asset

func (*SharedAsset) UnmarshalBinary

func (target *SharedAsset) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the SharedAsset type

func (*SharedAsset) UnmarshalBinaryWithContext

func (target *SharedAsset) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the SharedAsset type

func (*SharedAsset) UnmarshalJSON

func (sa *SharedAsset) UnmarshalJSON(b []byte) error

type SharedCostBreakdown

type SharedCostBreakdown struct {
	Name         string  `json:"name"`
	TotalCost    float64 `json:"totalCost"`
	CPUCost      float64 `json:"cpuCost,omitempty"`
	GPUCost      float64 `json:"gpuCost,omitempty"`
	RAMCost      float64 `json:"ramCost,omitempty"`
	PVCost       float64 `json:"pvCost,omitempty"`
	NetworkCost  float64 `json:"networkCost,omitempty"`
	LBCost       float64 `json:"loadBalancerCost,omitempty"`
	ExternalCost float64 `json:"externalCost,omitempty"`
}

type SharedCostBreakdowns

type SharedCostBreakdowns map[string]SharedCostBreakdown

func (SharedCostBreakdowns) Add

func (SharedCostBreakdowns) Clone

func (SharedCostBreakdowns) Insert

func (scbs SharedCostBreakdowns) Insert(scb SharedCostBreakdown)

func (SharedCostBreakdowns) SanitizeNaN

func (scbs SharedCostBreakdowns) SanitizeNaN()

type StringTable

type StringTable struct {
	// contains filtered or unexported fields
}

StringTable maps strings to specific indices for encoding

func NewStringTable

func NewStringTable(contents ...string) *StringTable

NewStringTable Creates a new StringTable instance with provided contents

func (*StringTable) AddOrGet

func (st *StringTable) AddOrGet(s string) int

AddOrGet atomically retrieves a string entry's index if it exist. Otherwise, it will add the entry and return the index.

func (*StringTable) ToBytes

func (st *StringTable) ToBytes() []byte

ToBytes Converts the contents to a binary encoded representation

func (*StringTable) ToSlice

func (st *StringTable) ToSlice() []string

ToSlice Converts the contents to a string array for encoding.

type SummaryAllocation

type SummaryAllocation struct {
	Name                   string                `json:"name"`
	Properties             *AllocationProperties `json:"-"`
	Start                  time.Time             `json:"start"`
	End                    time.Time             `json:"end"`
	CPUCoreRequestAverage  float64               `json:"cpuCoreRequestAverage"`
	CPUCoreUsageAverage    float64               `json:"cpuCoreUsageAverage"`
	CPUCost                float64               `json:"cpuCost"`
	GPUCost                float64               `json:"gpuCost"`
	NetworkCost            float64               `json:"networkCost"`
	LoadBalancerCost       float64               `json:"loadBalancerCost"`
	PVCost                 float64               `json:"pvCost"`
	RAMBytesRequestAverage float64               `json:"ramByteRequestAverage"`
	RAMBytesUsageAverage   float64               `json:"ramByteUsageAverage"`
	RAMCost                float64               `json:"ramCost"`
	SharedCost             float64               `json:"sharedCost"`
	ExternalCost           float64               `json:"externalCost"`
	Share                  bool                  `json:"-"`
	UnmountedPVCost        float64               `json:"-"`
}

SummaryAllocation summarizes an Allocation, keeping only fields necessary for providing a high-level view of identifying the Allocation over a period of time (Start, End) over which it ran, and inspecting the associated per- resource costs (subtotaled with adjustments), total cost, and efficiency.

SummaryAllocation does not have a concept of Window (i.e. the time period within which it is defined, as opposed to the Start and End times). That context must be provided by a SummaryAllocationSet.

func NewMockUnitSummaryAllocation

func NewMockUnitSummaryAllocation(name string, start time.Time, resolution time.Duration, props *AllocationProperties) *SummaryAllocation

NewMockUnitSummaryAllocation creates an *SummaryAllocation with all of its float64 values set to 1 and generic properties if not provided in arg

func NewSummaryAllocation

func NewSummaryAllocation(alloc *Allocation, reconcile, reconcileNetwork bool) *SummaryAllocation

NewSummaryAllocation converts an Allocation to a SummaryAllocation by dropping unnecessary fields and consolidating others (e.g. adjustments). Reconciliation happens here because that process is synonymous with the consolidation of adjustment fields.

func (*SummaryAllocation) Add

func (sa *SummaryAllocation) Add(that *SummaryAllocation) error

Add sums two SummaryAllocations, adding the given SummaryAllocation to the receiving one, thus mutating the receiver. For performance reasons, it simply drops Properties, so a SummaryAllocation can only be Added once.

func (*SummaryAllocation) CPUEfficiency

func (sa *SummaryAllocation) CPUEfficiency() float64

CPUEfficiency is the ratio of usage to request. If there is no request and no usage or cost, then efficiency is zero. If there is no request, but there is usage or cost, then efficiency is 100%.

func (*SummaryAllocation) Clone

func (sa *SummaryAllocation) Clone() *SummaryAllocation

Clone copies the SummaryAllocation and returns the copy

func (*SummaryAllocation) Equal

func (sa *SummaryAllocation) Equal(that *SummaryAllocation) bool

func (*SummaryAllocation) IsExternal

func (sa *SummaryAllocation) IsExternal() bool

IsExternal is true if the given SummaryAllocation represents external costs.

func (*SummaryAllocation) IsIdle

func (sa *SummaryAllocation) IsIdle() bool

IsIdle is true if the given SummaryAllocation represents idle costs.

func (*SummaryAllocation) IsUnallocated

func (sa *SummaryAllocation) IsUnallocated() bool

IsUnallocated is true if the given SummaryAllocation represents unallocated costs.

func (*SummaryAllocation) IsUnmounted

func (sa *SummaryAllocation) IsUnmounted() bool

IsUnmounted is true if the given SummaryAllocation represents unmounted volume costs.

func (*SummaryAllocation) Minutes

func (sa *SummaryAllocation) Minutes() float64

Minutes returns the number of minutes the SummaryAllocation represents, as defined by the difference between the end and start times.

func (*SummaryAllocation) RAMEfficiency

func (sa *SummaryAllocation) RAMEfficiency() float64

RAMEfficiency is the ratio of usage to request. If there is no request and no usage or cost, then efficiency is zero. If there is no request, but there is usage or cost, then efficiency is 100%.

func (*SummaryAllocation) ToResponse

func (sa *SummaryAllocation) ToResponse() *SummaryAllocationResponse

ToResponse converts a SummaryAllocation to a SummaryAllocationResponse, protecting against NaN and null values.

func (*SummaryAllocation) TotalCost

func (sa *SummaryAllocation) TotalCost() float64

TotalCost is the total cost of the SummaryAllocation

func (*SummaryAllocation) TotalEfficiency

func (sa *SummaryAllocation) TotalEfficiency() float64

TotalEfficiency is the cost-weighted average of CPU and RAM efficiency. If there is no cost at all, then efficiency is zero.

type SummaryAllocationQuerier

type SummaryAllocationQuerier interface {
	QuerySummaryAllocation(start, end time.Time, opts *AllocationQueryOptions) (*SummaryAllocationSetRange, error)
}

SummaryAllocationQuerier interface defining api for requesting SummaryAllocation data

type SummaryAllocationResponse

type SummaryAllocationResponse struct {
	Name                   string    `json:"name"`
	Start                  time.Time `json:"start"`
	End                    time.Time `json:"end"`
	CPUCoreRequestAverage  *float64  `json:"cpuCoreRequestAverage"`
	CPUCoreUsageAverage    *float64  `json:"cpuCoreUsageAverage"`
	CPUCost                *float64  `json:"cpuCost"`
	GPUCost                *float64  `json:"gpuCost"`
	NetworkCost            *float64  `json:"networkCost"`
	LoadBalancerCost       *float64  `json:"loadBalancerCost"`
	PVCost                 *float64  `json:"pvCost"`
	RAMBytesRequestAverage *float64  `json:"ramByteRequestAverage"`
	RAMBytesUsageAverage   *float64  `json:"ramByteUsageAverage"`
	RAMCost                *float64  `json:"ramCost"`
	SharedCost             *float64  `json:"sharedCost"`
	ExternalCost           *float64  `json:"externalCost"`
	TotalEfficiency        *float64  `json:"totalEfficiency"`
	TotalCost              *float64  `json:"totalCost"`
}

SummaryAllocationResponse is a sanitized version of SummaryAllocation, which formats fields and protects against issues like mashaling NaNs.

type SummaryAllocationSet

type SummaryAllocationSet struct {
	sync.RWMutex

	SummaryAllocations map[string]*SummaryAllocation `json:"allocations"`
	Window             Window                        `json:"window"`
	// contains filtered or unexported fields
}

SummaryAllocationSet stores a set of SummaryAllocations, each with a unique name, that share a window. An AllocationSet is mutable, so treat it like a threadsafe map.

func NewMockUnitSummaryAllocationSet

func NewMockUnitSummaryAllocationSet(start time.Time, resolution time.Duration) *SummaryAllocationSet

NewMockUnitSummaryAllocationSet creates an *SummaryAllocationSet

func NewSummaryAllocationSet

func NewSummaryAllocationSet(as *AllocationSet, filter, keep AllocationMatcher, reconcile, reconcileNetwork bool) *SummaryAllocationSet

NewSummaryAllocationSet converts an AllocationSet to a SummaryAllocationSet. Filter functions, keep functions, and reconciliation parameters are required for unfortunate reasons to do with performance and legacy order-of- operations details, as well as the fact that reconciliation has been pushed down to the conversion step between Allocation and SummaryAllocation.

This filter is an AllocationMatcher, not an AST, because at this point we already have the data and want to make sure that the filter has already gone through a compile step to deal with things like aliases.

func (*SummaryAllocationSet) Add

Add sums two SummaryAllocationSets, which Adds all SummaryAllocations in the given SummaryAllocationSet to their counterparts in the receiving set. Add also expands the Window to include both constituent Windows, in the case that Add is being used from accumulating (as opposed to aggregating). For performance reasons, the function may return either a new set, or an unmodified original, so it should not be assumed that the original sets are safeuly usable after calling Add.

func (*SummaryAllocationSet) AggregateBy

func (sas *SummaryAllocationSet) AggregateBy(aggregateBy []string, options *AllocationAggregationOptions) error

AggregateBy aggregates the Allocations in the given AllocationSet by the given AllocationProperty. This will only be legal if the AllocationSet is divisible by the given AllocationProperty; e.g. Containers can be divided by Namespace, but not vice-a-versa.

func (*SummaryAllocationSet) CPUEfficiency

func (sas *SummaryAllocationSet) CPUEfficiency() float64

CPUEfficiency func to calculate average CPU efficiency over SummaryAllocationSet

func (*SummaryAllocationSet) Clone

Clone creates a deep copy of the SummaryAllocationSet

func (*SummaryAllocationSet) Delete

func (sas *SummaryAllocationSet) Delete(name string)

Delete removes the allocation with the given name from the set

func (*SummaryAllocationSet) Each

func (sas *SummaryAllocationSet) Each(f func(string, *SummaryAllocation))

Each invokes the given function for each SummaryAllocation in the set

func (*SummaryAllocationSet) Equal

func (*SummaryAllocationSet) GetUnmountedPVCost

func (sas *SummaryAllocationSet) GetUnmountedPVCost() float64

func (*SummaryAllocationSet) Insert

func (sas *SummaryAllocationSet) Insert(sa *SummaryAllocation) error

Insert aggregates the current entry in the SummaryAllocationSet by the given Allocation, but only if the Allocation is valid, i.e. matches the SummaryAllocationSet's window. If there is no existing entry, one is created. Nil error response indicates success.

func (*SummaryAllocationSet) RAMEfficiency

func (sas *SummaryAllocationSet) RAMEfficiency() float64

RAMEfficiency func to calculate average RAM efficiency over SummaryAllocationSet

func (*SummaryAllocationSet) ToResponse

ToResponse converts a SummaryAllocationSet to a SummaryAllocationSetResponse, protecting against NaN and null values.

func (*SummaryAllocationSet) TotalCost

func (sas *SummaryAllocationSet) TotalCost() float64

func (*SummaryAllocationSet) TotalEfficiency

func (sas *SummaryAllocationSet) TotalEfficiency() float64

TotalEfficiency func to calculate average Total efficiency over SummaryAllocationSet

type SummaryAllocationSetRange

type SummaryAllocationSetRange struct {
	sync.RWMutex
	Step                  time.Duration           `json:"step"`
	SummaryAllocationSets []*SummaryAllocationSet `json:"sets"`
	Window                Window                  `json:"window"`
	Message               string                  `json:"-"`
}

SummaryAllocationSetRange is a thread-safe slice of SummaryAllocationSets.

func NewSummaryAllocationSetRange

func NewSummaryAllocationSetRange(sass ...*SummaryAllocationSet) *SummaryAllocationSetRange

NewSummaryAllocationSetRange instantiates a new range composed of the given SummaryAllocationSets in the order provided. The expectations about the SummaryAllocationSets are as follows: - window durations are all equal - sets are consecutive (i.e. chronologically sorted) - there are no gaps between sets - sets do not have overlapping windows

func (*SummaryAllocationSetRange) Accumulate

func (*SummaryAllocationSetRange) AggregateBy

func (sasr *SummaryAllocationSetRange) AggregateBy(aggregateBy []string, options *AllocationAggregationOptions) error

AggregateBy aggregates each AllocationSet in the range by the given properties and options.

func (*SummaryAllocationSetRange) Append

Append appends the given AllocationSet to the end of the range. It does not validate whether or not that violates window continuity.

func (*SummaryAllocationSetRange) Clone

func (*SummaryAllocationSetRange) Each

func (sasr *SummaryAllocationSetRange) Each(f func(int, *SummaryAllocationSet))

Each invokes the given function for each AllocationSet in the range

func (*SummaryAllocationSetRange) InsertExternalAllocations

func (sasr *SummaryAllocationSetRange) InsertExternalAllocations(that *AllocationSetRange) error

InsertExternalAllocations takes all allocations in the given AllocationSetRange (they should all be considered "external") and inserts them into the receiving SummaryAllocationSetRange. TODO:CLEANUP replace this with a better idea (or get rid of external allocations, as such, altogether)

func (*SummaryAllocationSetRange) Print

func (sasr *SummaryAllocationSetRange) Print(verbose bool)

TODO remove after testing

func (*SummaryAllocationSetRange) ToResponse

ToResponse converts a SummaryAllocationSet to a SummaryAllocationSetResponse, protecting against NaN and null values.

func (*SummaryAllocationSetRange) TotalCost

func (sasr *SummaryAllocationSetRange) TotalCost() float64

type SummaryAllocationSetRangeResponse

type SummaryAllocationSetRangeResponse struct {
	Step                  time.Duration                   `json:"step"`
	SummaryAllocationSets []*SummaryAllocationSetResponse `json:"sets"`
	Window                Window                          `json:"window"`
}

SummaryAllocationSetRangeResponse is a sanitized version of SummaryAllocationSetRange, which formats fields and protects against issues like marshaling NaNs.

func EmptySummaryAllocationSetRangeResponse

func EmptySummaryAllocationSetRangeResponse() *SummaryAllocationSetRangeResponse

type SummaryAllocationSetResponse

type SummaryAllocationSetResponse struct {
	SummaryAllocations map[string]*SummaryAllocationResponse `json:"allocations"`
	Window             Window                                `json:"window"`
}

SummaryAllocationSetResponse is a sanitized version of SummaryAllocationSet, which formats fields and protects against issues like marshaling NaNs.

type TotalsStore

type TotalsStore interface {
	AllocationTotalsStore
	AssetTotalsStore
}

TotalsStore acts as both an AllocationTotalsStore and an AssetTotalsStore.

type Window

type Window struct {
	// contains filtered or unexported fields
}

Window defines a period of time with a start and an end. If either start or end are nil it indicates an open time period.

func GetWindows

func GetWindows(start time.Time, end time.Time, windowSize time.Duration) ([]Window, error)

GetWindows returns a slice of Window with equal size between the given start and end. If windowSize does not evenly divide the period between start and end, the last window is not added

func GetWindowsForQueryWindow

func GetWindowsForQueryWindow(start time.Time, end time.Time, queryWindow time.Duration) ([]Window, error)

GetWindowsForQueryWindow breaks up a window into an array of windows with a max size of queryWindow

func NewClosedWindow

func NewClosedWindow(start, end time.Time) Window

NewClosedWindow creates and returns a new Window instance from the given times, which cannot be nil, so they are value types.

func NewWindow

func NewWindow(start, end *time.Time) Window

NewWindow creates and returns a new Window instance from the given times

func ParseWindowUTC

func ParseWindowUTC(window string) (Window, error)

ParseWindowUTC attempts to parse the given string into a valid Window. It accepts several formats, returning an error if the given string does not match one of the following: - named intervals: "today", "yesterday", "week", "month", "lastweek", "lastmonth" - durations: "24h", "7d", etc. - date ranges: "2020-04-01T00:00:00Z,2020-04-03T00:00:00Z", etc. - timestamp ranges: "1586822400,1586908800", etc.

func ParseWindowWithOffset

func ParseWindowWithOffset(window string, offset time.Duration) (Window, error)

ParseWindowWithOffset parses the given window string within the context of the timezone defined by the UTC offset.

func ParseWindowWithOffsetString

func ParseWindowWithOffsetString(window string, offset string) (Window, error)

ParseWindowWithOffsetString parses the given window string within the context of the timezone defined by the UTC offset string of format -07:00, +01:30, etc.

func (Window) ApproximatelyEqual

func (w Window) ApproximatelyEqual(that Window, threshold time.Duration) bool

ApproximatelyEqual returns true if the start and end times of the two windows, respectively, are within the given threshold of each other.

func (Window) Clone

func (w Window) Clone() Window

func (Window) Contains

func (w Window) Contains(t time.Time) bool

func (Window) ContainsWindow

func (w Window) ContainsWindow(that Window) bool

func (Window) Contract

func (w Window) Contract(that Window) Window

func (Window) ContractEnd

func (w Window) ContractEnd(end time.Time) Window

func (Window) ContractStart

func (w Window) ContractStart(start time.Time) Window

func (Window) Duration

func (w Window) Duration() time.Duration

func (Window) DurationOffset

func (w Window) DurationOffset() (time.Duration, time.Duration, error)

DurationOffset returns durations representing the duration and offset of the given window

func (Window) DurationOffsetForPrometheus

func (w Window) DurationOffsetForPrometheus() (string, string, error)

DurationOffsetForPrometheus returns strings representing durations for the duration and offset of the given window, factoring in the Thanos offset if necessary. Whereas duration is a simple duration string (e.g. "1d"), the offset includes the word "offset" (e.g. " offset 2d") so that the values returned can be used directly in the formatting string "some_metric[%s]%s" to generate the query "some_metric[1d] offset 2d".

func (Window) DurationOffsetStrings

func (w Window) DurationOffsetStrings() (string, string)

DurationOffsetStrings returns formatted, Prometheus-compatible strings representing the duration and offset of the window in terms of days, hours, minutes, or seconds; e.g. ("7d", "1441m", "30m", "1s", "")

func (Window) End

func (w Window) End() *time.Time

func (Window) Equal

func (w Window) Equal(that Window) bool

func (Window) Expand

func (w Window) Expand(that Window) Window

func (Window) ExpandEnd

func (w Window) ExpandEnd(end time.Time) Window

func (Window) ExpandStart

func (w Window) ExpandStart(start time.Time) Window

func (Window) GetPercentInWindow

func (w Window) GetPercentInWindow(that Window) float64

GetPercentInWindow Determine pct of item time contained the window. determined by the overlap of the start/end with the given window, which will be negative if there is no overlap. If there is positive overlap, compare it with the total mins.

e.g. here are the two possible scenarios as simplidied 10m windows with dashes representing item's time running:

  1. item falls entirely within one CloudCostSet window | ---- | | | totalMins = 4.0 pct := 4.0 / 4.0 = 1.0 for window 1 pct := 0.0 / 4.0 = 0.0 for window 2 pct := 0.0 / 4.0 = 0.0 for window 3

  2. item overlaps multiple CloudCostSet windows | ----|----------|-- | totalMins = 16.0 pct := 4.0 / 16.0 = 0.250 for window 1 pct := 10.0 / 16.0 = 0.625 for window 2 pct := 2.0 / 16.0 = 0.125 for window 3

func (Window) HasDuration

func (w Window) HasDuration() bool

HasDuration a Window has duration if neither start and end are not nil and not equal

func (Window) Hours

func (w Window) Hours() float64

func (Window) IsEmpty

func (w Window) IsEmpty() bool

IsEmpty a Window is empty if it does not have a start and an end

func (Window) IsNegative

func (w Window) IsNegative() bool

IsNegative a Window is negative if start and end are not null and end is before start

func (Window) IsOpen

func (w Window) IsOpen() bool

IsOpen a Window is open if it has a nil start or end

func (*Window) MarshalBinary

func (target *Window) MarshalBinary() (data []byte, err error)

MarshalBinary serializes the internal properties of this Window instance into a byte array

func (*Window) MarshalBinaryWithContext

func (target *Window) MarshalBinaryWithContext(ctx *EncodingContext) (err error)

MarshalBinaryWithContext serializes the internal properties of this Window instance into a byte array leveraging a predefined context.

func (Window) MarshalJSON

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

func (Window) Minutes

func (w Window) Minutes() float64

func (*Window) Set

func (w *Window) Set(start, end *time.Time)

func (Window) Shift

func (w Window) Shift(dur time.Duration) Window

Shift adds the given duration to both the start and end times of the window

func (Window) Start

func (w Window) Start() *time.Time

func (Window) String

func (w Window) String() string

func (*Window) UnmarshalBinary

func (target *Window) UnmarshalBinary(data []byte) error

UnmarshalBinary uses the data passed byte array to set all the internal properties of the Window type

func (*Window) UnmarshalBinaryWithContext

func (target *Window) UnmarshalBinaryWithContext(ctx *DecodingContext) (err error)

UnmarshalBinaryWithContext uses the context containing a string table and binary buffer to set all the internal properties of the Window type

func (*Window) UnmarshalJSON

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

Jump to

Keyboard shortcuts

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