cloudcost

package
v1.109.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultChartItemsLength int = 10

DefaultChartItemsLength the default max number of items for a ViewGraphDataSet

Variables

This section is empty.

Functions

func CloudCostViewTableRowsToCSV

func CloudCostViewTableRowsToCSV(writer *csv.Writer, ctr ViewTableRows, window string) error

CloudCostViewTableRowsToCSV takes the csv writer and writes the ViewTableRows into the writer.

func DefaultMockCloudCostSet

func DefaultMockCloudCostSet(start, end time.Time, provider, integration string) *opencost.CloudCostSet

func NewIngestor

func NewIngestor(ingestorConfig IngestorConfig, repo Repository, config cloud.KeyedConfig) (*ingestor, error)

NewIngestor is an initializer for ingestor

Types

type CloudCostIntegration

type CloudCostIntegration interface {
	GetCloudCost(time.Time, time.Time) (*opencost.CloudCostSetRange, error)
	GetStatus() cloud.ConnectionStatus
}

CloudCostIntegration is an interface for retrieving daily granularity CloudCost data for a given range

func GetIntegrationFromConfig

func GetIntegrationFromConfig(kc cloud.KeyedConfig) CloudCostIntegration

GetIntegrationFromConfig coverts any valid KeyedConfig into the appropriate BillingIntegration if possible

type IngestionManager

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

IngestionManager is a config.Observer which creates Ingestor instances based on the signals that it receives from the config.Controller

func NewIngestionManager

func NewIngestionManager(controller *config.Controller, repo Repository, ingConf IngestorConfig) *IngestionManager

NewIngestionManager creates a new IngestionManager and registers it with the provided integration controller

func (*IngestionManager) DeleteConfig

func (im *IngestionManager) DeleteConfig(key string)

DeleteConfig is an imperative function which removes an ingestor with a matching key

func (*IngestionManager) PutConfig

func (im *IngestionManager) PutConfig(kc cloud.KeyedConfig)

PutConfig is an imperative function which puts an ingestor for the provided Integration

func (*IngestionManager) Rebuild

func (im *IngestionManager) Rebuild(integrationKey string) error

func (*IngestionManager) RebuildAll

func (im *IngestionManager) RebuildAll()

func (*IngestionManager) Repair

func (im *IngestionManager) Repair(integrationKey string, start, end time.Time) error

func (*IngestionManager) RepairAll

func (im *IngestionManager) RepairAll(start, end time.Time) error

func (*IngestionManager) SetConfigs

func (im *IngestionManager) SetConfigs(configs map[string]cloud.KeyedConfig)

SetConfigs is a declarative function for setting which BillingIntegrations IngestionManager should have ingestors for

func (*IngestionManager) StartAll

func (im *IngestionManager) StartAll()

func (*IngestionManager) StopAll

func (im *IngestionManager) StopAll()

type IngestorConfig

type IngestorConfig struct {
	MonthToDateRunInterval int
	RefreshRate            time.Duration
	Resolution             time.Duration
	Duration               time.Duration
	QueryWindow            time.Duration
	RunWindow              time.Duration
}

IngestorConfig is a configuration struct for an Ingestor

func DefaultIngestorConfiguration

func DefaultIngestorConfiguration() IngestorConfig

DefaultIngestorConfiguration retrieves an IngestorConfig from env variables

type IngestorStatus

type IngestorStatus struct {
	Created          time.Time
	LastRun          time.Time
	NextRun          time.Time
	Runs             int
	Coverage         opencost.Window
	ConnectionStatus cloud.ConnectionStatus
}

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, billingIntegration string) (*opencost.CloudCostSet, error)

func (*MemoryRepository) Has

func (m *MemoryRepository) Has(startTime time.Time, billingIntegration 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 CloudCost pipeline controls and diagnostics endpoints

func NewPipelineService

func NewPipelineService(repo Repository, ic *config.Controller, ingConf IngestorConfig) *PipelineService

NewPipelineService is a constructor for a PipelineService

func (*PipelineService) GetCloudCostRebuildHandler

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

GetCloudCostRebuildHandler creates a handler from a http request which initiates a rebuild of cloud cost pipeline, if an integrationKey is provided then it only rebuilds the specified billing integration

func (*PipelineService) GetCloudCostRepairHandler

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

GetCloudCostRepairHandler creates a handler from a http request which initiates a repair of cloud cost for a given window, if an integrationKey is provided then it only repairs the specified integration

func (*PipelineService) GetCloudCostStatusHandler

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

GetCloudCostStatusHandler creates a handler from a http request which returns a list of the billing integration status

func (*PipelineService) Status

func (dp *PipelineService) Status() []Status

Status merges status values from the config.Controller and the IngestionManager to give a combined view of that state of configs and their ingestion status

type Querier

type Querier interface {
	Query(QueryRequest, context.Context) (*opencost.CloudCostSetRange, error)
}

Querier allows for querying ranges of CloudCost data

type QueryRequest

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

func ParseCloudCostRequest

func ParseCloudCostRequest(qp httputil.QueryParams) (*QueryRequest, error)

type QueryService

type QueryService struct {
	Querier     Querier
	ViewQuerier ViewQuerier
}

QueryService surfaces endpoints for accessing CloudCost data in raw form or for display in views

func NewQueryService

func NewQueryService(querier Querier, viewQuerier ViewQuerier) *QueryService

func (*QueryService) GetCloudCostHandler

func (s *QueryService) GetCloudCostHandler() func(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func (*QueryService) GetCloudCostViewGraphHandler

func (s *QueryService) GetCloudCostViewGraphHandler() func(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func (*QueryService) GetCloudCostViewTableHandler

func (s *QueryService) GetCloudCostViewTableHandler() func(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

func (*QueryService) GetCloudCostViewTotalsHandler

func (s *QueryService) GetCloudCostViewTotalsHandler() 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) (*opencost.CloudCostSet, error)
	Keys() ([]string, error)
	Put(*opencost.CloudCostSet) error
	Expire(time.Time) error
}

Repository is an interface for storing and retrieving CloudCost data

type RepositoryQuerier

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

RepositoryQuerier is an implementation of Querier and ViewQuerier which pulls directly from a Repository

func NewRepositoryQuerier

func NewRepositoryQuerier(repo Repository) *RepositoryQuerier

func (*RepositoryQuerier) Query

func (*RepositoryQuerier) QueryViewGraph

func (rq *RepositoryQuerier) QueryViewGraph(request ViewQueryRequest, ctx context.Context) (ViewGraphData, error)

func (*RepositoryQuerier) QueryViewTable

func (rq *RepositoryQuerier) QueryViewTable(request ViewQueryRequest, ctx context.Context) (ViewTableRows, error)

func (*RepositoryQuerier) QueryViewTotals

func (rq *RepositoryQuerier) QueryViewTotals(request ViewQueryRequest, ctx context.Context) (*ViewTotals, error)

type SortDirection

type SortDirection string

SortDirection a string type that acts as an enumeration of possible request options

const (
	SortDirectionNone       SortDirection = ""
	SortDirectionAscending  SortDirection = "asc"
	SortDirectionDescending SortDirection = "desc"
)

func ParseSortDirection

func ParseSortDirection(sortDirection string) (SortDirection, error)

ParseSortDirection provides a resilient way to parse one of the enumerated SortDirection types from a string or throws an error if it is not able to.

type SortField

type SortField string

SortField a string type that acts as an enumeration of possible request options

const (
	SortFieldNone              SortField = ""
	SortFieldName              SortField = "name"
	SortFieldCost              SortField = "cost"
	SortFieldKubernetesPercent SortField = "kubernetesPercent"
)

func ParseSortField

func ParseSortField(sortColumn string) (SortField, error)

ParseSortField provides a resilient way to parse one of the enumerated SortField types from a string or throws an error if it is not able to.

type Status

type Status struct {
	Key              string             `json:"key"`
	Source           string             `json:"source"`
	Provider         string             `json:"provider"`
	Active           bool               `json:"active"`
	Valid            bool               `json:"valid"`
	LastRun          time.Time          `json:"lastRun"`
	NextRun          time.Time          `json:"nextRun"`
	RefreshRate      string             `json:"RefreshRate"`
	Created          time.Time          `json:"created"`
	Runs             int                `json:"runs"`
	Coverage         string             `json:"coverage"`
	ConnectionStatus string             `json:"connectionStatus"`
	Config           cloudconfig.Config `json:"config"`
}

Status gives the details and metadata of a CloudCost integration

type View

type View struct {
	GraphData  ViewGraphData `json:"graphData"`
	TableTotal *ViewTableRow `json:"tableTotal"`
	TableRows  ViewTableRows `json:"tableRows"`
}

View serves data to the Cloud Cost front end, in the structure it requires (i.e. a graph and a table).

type ViewGraphData

type ViewGraphData []*ViewGraphDataSet

func (ViewGraphData) Equal

func (vgd ViewGraphData) Equal(that ViewGraphData) bool

type ViewGraphDataSet

type ViewGraphDataSet struct {
	Start time.Time              `json:"start"`
	End   time.Time              `json:"end"`
	Items []ViewGraphDataSetItem `json:"items"`
}

func (*ViewGraphDataSet) Equal

func (vgds *ViewGraphDataSet) Equal(that *ViewGraphDataSet) bool

NOTE: does not compare start and end times, just that the items are equal

type ViewGraphDataSetItem

type ViewGraphDataSetItem struct {
	Name  string  `json:"name"`
	Value float64 `json:"value"`
}

func (ViewGraphDataSetItem) Equal

type ViewQuerier

type ViewQuerier interface {
	QueryViewGraph(ViewQueryRequest, context.Context) (ViewGraphData, error)
	QueryViewTotals(ViewQueryRequest, context.Context) (*ViewTotals, error)
	QueryViewTable(ViewQueryRequest, context.Context) (ViewTableRows, error)
}

ViewQuerier defines a contract for return View types to the QueryService to service the View Api

type ViewQueryRequest

type ViewQueryRequest struct {
	QueryRequest
	CostMetricName   opencost.CostMetricName
	ChartItemsLength int
	Offset           int
	Limit            int
	SortDirection    SortDirection
	SortColumn       SortField
}

type ViewTableRow

type ViewTableRow struct {
	Name              string            `json:"name"`
	Labels            map[string]string `json:"labels"`
	KubernetesPercent float64           `json:"kubernetesPercent"`
	Cost              float64           `json:"cost"`
}

func (*ViewTableRow) Equal

func (vtr *ViewTableRow) Equal(that *ViewTableRow) bool

type ViewTableRows

type ViewTableRows []*ViewTableRow

func (ViewTableRows) Equal

func (vtrs ViewTableRows) Equal(that ViewTableRows) bool

type ViewTotals added in v1.109.0

type ViewTotals struct {
	NumResults int           `json:"numResults"`
	Combined   *ViewTableRow `json:"combined"`
}

Jump to

Keyboard shortcuts

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