client

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BillingToRegionMap = map[string]string{
	"APE1":                   "ap-east-1",
	"APN1":                   "ap-northeast-1",
	"APN2":                   "ap-northeast-2",
	"APN3":                   "ap-northeast-3",
	"APS1":                   "ap-southeast-1",
	"APS2":                   "ap-southeast-2",
	"APS3":                   "ap-south-1",
	"APS4":                   "ap-southeast-3",
	"APS5":                   "ap-south-2",
	"APS6":                   "ap-southeast-4",
	"CAN1":                   "ca-central-1",
	"CNN1":                   "cn-north-1",
	"CNW1":                   "cn-northwest-1",
	"CPT1":                   "af-south-1",
	"EUC1":                   "eu-central-1",
	"EUC2":                   "eu-central-2",
	"EU":                     "eu-west-1",
	"EUW2":                   "eu-west-2",
	"EUW3":                   "eu-west-3",
	"EUN1":                   "eu-north-1",
	"EUS1":                   "eu-south-1",
	"EUS2":                   "eu-south-2",
	"MEC1":                   "me-central-1",
	"MES1":                   "me-south-1",
	"SAE1":                   "sa-east-1",
	"US":                     "us-east-1",
	"USE1":                   "us-east-1",
	"USE2":                   "us-east-2",
	"USW1":                   "us-west-1",
	"USW2":                   "us-west-2",
	"AWS GovCloud (US-East)": "us-gov-east-1",
	"AWS GovCloud (US)":      "us-gov-west-1",
}

billingToRegionMap maps the AWS billing region code to the AWS region Billing codes: https://docs.aws.amazon.com/AmazonS3/latest/userguide/aws-usage-report-understand.html Regions: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions

Functions

func ClusterNameFromInstance

func ClusterNameFromInstance(instance types.Instance) string

func NameFromVolume

func NameFromVolume(volume types.Volume) string

Types

type AWSClient

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

func NewAWSClient

func NewAWSClient(cfg Config) *AWSClient

func (*AWSClient) DescribeLoadBalancers added in v0.13.0

func (c *AWSClient) DescribeLoadBalancers(ctx context.Context) ([]elbTypes.LoadBalancer, error)

func (*AWSClient) DescribeRegions

func (c *AWSClient) DescribeRegions(ctx context.Context, allRegions bool) ([]types.Region, error)

func (*AWSClient) GetBillingData

func (c *AWSClient) GetBillingData(ctx context.Context, startDate time.Time, endDate time.Time) (*BillingData, error)

func (*AWSClient) GetRDSUnitData added in v0.15.0

func (c *AWSClient) GetRDSUnitData(ctx context.Context, instType, region, deploymentOption, databaseEngine, locationType string) (string, error)

func (*AWSClient) ListComputeInstances

func (c *AWSClient) ListComputeInstances(ctx context.Context) ([]types.Reservation, error)

func (*AWSClient) ListEBSVolumes

func (c *AWSClient) ListEBSVolumes(ctx context.Context) ([]types.Volume, error)

func (*AWSClient) ListEC2ServicePrices added in v0.13.0

func (c *AWSClient) ListEC2ServicePrices(ctx context.Context, region string, filters []pricingTypes.Filter) ([]string, error)

func (*AWSClient) ListELBPrices added in v0.13.0

func (c *AWSClient) ListELBPrices(ctx context.Context, region string) ([]string, error)

func (*AWSClient) ListOnDemandPrices

func (c *AWSClient) ListOnDemandPrices(ctx context.Context, region string) ([]string, error)

func (*AWSClient) ListRDSInstances added in v0.15.0

func (c *AWSClient) ListRDSInstances(ctx context.Context) ([]rdsTypes.DBInstance, error)

func (*AWSClient) ListSpotPrices

func (c *AWSClient) ListSpotPrices(ctx context.Context) ([]types.SpotPrice, error)

func (*AWSClient) ListStoragePrices

func (c *AWSClient) ListStoragePrices(ctx context.Context, region string) ([]string, error)

func (*AWSClient) ListVPCServicePrices added in v0.17.0

func (c *AWSClient) ListVPCServicePrices(ctx context.Context, region string, filters []pricingTypes.Filter) ([]string, error)

func (*AWSClient) Metrics

func (c *AWSClient) Metrics() []prometheus.Collector

type BillingData

type BillingData struct {
	// Regions is a map where string is the region and PricingModel is the value
	Regions map[string]*PricingModel
}

BillingData is the struct for the data we will be collecting

func (*BillingData) AddMetricGroup

func (s *BillingData) AddMetricGroup(region string, component string, group types.Group)

AddMetricGroup adds a metric group to the Region. If the key is empty, it will not add the metric group to the Region. If the dimension is empty, it will not add the metric group to the Region. Dimensions are cumulative and will be added to the same dimension if the dimension already exists.

type Client

type Client interface {
	GetBillingData(ctx context.Context, startDate time.Time, endDate time.Time) (*BillingData, error)
	DescribeRegions(ctx context.Context, allRegions bool) ([]types.Region, error)
	ListComputeInstances(ctx context.Context) ([]types.Reservation, error)
	ListEBSVolumes(ctx context.Context) ([]types.Volume, error)
	ListSpotPrices(ctx context.Context) ([]types.SpotPrice, error)
	ListOnDemandPrices(ctx context.Context, region string) ([]string, error)
	ListStoragePrices(ctx context.Context, region string) ([]string, error)
	ListEC2ServicePrices(ctx context.Context, region string, filters []pricingTypes.Filter) ([]string, error)
	ListVPCServicePrices(ctx context.Context, region string, filters []pricingTypes.Filter) ([]string, error)
	ListELBPrices(ctx context.Context, region string) ([]string, error)
	DescribeLoadBalancers(ctx context.Context) ([]elbTypes.LoadBalancer, error)
	ListRDSInstances(ctx context.Context) ([]rdsTypes.DBInstance, error)
	GetRDSUnitData(ctx context.Context, instType, region, deploymentOption, engineCode, isOutpost string) (string, error)

	// TODO: Break out Metrics into an independent interface
	Metrics() []prometheus.Collector
}

type Config

type Config struct {
	PricingService p.Pricing
	EC2Service     e.EC2
	BillingService c.CostExplorer
	RDSService     *rds.Client
	ELBService     elbv2client.ELBv2
}

type Metrics

type Metrics struct {
	// RequestCount is a counter that tracks the number of requests made to the AWS Cost Explorer API
	RequestCount prometheus.Counter

	// RequestErrorsCount is a counter that tracks the number of errors when making requests to the AWS Cost Explorer API
	RequestErrorsCount prometheus.Counter
}

func NewMetrics

func NewMetrics() *Metrics

type Pricing

type Pricing struct {
	Usage    float64
	Cost     float64
	Units    string
	UnitCost float64
}

type PricingModel

type PricingModel struct {
	// Model is a map where string is the component and Pricing is the usage, cost and unit
	Model map[string]*Pricing
}

Directories

Path Synopsis
Package mock_client is a generated GoMock package.
Package mock_client is a generated GoMock package.

Jump to

Keyboard shortcuts

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