customcost

package
v1.112.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CustomCostZoneProp           CustomCostProperty = "zone"
	CustomCostAccountNameProp                       = "accountName"
	CustomCostChargeCategoryProp                    = "chargeCategory"
	CustomCostDescriptionProp                       = "description"
	CustomCostResourceNameProp                      = "resourceName"
	CustomCostResourceTypeProp                      = "resourceType"
	CustomCostProviderIdProp                        = "providerId"
	CustomCostUsageUnitProp                         = "usageUnit"
	CustomCostDomainProp                            = "domain"
	CustomCostCostSourceProp                        = "costSource"
)

Variables

This section is empty.

Functions

func GetCustomCostWindowAccumulation

func GetCustomCostWindowAccumulation(window opencost.Window, accumulate opencost.AccumulateOption) (opencost.Window, opencost.AccumulateOption, error)

func NewCustomCostFilterParser

func NewCustomCostFilterParser() ast.FilterParser

NewCustomCostFilterParser creates a new `ast.FilterParser` implementation which uses CustomCost specific fields

func NewCustomCostMatchCompiler

func NewCustomCostMatchCompiler() *matcher.MatchCompiler[*CustomCost]

Types

type CostResponse

type CostResponse struct {
	Window          opencost.Window `json:"window"`
	TotalBilledCost float32         `json:"totalBilledCost"`
	TotalListCost   float32         `json:"totalListCost"`
	CustomCosts     []*CustomCost   `json:"customCosts"`
}

func NewCostResponse

func NewCostResponse(ccs *CustomCostSet) *CostResponse

type CostTimeseriesRequest

type CostTimeseriesRequest struct {
	Start       time.Time
	End         time.Time
	AggregateBy []CustomCostProperty
	Accumulate  opencost.AccumulateOption
	Filter      filter.Filter
}

func ParseCustomCostTimeseriesRequest

func ParseCustomCostTimeseriesRequest(qp mapper.PrimitiveMap) (*CostTimeseriesRequest, error)

type CostTimeseriesResponse

type CostTimeseriesResponse struct {
	Window     opencost.Window `json:"window"`
	Timeseries []*CostResponse `json:"timeseries"`
}

type CostTotalRequest

type CostTotalRequest struct {
	Start       time.Time
	End         time.Time
	AggregateBy []CustomCostProperty
	Accumulate  opencost.AccumulateOption
	Filter      filter.Filter
}

func ParseCustomCostTotalRequest

func ParseCustomCostTotalRequest(qp mapper.PrimitiveMap) (*CostTotalRequest, error)

type CustomCost

type CustomCost struct {
	Id             string  `json:"id"`
	Zone           string  `json:"zone"`
	AccountName    string  `json:"account_name"`
	ChargeCategory string  `json:"charge_category"`
	Description    string  `json:"description"`
	ResourceName   string  `json:"resource_name"`
	ResourceType   string  `json:"resource_type"`
	ProviderId     string  `json:"provider_id"`
	BilledCost     float32 `json:"billedCost"`
	ListCost       float32 `json:"listCost"`
	ListUnitPrice  float32 `json:"list_unit_price"`
	UsageQuantity  float32 `json:"usage_quantity"`
	UsageUnit      string  `json:"usage_unit"`
	Domain         string  `json:"domain"`
	CostSource     string  `json:"cost_source"`
	Aggregate      string  `json:"aggregate"`
}

func ParseCustomCostResponse

func ParseCustomCostResponse(ccResponse *pb.CustomCostResponse) []*CustomCost

func (*CustomCost) Add

func (cc *CustomCost) Add(other *CustomCost)

type CustomCostIngestor

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

func NewCustomCostIngestor

func NewCustomCostIngestor(ingestorConfig *CustomCostIngestorConfig, repo Repository, plugins map[string]*plugin.Client, res time.Duration) (*CustomCostIngestor, error)

NewIngestor is an initializer for ingestor

func (*CustomCostIngestor) BuildWindow

func (ing *CustomCostIngestor) BuildWindow(start, end time.Time)

func (*CustomCostIngestor) LoadWindow

func (ing *CustomCostIngestor) LoadWindow(start, end time.Time)

func (*CustomCostIngestor) Rebuild

func (ing *CustomCostIngestor) Rebuild(domain string) error

func (*CustomCostIngestor) Start

func (ing *CustomCostIngestor) Start(rebuild bool)

func (*CustomCostIngestor) Status

func (ing *CustomCostIngestor) Status() IngestorStatus

Status returns an IngestorStatus that describes the current state of the ingestor

func (*CustomCostIngestor) Stop

func (ing *CustomCostIngestor) Stop()

type CustomCostIngestorConfig

type CustomCostIngestorConfig struct {
	MonthToDateRunInterval               int
	HourlyDuration, DailyDuration        time.Duration
	DailyQueryWindow, HourlyQueryWindow  time.Duration
	PluginConfigDir, PluginExecutableDir string
}

CustomCost IngestorConfig is a configuration struct for an Ingestor

func DefaultIngestorConfiguration

func DefaultIngestorConfiguration() CustomCostIngestorConfig

DefaultIngestorConfiguration retrieves an CustomCostIngestorConfig from env variables

type CustomCostProperty

type CustomCostProperty string

func ParseCustomCostProperties

func ParseCustomCostProperties(props []string) ([]CustomCostProperty, error)

func ParseCustomCostProperty

func ParseCustomCostProperty(text string) (CustomCostProperty, error)

type CustomCostSet

type CustomCostSet struct {
	CustomCosts []*CustomCost
	Window      opencost.Window
}

func NewCustomCostSet

func NewCustomCostSet(window opencost.Window) *CustomCostSet

func (*CustomCostSet) Add

func (ccs *CustomCostSet) Add(customCost *CustomCost)

func (*CustomCostSet) Aggregate

func (ccs *CustomCostSet) Aggregate(aggregateBy []CustomCostProperty) error

type IngestorStatus

type IngestorStatus struct {
	Created     time.Time
	LastRun     time.Time
	NextRun     time.Time
	Runs        int
	Coverage    map[string]opencost.Window
	RefreshRate time.Duration
}

IngestorStatus includes diagnostic values for a given Ingestor

type MemoryRepository

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

MemoryRepository is an implementation of Repository that uses a map keyed on config key and window start along with a RWMutex to make it threadsafe

func NewMemoryRepository

func NewMemoryRepository() *MemoryRepository

func (*MemoryRepository) Expire

func (m *MemoryRepository) Expire(limit time.Time) error

Expire deletes all items in the map with a start time before the given limit

func (*MemoryRepository) Get

func (m *MemoryRepository) Get(startTime time.Time, domain string) (*pb.CustomCostResponse, error)

func (*MemoryRepository) Has

func (m *MemoryRepository) Has(startTime time.Time, domain string) (bool, error)

func (*MemoryRepository) Keys

func (m *MemoryRepository) Keys() ([]string, error)

func (*MemoryRepository) Put

type PipelineService

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

PipelineService exposes CustomCost pipeline controls and diagnostics endpoints

func NewPipelineService

func NewPipelineService(hourlyrepo, dailyrepo Repository, ingConf CustomCostIngestorConfig) (*PipelineService, error)

NewPipelineService is a constructor for a PipelineService

func (*PipelineService) GetCustomCostRebuildHandler

func (s *PipelineService) GetCustomCostRebuildHandler() func(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

GetCustomCostRebuildHandler creates a handler from a http request which initiates a rebuild of custom cost pipeline, if a domain is provided then it only rebuilds the specified billing domain

func (*PipelineService) GetCustomCostStatusHandler

func (s *PipelineService) GetCustomCostStatusHandler() func(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

GetCustomCostStatusHandler creates a handler from a http request which returns the custom cost ingestor status

func (*PipelineService) Status

func (dp *PipelineService) Status() Status

Status gives a combined view of the state of configs and the ingestor status

type Querier

type Querier interface {
	QueryTotal(ctx context.Context, request CostTotalRequest) (*CostResponse, error)
	QueryTimeseries(ctx context.Context, request CostTimeseriesRequest) (*CostTimeseriesResponse, error)
}

type QueryService

type QueryService struct {
	Querier Querier
}

func NewQueryService

func NewQueryService(querier Querier) *QueryService

func (*QueryService) GetCustomCostTimeseriesHandler

func (qs *QueryService) GetCustomCostTimeseriesHandler() func(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func (*QueryService) GetCustomCostTotalHandler

func (qs *QueryService) GetCustomCostTotalHandler() func(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

type Repository

type Repository interface {
	Has(time.Time, string) (bool, error)
	Get(time.Time, string) (*pb.CustomCostResponse, error)
	Keys() ([]string, error)
	Put(*pb.CustomCostResponse) error
	Expire(time.Time) error
}

Repository is an interface for storing and retrieving CustomCost data

type RepositoryQuerier

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

func NewRepositoryQuerier

func NewRepositoryQuerier(hourlyRepo, dailyRepo Repository, hourlyDuration, dailyDuration time.Duration) *RepositoryQuerier

func (*RepositoryQuerier) QueryTimeseries

func (*RepositoryQuerier) QueryTotal

func (rq *RepositoryQuerier) QueryTotal(ctx context.Context, request CostTotalRequest) (*CostResponse, error)

type Status

type Status struct {
	Enabled           bool                       `json:"enabled"`
	Domains           []string                   `json:"domains"`
	Key               string                     `json:"key,omitempty"`
	Source            string                     `json:"source,omitempty"`
	Provider          string                     `json:"provider,omitempty"`
	Active            bool                       `json:"active,omitempty"`
	Valid             bool                       `json:"valid,omitempty"`
	LastRun           time.Time                  `json:"lastRun,omitempty"`
	NextRun           time.Time                  `json:"nextRun,omitempty"`
	RefreshRateDaily  string                     `json:"RefreshRateDaily,omitempty"`
	RefreshRateHourly string                     `json:"RefreshRateHourly,omitempty"`
	Created           time.Time                  `json:"created,omitempty"`
	Runs              int                        `json:"runs,omitempty"`
	CoverageHourly    map[string]opencost.Window `json:"coverageHourly,omitempty"`
	CoverageDaily     map[string]opencost.Window `json:"coverageDaily,omitempty"`
	ConnectionStatus  string                     `json:"connectionStatus,omitempty"`
}

Status gives the details and metadata of a CustomCost integration

Jump to

Keyboard shortcuts

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