costmodel

package
v0.0.0-...-e26cdd7 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Hourly  Period = 1
	Daily          = 24
	Weekly         = 24 * 7
	Monthly        = 24 * 30
	Yearly         = 24 * 365
)
View Source
const CommentPrefix = "<!-- kost -->"

CommentPrefix is used to identify and hide old messages on GitHub.

Variables

View Source
var (
	ErrNoResults         = errors.New("no cost results")
	ErrBadQuery          = errors.New("bad query")
	ErrNilConfig         = errors.New("client config is nil")
	ErrEmptyAddress      = errors.New("client address can't be empty")
	ErrProdConfigMissing = errors.New("prod config is missing")
)

ErrNoResults is the error returned when querying for costs returns no results.

View Source
var ErrNoReports = errors.New("nothing to report")
View Source
var ErrUnknownKind = errors.New("unknown kind")

ErrUnknownKind is the error throw when the kind of the resource in the manifest is unknown to the parser.

Functions

This section is empty.

Types

type Client

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

Client is a client for the cost model.

func NewClient

func NewClient(config *ClientConfig) (*Client, error)

NewClient creates a new cost model client with the given configuration.

func (*Client) GetCostForPersistentVolume

func (c *Client) GetCostForPersistentVolume(ctx context.Context, cluster string) (Cost, error)

GetCostForPersistentVolume returns the average cost per persistent volume for a given cluster

func (*Client) GetCostPerCPU

func (c *Client) GetCostPerCPU(ctx context.Context, cluster string) (Cost, error)

GetCostPerCPU returns the average cost per CPU for a given cluster.

func (*Client) GetMemoryCost

func (c *Client) GetMemoryCost(ctx context.Context, cluster string) (Cost, error)

GetMemoryCost returns the cost per memory for a given cluster

func (*Client) GetNodeCount

func (c *Client) GetNodeCount(ctx context.Context, cluster string) (int, error)

GetNodeCount returns the average number of nodes over 30 days for a given cluster

type ClientConfig

type ClientConfig struct {
	Address        string
	HTTPConfigFile string
	Username       string
	Password       string
}

ClientConfig is the configuration for the cost model client.

type Clients

type Clients struct {
	Prod *Client
	Dev  *Client
}

Clients bundles the dev and prod client in one struct.

func NewClients

func NewClients(prodConfig, devConfig *ClientConfig) (*Clients, error)

NewClients creates a new cost model clients with the given configuration.

func (*Clients) GetClusterCosts

func (c *Clients) GetClusterCosts(ctx context.Context, cluster string) (*CostModel, error)

GetClusterCosts returns the cost for a cluster and differentiate for dev and prod clusters

type Cluster

type Cluster struct {
	Name      string
	NodeCount int
}

type Cost

type Cost struct {
	Dollars float64
	Spot    float64
	NonSpot float64
}

Cost represents the _hourly_ cost of a resource in USD. If the cluster does not have pricing data for spot nodes, then Dollars will be set.

func (Cost) DollarsForPeriod

func (c Cost) DollarsForPeriod(p Period, r int64) float64

DollarsForPeriod returns the cost of a resource in USD for a given period. Primarily used by PersistentVolumeClaims which do not have spot/non spot pricing.

func (Cost) DollarsYearly

func (c Cost) DollarsYearly(memReq int64) float64

func (Cost) NonSpotCPUForPeriod

func (c Cost) NonSpotCPUForPeriod(p Period, r int64) float64

func (Cost) NonSpotMemoryForPeriod

func (c Cost) NonSpotMemoryForPeriod(p Period, r int64) float64

func (Cost) NonSpotYearly

func (c Cost) NonSpotYearly(cpuReq int64) float64

func (Cost) SpotCPUForPeriod

func (c Cost) SpotCPUForPeriod(p Period, r int64) float64

func (Cost) SpotMemoryForPeriod

func (c Cost) SpotMemoryForPeriod(p Period, r int64) float64

func (Cost) SpotYearly

func (c Cost) SpotYearly(cpuReq int64) float64

type CostModel

type CostModel struct {
	Cluster          *Cluster
	CPU              Cost
	RAM              Cost
	PersistentVolume Cost
}

CostModel represents the cost of each resource for a specific cluster

func GetCostModelForCluster

func GetCostModelForCluster(ctx context.Context, client *Client, cluster string) (*CostModel, error)

func (*CostModel) TotalCostForPeriod

func (c *CostModel) TotalCostForPeriod(p Period, r Requirements) float64

TotalCostForPeriod calculates the costs of each resource on the CostModel and returns the sum of the costs

type Period

type Period float64

func (Period) Keys

func (p Period) Keys() PeriodKeys

func (Period) String

func (p Period) String() string

type PeriodKeys

type PeriodKeys struct {
	To    string
	Delta string
	From  string
}

type ReportType

type ReportType string
const (
	Table    ReportType = "table"
	Summary  ReportType = "summary"
	Markdown ReportType = "markdown"
)

type Reporter

type Reporter struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

func New

func New(w io.Writer, reportType string) *Reporter

func (*Reporter) AddReport

func (r *Reporter) AddReport(costModel *CostModel, from, to Requirements)

AddReport adds a costmodel and associated from, to resources to the reporter.

func (*Reporter) Write

func (r *Reporter) Write() error

type Requirements

type Requirements struct {
	CPU              int64
	Memory           int64
	PersistentVolume int64
	Kind             string
	Namespace        string
	Name             string
}

Requirements is a struct that holds the aggergated amount of resources for a given manifest file. CPU and Memory are in millicores and bytes respectively and are the sum of all containers in a pod. TODO: Calculate the amount of persistent volume required for a given manifest. This will require finding the associated PVC and calculating the size of the volume.

func Delta

func Delta(from, to Requirements) Requirements

Delta returns the difference between two resources. A positive value signals that the resource has increased. A negative value signals that the resource has decreased.

func ParseManifest

func ParseManifest(src []byte, costModel *CostModel) (Requirements, error)

ParseManifest will parse a manifest file and return the aggregated amount of resources requested. The manifest can be a Deployment, StatefulSet, DaemonSet, Cronjob, Job, or Pod. If the manifest has the number of Replicas, the total resources will be multiplied by the number of replicas.

func (*Requirements) AddRequirements

func (r *Requirements) AddRequirements(reqs corev1.ResourceRequirements)

AddRequirements will increment the resources by the amount specified in the given requirements.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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