metering

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AggregateByTimeStep     = "timeStep"
	GroupByConsumptionQuery = "consumptionQuery"
)

Variables

This section is empty.

Functions

func ValidateQueryRequest

func ValidateQueryRequest(request *QueryRequest) error

Types

type AggregationType

type AggregationType string

type BaseConsumptionTags

type BaseConsumptionTags struct {
	Feature      string `json:"feature"`            //VolumeSets, Workloads, Ingress, SpiceDb, etc.
	Metric       string `json:"metric"`             //Required. CPU, Memory, Egress, StorageCapacity, etc.
	Org          string `json:"org"`                //Required. Everything lives in an org
	Gvc          string `json:"gvc,omitempty"`      //Optional. Not all resources are gvc-scoped
	Name         string `json:"name"`               //Required. All metered entities have a name.
	Location     string `json:"location,omitempty"` //Optional. It's possible that some objects will be global
	LocationType string `json:"locationType"`
}

type Bucket

type Bucket struct {
	Id               int64     `json:"id"`
	PartitionsEnding time.Time `json:"partitionsEnding" gorm:"type:timestamptz"`
	Created          time.Time `json:"created" gorm:"type:timestamptz;default:now()"`
	Orgs             []*Org    `json:"orgs,omitempty"`
}

func (*Bucket) CheckpointName

func (b *Bucket) CheckpointName() string

func (*Bucket) SchemaName

func (b *Bucket) SchemaName() string

type ChargeDetail

type ChargeDetail struct {
	Charge           math.Float64 `json:"amount"`
	Units            math.Float64 `json:"units"`
	Rate             math.Float64 `json:"rate"`
	RatePlanItem     string       `json:"ratePlanItem"`
	ChargeableItemId string       `json:"chargeableItemId"`
	From             math.Float64 `json:"from"`
	To               math.Float64 `json:"to"`
}

func (ChargeDetail) Add

func (c ChargeDetail) Add(other ChargeDetail) ChargeDetail

type Charges

type Charges struct {
	Charge   math.Float64   `json:"total"`
	Currency string         `json:"currency,omitempty"`
	RatePlan []string       `json:"ratePlans"`
	Details  []ChargeDetail `json:"details,omitempty" gorm:"type:jsonb"`
	// contains filtered or unexported fields
}

func (*Charges) Add

func (c *Charges) Add(other *Charges) *Charges

func (*Charges) ExtractDetailsFromMap

func (c *Charges) ExtractDetailsFromMap()

type Client

type Client interface {
	SetProfiling(enabled bool)
	QueryTagValues(token string, org string, query *TagValuesQueryRequest) (*TagValuesQueryResult, error)
	QueryByOrg(token string, org string, query *QueryRequest) (*QueryResult, error)
	Query(token string, query *QueryRequest) (*QueryResult, error)

	/*
	  DecomposeAndQueryByOrg and DecomposeAndQuery ensure that the given query is executed (at least) once for each
	  subSegment. If the subSegments are not aligned with query.TimeStep, the query will be decomposed into smaller
	  TimeSteps, given by decomposeInto.

	  Decomposition will fail if the query.TimeSegment is not aligned with the
	  smallest value in decomposeInto. e.g. if you give a query with a TimeSegment of
	  2023-01-01T00:01:01 - 2023-01-02T00:00:00, decomposition will fail because the start time is not aligned with the
	  smallest possible TimeStep (TimeStepHour)
	*/
	DecomposeAndQueryByOrg(token string, org string, query *QueryRequest, boundaryTimes []time.Time, decomposeInto []timeUtils.TimeStep) ([]*QueryResult, error)
	DecomposeAndQuery(token string, query *QueryRequest, boundaryTimes []time.Time, decomposeInto []timeUtils.TimeStep) ([]*QueryResult, error)
	GroupQueryResults(results []*QueryResult, aggregationPeriod timeUtils.TimeSegment, timeStep timeUtils.TimeStep, aggregateByTimeStep bool) (*QueryResult, error)

	AdminListCheckpoints(token string) (*checkpoints.ListCheckpointsResult, error)
	AdminResetCheckpoints(token string, request *checkpoints.ResetCheckpointsRequest) error
	AdminQueryCheckpoints(token string, request *checkpoints.QueryCheckpointsRequest) (*checkpoints.QueryCheckpointsResult, error)

	GetBucket(token string, request *GetBucketRequest) (*Bucket, error)
	ListBuckets(token string) ([]*Bucket, error)
}

func NewClient

func NewClient(url string) Client

type Consumption

type Consumption struct {
	*Charges        `gorm:"-"`
	ProjectedCharge math.Float64 `json:"projectedTotal,omitempty" gorm:"-"`
	Value           math.Float64 `json:"value"`
	ProjectedValue  math.Float64 `json:"projectedValue,omitempty" gorm:"-"`
	Job             string       `json:"job,omitempty"`
	Tags            any          `json:"tags" gorm:"type:jsonb"`
	// contains filtered or unexported fields
}

func (*Consumption) Add

func (c *Consumption) Add(other *Consumption) (*Consumption, error)

func (*Consumption) FingerprintTags

func (c *Consumption) FingerprintTags() string

func (*Consumption) GetQueryIndex

func (c *Consumption) GetQueryIndex() int

func (*Consumption) SetQueryIndex

func (c *Consumption) SetQueryIndex(i int)

type ConsumptionGroup

type ConsumptionGroup struct {
	Key          map[string]any `json:"key"`
	Consumptions []*Consumption `json:"consumptions"`
}

type ConsumptionPeriod

type ConsumptionPeriod struct {
	StartTime        time.Time           `json:"startTime"`
	EndTime          time.Time           `json:"endTime"`
	TotalSeconds     math.Float64        `json:"totalSeconds"`
	ElapsedSeconds   math.Float64        `json:"elapsedSeconds,omitempty"`
	ConsumptionCount int                 `json:"consumptionCount"`
	Groups           []*ConsumptionGroup `json:"groups"`
}

func (*ConsumptionPeriod) TimeSegment

func (p *ConsumptionPeriod) TimeSegment() timeUtils.TimeSegment

type ConsumptionQuery

type ConsumptionQuery struct {
	FilterBy        map[string]string `json:"filterBy"`
	AggregateBy     []string          `json:"aggregateBy,omitempty"`
	ChargeableItems []string          `json:"chargeableItems,omitempty"`
}

func (*ConsumptionQuery) AggregatesByTimeStep

func (q *ConsumptionQuery) AggregatesByTimeStep() bool

func (*ConsumptionQuery) Clone

func (q *ConsumptionQuery) Clone() *ConsumptionQuery

func (*ConsumptionQuery) DoesAggregateBy

func (q *ConsumptionQuery) DoesAggregateBy(field string) bool

func (*ConsumptionQuery) EnsureAggregatesBy

func (q *ConsumptionQuery) EnsureAggregatesBy(field string)

func (*ConsumptionQuery) EnsureDoesNotAggregateBy

func (q *ConsumptionQuery) EnsureDoesNotAggregateBy(field string)

type CopyOrgRequest

type CopyOrgRequest struct {
	SourceBucket      int64     `json:"sourceBucket"`
	DestinationBucket int64     `json:"destinationBucket"`
	StartTime         time.Time `json:"startTime"`
	EndTime           time.Time `json:"endTime"`
}

type GetBucketRequest

type GetBucketRequest struct {
	Id int64 `json:"id"`
}

type MoveOrgRequest

type MoveOrgRequest struct {
	SourceBucket      int64     `json:"sourceBucket"`
	DestinationBucket int64     `json:"destinationBucket"`
	StartTime         time.Time `json:"startTime"`
	EndTime           time.Time `json:"endTime"`
}

type Org

type Org struct {
	Name     string    `json:"name" gorm:"primaryKey"`
	Created  time.Time `json:"created" gorm:"type:timestamptz;default:now()"`
	BucketId int64     `json:"bucketId"`
	Bucket   *Bucket   `json:"bucket,omitempty"`
}

func (*Org) String

func (o *Org) String() string

type QueryRequest

type QueryRequest struct {
	StartTime           time.Time          `json:"startTime"`
	EndTime             time.Time          `json:"endTime"`
	TimeStep            timeUtils.TimeStep `json:"timeStep"`
	GroupBy             []string           `json:"groupBy,omitempty"`
	AggregateByTimeStep bool               `json:"aggregateByTimeStep"`

	ConsumptionQueries []*ConsumptionQuery `json:"consumptionQueries"`
}

func (*QueryRequest) Clone

func (q *QueryRequest) Clone() *QueryRequest

func (*QueryRequest) SetTimeSegment

func (q *QueryRequest) SetTimeSegment(t timeUtils.TimeSegment) error

func (*QueryRequest) TimeSegment

func (q *QueryRequest) TimeSegment() timeUtils.TimeSegment

type QueryResult

type QueryResult struct {
	Periods          []*ConsumptionPeriod `json:"periods"`
	ConsumptionCount int                  `json:"consumptionCount"`
}

func (*QueryResult) AllConsumptions

func (q *QueryResult) AllConsumptions() []*Consumption

func (*QueryResult) Merge

func (q *QueryResult) Merge(other *QueryResult)

type QueryResultAggregator

type QueryResultAggregator struct {
	TimeStep timeUtils.TimeStep
	timeUtils.TimeSegment
	AggregateByTimeStep bool
	// contains filtered or unexported fields
}

func NewQueryResultAggregator

func NewQueryResultAggregator(aggregationPeriod timeUtils.TimeSegment, timeStep timeUtils.TimeStep, aggregateByTimeStep bool) QueryResultAggregator

func (QueryResultAggregator) AggregateQueryResults

func (q QueryResultAggregator) AggregateQueryResults(results ...*QueryResult) error

func (QueryResultAggregator) QueryResult

func (q QueryResultAggregator) QueryResult(timeStep timeUtils.TimeStep) (*QueryResult, error)

type ScrubOrgRequest

type ScrubOrgRequest struct {
	DestinationBucket int64     `json:"destinationBucket"`
	StartTime         time.Time `json:"startTime"`
	EndTime           time.Time `json:"endTime"`
}

type TagValuesQueryRequest

type TagValuesQueryRequest struct {
	StartTime time.Time         `json:"startTime"`
	EndTime   time.Time         `json:"endTime"`
	Tag       string            `json:"tag"`
	FilterBy  map[string]string `json:"filterBy"`
}

func (*TagValuesQueryRequest) TimeSegment

func (r *TagValuesQueryRequest) TimeSegment() timeUtils.TimeSegment

func (*TagValuesQueryRequest) Validate

func (r *TagValuesQueryRequest) Validate() error

type TagValuesQueryResult

type TagValuesQueryResult struct {
	*TagValuesQueryRequest
	TagValues []string `json:"tagValues"`
}

type VolumeSetConsumptionTags

type VolumeSetConsumptionTags struct {
	WorkloadConsumptionTags
	VolumeIndex      int    `json:"volumeIndex"`
	Driver           string `json:"driver"`
	PerformanceClass string `json:"performanceClass"`
}

type VolumeSetSnapshotConsumptionTags

type VolumeSetSnapshotConsumptionTags struct {
	VolumeSetConsumptionTags
	SnapshotName string `json:"snapshotName"`
}

type WorkloadConsumptionTags

type WorkloadConsumptionTags struct {
	BaseConsumptionTags
	Workload string `json:"workload"`
}

Jump to

Keyboard shortcuts

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