opencost

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 17 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"
)
View Source
const (
	// GeneratorPackageName is the package the generator is targetting
	GeneratorPackageName string = "opencost"

	// 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"

	// DefaultCodecVersion is used for any resources listed in the Default version set
	DefaultCodecVersion uint8 = 16

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

	// AllocationCodecVersion is used for any resources listed in the Allocation version set
	AllocationCodecVersion uint8 = 16
)
View Source
const AWSProvider = "AWS"

AWSProvider describes the provider AWS

View Source
const AzureProvider = "Azure"

AzureProvider describes the provider Azure

View Source
const ComputeCategory = "Compute"

ComputeCategory signifies the Compute Category

View Source
const ExternalSuffix = "__external__"

ExternalSuffix indicates an external allocation

View Source
const GCPProvider = "GCP"

GCPProvider describes the provider GCP

View Source
const IdleSuffix = "__idle__"

IdleSuffix indicates an idle allocation property

View Source
const KubernetesService = "Kubernetes"
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 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 UnmountedSuffix = "__unmounted__"

UnmountedSuffix indicated allocation to an unmounted PV

Variables

This section is empty.

Functions

func BingenFileBackedStringTableDir

func BingenFileBackedStringTableDir() string

BingenFileBackedStringTableDir returns the directory configured for file backed string tables.

func ConfigureBingen

func ConfigureBingen(config *BingenConfiguration)

ConfigureBingen accepts a new *BingenConfiguration instance which updates the internal decoder and encoder behavior.

func DurationOffsetStrings

func DurationOffsetStrings(_ time.Duration, _ time.Duration) (string, string)

func IsBingenFileBackedStringTableEnabled

func IsBingenFileBackedStringTableEnabled() bool

IsBingenFileBackedStringTableEnabled accessor for file backed string table configuration

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 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 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"`
	NetworkCostAdjustment      float64               `json:"networkCostAdjustment"`
	LoadBalancerCost           float64               `json:"loadBalancerCost"`
	LoadBalancerCostAdjustment float64               `json:"loadBalancerCostAdjustment"`
	PVs                        PVAllocations         `json:"-"`
	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"`

	TestProperty int    `json:"testProperty"` //@bingen:field[version=16, default=0]
	TestStr      string `json:"testStr"`      //@bingen:field[version=16, default=test]
}

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, externalLabelsCfg map[string]string) (*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 TOOD.

  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 (*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) 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) 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) LBTotalCost

func (a *Allocation) LBTotalCost() float64

LBTotalCost 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) 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) 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) 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) UnmarshalBinaryFromReader

func (target *Allocation) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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

type AllocationAggregationOptions

type AllocationAggregationOptions struct {
	FilterFuncs       []AllocationMatchFunc
	SplitIdle         bool
	IdleByNode        bool
	MergeUnallocated  bool
	ShareFuncs        []AllocationMatchFunc
	ShareIdle         string
	ShareSplit        string
	SharedHourlyCosts map[string]float64
}

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 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 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:"allocationLabels,omitempty"`
	Annotations    AllocationAnnotations `json:"allocationAnnotations,omitempty"`
}

AllocationProperties describes a set of Kubernetes objects.

func (*AllocationProperties) Clone

func (*AllocationProperties) Equal

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) UnmarshalBinaryFromReader

func (target *AllocationProperties) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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 AllocationSet

type AllocationSet struct {
	sync.RWMutex

	FromSource string // stores the name of the source used to compute the data
	Window     Window
	Warnings   []string
	Errors     []string
	// contains filtered or unexported fields
}

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 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) 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) ComputeIdleAllocations

func (as *AllocationSet) ComputeIdleAllocations(assetSet *AssetSet) (map[string]*Allocation, error)

ComputeIdleAllocations computes the idle allocations for the AllocationSet, given a set of Assets. Ideally, assetSet should contain only Nodes, but if it contains other Assets, they will be ignored; only CPU, GPU and RAM are considered for idle allocation. If the Nodes have adjustments, then apply the adjustments proportionally to each of the resources so that total allocation with idle reflects the adjusted node costs. One idle allocation per-cluster will be computed and returned, keyed by cluster_id.

func (*AllocationSet) ComputeIdleAllocationsByNode

func (as *AllocationSet) ComputeIdleAllocationsByNode(assetSet *AssetSet) (map[string]*Allocation, error)

ComputeIdleAllocationsByNode computes the idle allocations for the AllocationSet, given a set of Assets. Ideally, assetSet should contain only Nodes, but if it contains other Assets, they will be ignored; only CPU, GPU and RAM are considered for idle allocation. If the Nodes have adjustments, then apply the adjustments proportionally to each of the resources so that total allocation with idle reflects the adjusted node costs. One idle allocation per-node will be computed and returned, keyed by cluster_id.

func (*AllocationSet) Delete

func (as *AllocationSet) Delete(name string)

Delete removes the allocation with the given name from the set

func (*AllocationSet) Each

func (as *AllocationSet) Each(f func(string, *Allocation))

Each invokes the given function for each Allocation in 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) 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) Map

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

Map clones and returns a map of the AllocationSet's Allocations

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) Resolution

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

Resolution returns the AllocationSet's window duration

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) 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) UnmarshalBinaryFromReader

func (target *AllocationSet) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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 {
	sync.RWMutex

	FromStore string // stores the name of the store used to retrieve the data
	// contains filtered or unexported fields
}

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() (*AllocationSet, error)

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

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) Each

func (asr *AllocationSetRange) Each(f func(int, *AllocationSet))

Each invokes the given function for each AllocationSet in the range

func (*AllocationSetRange) Get

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

Get 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) Slice

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

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

func (*AllocationSetRange) String

func (asr *AllocationSetRange) String() string

String represents the given AllocationSetRange as a string

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) UnmarshalBinaryFromReader

func (target *AllocationSetRange) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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 AllocationSetStream

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

AllocationSetStream is a single use field stream for the contents of an AllocationSet instance. Instead of creating an instance and populating the fields on that instance, we provide a streaming iterator which yields (BingenFieldInfo, *BingenValue) tuples for each streamable element. All slices and maps will be flattened one depth and each element streamed individually.

func (*AllocationSetStream) Close

func (stream *AllocationSetStream) Close()

Closes closes the internal io.Reader used to read and parse the AllocationSet fields. This should be called once the stream is no longer needed.

func (*AllocationSetStream) Error

func (stream *AllocationSetStream) Error() error

Error returns an error if one occurred during the process of streaming the AllocationSet This can be checked after iterating through the Stream().

func (*AllocationSetStream) Stream

Stream returns the iterator which will stream each field of the target type.

type Any

type Any struct {
	Cost float64
	// contains filtered or unexported fields
}

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) Adjustment

func (a *Any) Adjustment() float64

Adjustment returns the Asset's cost adjustment

func (*Any) Clone

func (a *Any) Clone() Asset

Clone returns a cloned instance of the Asset

func (*Any) End

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

End returns the Asset's end time within the window

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) Labels

func (a *Any) Labels() AssetLabels

Labels returns the Asset's labels

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) Properties

func (a *Any) Properties() *AssetProperties

Properties returns the Asset's properties

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) Start

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

Start returns the Asset's start time within the 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) UnmarshalBinaryFromReader

func (target *Any) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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) Window

func (a *Any) Window() Window

Window returns the Asset's window

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

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

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

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

	// Temporal values
	Start() time.Time
	End() time.Time
	SetStartEnd(time.Time, time.Time)
	Window() Window
	ExpandWindow(Window)
	Minutes() float64

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

	// 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 AssetAggregationOptions

type AssetAggregationOptions struct {
	SharedHourlyCosts map[string]float64
	FilterFuncs       []AssetMatchFunc
}

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) 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 AssetMatchFunc

type AssetMatchFunc func(Asset) bool

AssetMatchFunc is a function that can be used to match Assets by returning true for any given Asset if a condition is met.

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) UnmarshalBinaryFromReader

func (target *AssetProperties) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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"

	// 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"
)

func ParseAssetProperty

func ParseAssetProperty(text string) (AssetProperty, error)

ParseAssetProperty attempts to parse a string into an AssetProperty

type AssetSet

type AssetSet struct {
	sync.RWMutex

	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
	// contains filtered or unexported fields
}

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 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) Each

func (as *AssetSet) Each(f func(string, Asset))

Each invokes the given function for each Asset in the set

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) (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) Insert

func (as *AssetSet) Insert(asset Asset) 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) Map

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

Map clones and returns a map of the AssetSet's Assets

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) Set

func (as *AssetSet) Set(asset Asset, aggregateBy []string) 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) UnmarshalBinaryFromReader

func (target *AssetSet) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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 {
	sync.RWMutex

	FromStore string // stores the name of the store used to retrieve the data
	// contains filtered or unexported fields
}

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() (*AssetSet, error)

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

func (*AssetSetRange) AggregateBy

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

func (*AssetSetRange) Append

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

func (*AssetSetRange) Each

func (asr *AssetSetRange) Each(f func(int, *AssetSet))

Each invokes the given function for each AssetSet in the range

func (*AssetSetRange) Get

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

func (*AssetSetRange) Length

func (asr *AssetSetRange) Length() int

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) 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) UnmarshalBinaryFromReader

func (target *AssetSetRange) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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 AssetSetStream

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

AssetSetStream is a single use field stream for the contents of an AssetSet instance. Instead of creating an instance and populating the fields on that instance, we provide a streaming iterator which yields (BingenFieldInfo, *BingenValue) tuples for each streamable element. All slices and maps will be flattened one depth and each element streamed individually.

func (*AssetSetStream) Close

func (stream *AssetSetStream) Close()

Closes closes the internal io.Reader used to read and parse the AssetSet fields. This should be called once the stream is no longer needed.

func (*AssetSetStream) Error

func (stream *AssetSetStream) Error() error

Error returns an error if one occurred during the process of streaming the AssetSet This can be checked after iterating through the Stream().

func (*AssetSetStream) Stream

func (stream *AssetSetStream) Stream() iter.Seq2[BingenFieldInfo, *BingenValue]

Stream returns the iterator which will stream each field of the target type.

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 BingenConfiguration

type BingenConfiguration struct {
	// FileBackedStringTableEnabled enables the use of file-backed string tables for streaming
	// bingen decoding.
	FileBackedStringTableEnabled bool

	// FileBackedStringTableDir is the directory to write the string table files for reading.
	FileBackedStringTableDir string
}

BingenConfiguration is used to set any custom configuration in the way files are encoded or decoded.

func DefaultBingenConfiguration

func DefaultBingenConfiguration() *BingenConfiguration

DefaultBingenConfiguration creates the default implementation of the bingen configuration and returns it.

type BingenFieldInfo

type BingenFieldInfo struct {
	Type reflect.Type
	Name string
}

BingenFieldInfo contains the type of the field being streamed as well as the name of the field.

type BingenStream

type BingenStream interface {
	// Stream returns the iterator which will stream each field of the target type and
	// return the field info as well as the value.
	Stream() iter.Seq2[BingenFieldInfo, *BingenValue]

	// Close will close any dynamic io.Reader used to stream in the fields
	Close()

	// Error returns an error if one occurred during the process of streaming the type's fields.
	// This can be checked after iterating through the Stream().
	Error() error
}

BingenStream is the stream interface for all streamable types

func NewAllocationSetStream

func NewAllocationSetStream(reader io.Reader) BingenStream

NewAllocationSetStream creates a new AllocationSetStream, which uses the io.Reader data to stream all internal fields of an AllocationSet instance

func NewAssetSetStream

func NewAssetSetStream(reader io.Reader) BingenStream

NewAssetSetStream creates a new AssetSetStream, which uses the io.Reader data to stream all internal fields of an AssetSet instance

func NewStreamFor

func NewStreamFor[T any](reader io.Reader) (BingenStream, error)

NewStreamFor accepts an io.Reader, and returns a new BingenStream for the generic T type provided _if_ it is a registered bingen type that is annotated as 'streamable'. See the streamFactoryMap for generated type listings.

type BingenValue

type BingenValue struct {
	Value any
	Index any
}

BingenValue contains the value of a field as well as any index/key associated with that value.

func (*BingenValue) IsNil

func (bv *BingenValue) IsNil() bool

IsNil is just a method accessor way to check to see if the value returned was nil

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

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) 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) UnmarshalBinaryFromReader

func (target *Breakdown) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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 {
	Cost   float64
	Credit float64 // Credit is a negative value representing dollars credited back to a given line-item
	// contains filtered or unexported fields
}

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) Adjustment

func (ca *Cloud) Adjustment() float64

Adjustment returns the Asset's adjustment value

func (*Cloud) Clone

func (ca *Cloud) Clone() Asset

Clone returns a cloned instance of the Asset

func (*Cloud) End

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

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

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) Labels

func (ca *Cloud) Labels() AssetLabels

Labels returns the AssetLabels

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) Properties

func (ca *Cloud) Properties() *AssetProperties

Properties returns the AssetProperties

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) Start

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

Start returns the Asset's precise start time within the 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) UnmarshalBinaryFromReader

func (target *Cloud) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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) Window

func (ca *Cloud) Window() Window

Window returns the window within which the Asset ran

type ClusterManagement

type ClusterManagement struct {
	Cost float64
	// contains filtered or unexported fields
}

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) Adjustment

func (cm *ClusterManagement) Adjustment() float64

Adjustment does not apply to ClusterManagement

func (*ClusterManagement) Clone

func (cm *ClusterManagement) Clone() Asset

Clone returns a cloned instance of the Asset

func (*ClusterManagement) End

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

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

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) Labels

func (cm *ClusterManagement) Labels() AssetLabels

Labels returns the Asset's labels

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) Properties

func (cm *ClusterManagement) Properties() *AssetProperties

Properties returns the Asset's properties

func (*ClusterManagement) SetAdjustment

func (cm *ClusterManagement) SetAdjustment(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) Start

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

Start returns the Asset's precise start time within the 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) UnmarshalBinaryFromReader

func (target *ClusterManagement) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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) Window

func (cm *ClusterManagement) Window() Window

Window return the Asset's window

type DecodingContext

type DecodingContext struct {
	Buffer *util.Buffer
	Table  StringTableReader
}

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

func NewDecodingContextFromBytes

func NewDecodingContextFromBytes(data []byte) *DecodingContext

NewDecodingContextFromBytes creates a new DecodingContext instance using an byte slice

func NewDecodingContextFromReader

func NewDecodingContextFromReader(reader io.Reader) *DecodingContext

NewDecodingContextFromReader creates a new DecodingContext instance using an io.Reader implementation

func (*DecodingContext) Close

func (dc *DecodingContext) Close()

Close will ensure that any string table resources and buffer resources are cleaned up.

func (*DecodingContext) IsStringTable

func (dc *DecodingContext) IsStringTable() bool

IsStringTable returns true if the table is available

type Disk

type Disk struct {
	Cost      float64
	ByteHours float64
	Local     float64
	Breakdown *Breakdown
	// contains filtered or unexported fields
}

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) Adjustment

func (d *Disk) Adjustment() float64

Adjustment returns the Asset's cost adjustment

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) End

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

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

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) Labels

func (d *Disk) Labels() AssetLabels

Labels returns the Asset's labels

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) Properties

func (d *Disk) Properties() *AssetProperties

Properties returns the Asset's properties

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) Start

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

Start returns the precise start time of the Asset within the 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) UnmarshalBinaryFromReader

func (target *Disk) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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) Window

func (d *Disk) Window() Window

Window returns the window within which the Asset

type EncodingContext

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

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 FileStringTableReader

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

FileStringTableReader leverages a local file to write string table data for lookup. On memory focused systems, this allows a slower parse with a significant decrease in memory usage. This implementation is often pair with streaming readers for high throughput with reduced memory usage.

func (*FileStringTableReader) At

func (fstr *FileStringTableReader) At(index int) string

At returns the string from the internal file using the reference's offset and length.

func (*FileStringTableReader) Close

func (fstr *FileStringTableReader) Close() error

Close for the file string table reader closes the file and deletes it.

func (*FileStringTableReader) Len

func (fstr *FileStringTableReader) Len() int

Len returns the total number of strings loaded in the string table.

type LoadBalancer

type LoadBalancer struct {
	Cost float64
	// contains filtered or unexported fields
}

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) *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) Adjustment

func (lb *LoadBalancer) Adjustment() float64

Adjustment returns the Asset's cost adjustment

func (*LoadBalancer) Clone

func (lb *LoadBalancer) Clone() Asset

Clone returns a cloned instance of the given Asset

func (*LoadBalancer) End

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

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

func (*LoadBalancer) Equal

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

Equal returns true if the tow Assets match precisely

func (*LoadBalancer) ExpandWindow

func (lb *LoadBalancer) ExpandWindow(w Window)

ExpandWindow expands the Asset's window by the given window

func (*LoadBalancer) Labels

func (lb *LoadBalancer) Labels() AssetLabels

Labels returns the Asset's labels

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) Properties

func (lb *LoadBalancer) Properties() *AssetProperties

Properties returns the Asset's properties

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) Start

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

Start returns the preceise start point of the Asset within the 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) UnmarshalBinaryFromReader

func (target *LoadBalancer) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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) Window

func (lb *LoadBalancer) Window() Window

Window returns the window within which the Asset ran

type Network

type Network struct {
	Cost float64
	// contains filtered or unexported fields
}

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) Adjustment

func (n *Network) Adjustment() float64

Adjustment returns the Asset's cost adjustment

func (*Network) Clone

func (n *Network) Clone() Asset

Clone returns a deep copy of the given Network

func (*Network) End

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

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

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) Labels

func (n *Network) Labels() AssetLabels

Labels returns the Asset's labels

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) Properties

func (n *Network) Properties() *AssetProperties

Properties returns the Asset's properties

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) Start

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

Start returns the precise start time of the Asset within the 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) UnmarshalBinaryFromReader

func (target *Network) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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) Window

func (n *Network) Window() Window

Window returns the window within which the Asset ran

type Node

type Node struct {
	NodeType     string
	CPUCoreHours float64
	RAMByteHours float64
	GPUHours     float64
	CPUBreakdown *Breakdown
	RAMBreakdown *Breakdown
	CPUCost      float64
	GPUCost      float64
	GPUCount     float64
	RAMCost      float64
	Discount     float64
	Preemptible  float64
	// contains filtered or unexported fields
}

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) Adjustment

func (n *Node) Adjustment() float64

Adjustment returns the Asset's cost adjustment

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) End

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

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

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) 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) Labels

func (n *Node) Labels() AssetLabels

Labels returns the Asset's labels

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) Properties

func (n *Node) Properties() *AssetProperties

Properties returns the Asset's properties

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) 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) Start

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

Start returns the precise start time of the Asset within the 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) UnmarshalBinaryFromReader

func (target *Node) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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) Window

func (n *Node) Window() Window

Window returns the window within which the Asset ran

type PVAllocation

type PVAllocation struct {
	ByteHours float64 `json:"byteHours"`
	Cost      float64 `json:"cost"`
}

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

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) 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) UnmarshalBinaryFromReader

func (target *PVAllocation) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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

type PVKey

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

PVKey for identifying Disk type assets

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) 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) UnmarshalBinaryFromReader

func (target *PVKey) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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

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) 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) 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) UnmarshalBinaryFromReader

func (target *RawAllocationOnlyData) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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 SharedAsset

type SharedAsset struct {
	Cost float64
	// contains filtered or unexported fields
}

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) Adjustment

func (sa *SharedAsset) Adjustment() float64

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

func (*SharedAsset) Clone

func (sa *SharedAsset) Clone() Asset

Clone returns a deep copy of the given SharedAsset

func (*SharedAsset) End

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

End returns the end time of the Asset

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) Labels

func (sa *SharedAsset) Labels() AssetLabels

Labels returns the Asset's labels

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) Properties

func (sa *SharedAsset) Properties() *AssetProperties

Properties returns the Asset's properties

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) Start

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

Start returns the start time of the Asset

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) UnmarshalBinaryFromReader

func (target *SharedAsset) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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) Window

func (sa *SharedAsset) Window() Window

Window returns the window within the SharedAsset ran

type SliceStringTableReader

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

SliceStringTableReader is a basic pre-loaded []string that provides index-based access. The cost of this implementation is holding all strings in memory, which provides faster lookup performance at the expense of memory usage.

func (*SliceStringTableReader) At

func (sstr *SliceStringTableReader) At(index int) string

At returns the string entry at a specific index, or panics on out of bounds.

func (*SliceStringTableReader) Close

func (sstr *SliceStringTableReader) Close() error

Close for the slice tables just nils out the slice and returns

func (*SliceStringTableReader) Len

func (sstr *SliceStringTableReader) Len() int

Len returns the total number of strings loaded in the string table.

type StreamFactoryFunc

type StreamFactoryFunc func(io.Reader) BingenStream

StreamFactoryFunc is an alias for a func that creates a BingenStream implementation.

type StringTableReader

type StringTableReader interface {
	// At returns the string entry at a specific index, or panics on out of bounds.
	At(index int) string

	// Len returns the total number of strings loaded in the string table.
	Len() int

	// Close will clear the loaded table, and drop any external resources used.
	Close() error
}

StringTableReader is the interface used to read the string table from the decoding.

func NewFileStringTableReaderFrom

func NewFileStringTableReaderFrom(buffer *util.Buffer, dir string) StringTableReader

NewFileStringTableFromBuffer reads exactly tl length-prefixed (uint16) string payloads from buffer and appends each payload to a new temp file. It does not retain full strings in memory.

func NewSliceStringTableReaderFrom

func NewSliceStringTableReaderFrom(buffer *util.Buffer) StringTableReader

NewSliceStringTableReaderFrom creates a new SliceStringTableReader instance loading data directly from the buffer. The buffer's position should start at the table length.

type StringTableWriter

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

StringTableWriter maps strings to specific indices for encoding

func NewStringTableWriter

func NewStringTableWriter(contents ...string) *StringTableWriter

NewStringTableWriter Creates a new StringTableWriter instance with provided contents

func (*StringTableWriter) AddOrGet

func (st *StringTableWriter) 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 (*StringTableWriter) ToBytes

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

ToBytes Converts the contents to a binary encoded representation

func (*StringTableWriter) ToSlice

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

ToSlice Converts the contents to a string array for encoding.

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 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) 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) Hours

func (w Window) Hours() float64

func (Window) IsEmpty

func (w Window) IsEmpty() bool

func (Window) IsNegative

func (w Window) IsNegative() bool

func (Window) IsOpen

func (w Window) IsOpen() bool

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)

TODO:CLEANUP make this unmarshalable (make Start and End public)

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) UnmarshalBinaryFromReader

func (target *Window) UnmarshalBinaryFromReader(reader io.Reader) error

UnmarshalBinaryFromReader uses the io.Reader data 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

Jump to

Keyboard shortcuts

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