gcp

package
v1.113.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	UsageDateColumnName          = "usage_date"
	BillingAccountIDColumnName   = "billing_id"
	ProjectIDColumnName          = "project_id"
	ProjectNameColumnName        = "project_name"
	RegionColumnName             = "region"
	ZoneColumnName               = "zone"
	ServiceDescriptionColumnName = "service"
	SKUDescriptionColumnName     = "description"
	LabelsColumnName             = "labels"
	ResourceNameColumnName       = "resource"
	ResourceGlobalNameColumnName = "global_resource"
	CostColumnName               = "cost"
	ListCostColumnName           = "list_cost"
	CreditsColumnName            = "credits"
)
View Source
const (
	GCPHourlyPublicIPCost = 0.01

	GCPMonthlyBasicDiskCost = 0.04
	GCPMonthlySSDDiskCost   = 0.17
	GCPMonthlyGP2DiskCost   = 0.1

	GKEPreemptibleLabel = "cloud.google.com/gke-preemptible"
	GKESpotLabel        = "cloud.google.com/gke-spot"
)
View Source
const (
	GCPReservedInstanceResourceTypeRAM string = "MEMORY"
	GCPReservedInstanceResourceTypeCPU string = "VCPU"
	GCPReservedInstanceStatusActive    string = "ACTIVE"
	GCPReservedInstancePlanOneYear     string = "TWELVE_MONTH"
	GCPReservedInstancePlanThreeYear   string = "THIRTY_SIX_MONTH"
)
View Source
const BigqueryUpdateType = "bigqueryupdate"
View Source
const BillingAPIURLFmt = "https://cloudbilling.googleapis.com/v1/services/6F81-5844-456A/skus?key=%s&currencyCode=%s"
View Source
const BiqQueryWhereDateFmt = `usage_start_time >= "%s" AND usage_start_time < "%s"`
View Source
const BiqQueryWherePartitionFmt = `DATE(_PARTITIONTIME) >= "%s" AND DATE(_PARTITIONTIME) < "%s"`
View Source
const GKE_GPU_TAG = "cloud.google.com/gke-accelerator"
View Source
const ServiceAccountKeyAuthorizerType = "GCPServiceAccountKey"
View Source
const WorkloadIdentityAuthorizerType = "GCPWorkloadIdentity"

Variables

This section is empty.

Functions

func ConvertBigQueryConfigToConfig

func ConvertBigQueryConfigToConfig(bqc BigQueryConfig) cloud.KeyedConfig

func GetWhereConjuncts added in v1.108.0

func GetWhereConjuncts(start time.Time, end time.Time) []string

GetWhereConjuncts creates a list of Where filter statements that filter for usage start date and partition time additional filters can be added before combining into the final where clause

func IsK8s

func IsK8s(labels map[string]string) bool

func ParseGCPProjectID

func ParseGCPProjectID(id string) string

func ParseProviderID

func ParseProviderID(id string) string

func SelectCategory

func SelectCategory(service, description string) string

Types

type Authorizer

type Authorizer interface {
	cloud.Authorizer
	CreateGCPClientOptions() ([]option.ClientOption, error)
}

Authorizer provide a []option.ClientOption which is used in when creating clients in the GCP SDK

func SelectAuthorizerByType

func SelectAuthorizerByType(typeStr string) (Authorizer, error)

SelectAuthorizerByType is an implementation of AuthorizerSelectorFn and acts as a register for Authorizer types

type BigQueryConfig

type BigQueryConfig struct {
	ProjectID          string            `json:"projectID"`
	BillingDataDataset string            `json:"billingDataDataset"`
	Key                map[string]string `json:"key"`
}

BigQueryConfig contain the required config and credentials to access OOC resources for GCP Deprecated: v1.104 Use BigQueryConfiguration instead

func (*BigQueryConfig) IsEmpty

func (bqc *BigQueryConfig) IsEmpty() bool

IsEmpty returns true if all fields in config are empty, false if not.

type BigQueryConfiguration

type BigQueryConfiguration struct {
	ProjectID  string     `json:"projectID"`
	Dataset    string     `json:"dataset"`
	Table      string     `json:"table"`
	Authorizer Authorizer `json:"authorizer"`
}

func (*BigQueryConfiguration) Equals

func (bqc *BigQueryConfiguration) Equals(config cloud.Config) bool

func (*BigQueryConfiguration) GetBigQueryClient

func (bqc *BigQueryConfiguration) GetBigQueryClient(ctx context.Context) (*bigquery.Client, error)

func (*BigQueryConfiguration) GetBillingDataDataset

func (bqc *BigQueryConfiguration) GetBillingDataDataset() string

func (*BigQueryConfiguration) Key

func (bqc *BigQueryConfiguration) Key() string

Key uses the Usage Project Id as the Provider Key for GCP

func (*BigQueryConfiguration) Provider added in v1.107.0

func (bqc *BigQueryConfiguration) Provider() string

func (*BigQueryConfiguration) Sanitize

func (bqc *BigQueryConfiguration) Sanitize() cloud.Config

func (*BigQueryConfiguration) UnmarshalJSON

func (bqc *BigQueryConfiguration) UnmarshalJSON(b []byte) error

UnmarshalJSON assumes data is save as an BigQueryConfigurationDTO

func (*BigQueryConfiguration) Validate

func (bqc *BigQueryConfiguration) Validate() error

type BigQueryIntegration

type BigQueryIntegration struct {
	BigQueryQuerier
}

func (*BigQueryIntegration) GetCloudCost

func (bqi *BigQueryIntegration) GetCloudCost(start time.Time, end time.Time) (*opencost.CloudCostSetRange, error)

func (*BigQueryIntegration) GetFlexibleCUDRates added in v1.108.0

func (bqi *BigQueryIntegration) GetFlexibleCUDRates(start time.Time, end time.Time) (map[time.Time]FlexibleCUDRates, error)

GetFlexibleCUDRates returns a map of FlexibleCUDRates keyed on the start time of the day which those FlexibleCUDRates were derived from.

type BigQueryQuerier

type BigQueryQuerier struct {
	BigQueryConfiguration
	ConnectionStatus cloud.ConnectionStatus
}

func (*BigQueryQuerier) Equals

func (bqq *BigQueryQuerier) Equals(config cloud.Config) bool

func (*BigQueryQuerier) GetStatus added in v1.107.0

func (bqq *BigQueryQuerier) GetStatus() cloud.ConnectionStatus

func (*BigQueryQuerier) Query

func (bqq *BigQueryQuerier) Query(ctx context.Context, queryStr string) (*bigquery.RowIterator, error)

type CloudCostLoader

type CloudCostLoader struct {
	CloudCost        *opencost.CloudCost
	FlexibleCUDRates map[time.Time]FlexibleCUDRates
}

func (*CloudCostLoader) Load

func (ccl *CloudCostLoader) Load(values []bigquery.Value, schema bigquery.Schema) error

Load populates the fields of a CloudCostValues with bigquery.Value from provided slice

type FlexibleCUDCostTotalsLoader added in v1.108.0

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

func (*FlexibleCUDCostTotalsLoader) Load added in v1.108.0

func (ctl *FlexibleCUDCostTotalsLoader) Load(values []bigquery.Value, schema bigquery.Schema) error

type FlexibleCUDCreditTotalsLoader added in v1.108.0

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

func (*FlexibleCUDCreditTotalsLoader) Load added in v1.108.0

func (ctl *FlexibleCUDCreditTotalsLoader) Load(values []bigquery.Value, schema bigquery.Schema) error

type FlexibleCUDRates added in v1.108.0

type FlexibleCUDRates struct {
	NetRate float64
	Rate    float64
}

FlexibleCUDRates are the total amount paid / total amount credited per day for all Flexible CUDs. Since credited will be a negative value this will be a negative ratio. This can then be multiplied with the credits from Flexible CUDs on specific line items to determine the amount paid for the credit it received. This allows us to amortize the Flexible CUD costs which are not associated with resources in the billing export. AmountPayed itself may have some credits on it so a Rate and a NetRate are created. Having both allow us to populate AmortizedCost and AmortizedNetCost respectively.

type GCP

type GCP struct {
	Pricing                 map[string]*GCPPricing
	Clientset               clustercache.ClusterCache
	APIKey                  string
	BaseCPUPrice            string
	ProjectID               string
	BillingDataDataset      string
	DownloadPricingDataLock sync.RWMutex
	ReservedInstances       []*GCPReservedInstance
	Config                  models.ProviderConfig
	ServiceKeyProvided      bool
	ValidPricingKeys        map[string]bool
	MetadataClient          *metadata.Client

	ClusterRegion    string
	ClusterAccountID string
	ClusterProjectID string
	// contains filtered or unexported fields
}

GCP implements a provider interface for GCP

func (*GCP) AllNodePricing

func (gcp *GCP) AllNodePricing() (interface{}, error)

AllNodePricing returns the GCP pricing objects stored

func (*GCP) ApplyReservedInstancePricing

func (gcp *GCP) ApplyReservedInstancePricing(nodes map[string]*models.Node)

func (*GCP) ClusterInfo

func (gcp *GCP) ClusterInfo() (map[string]string, error)

ClusterInfo returns information on the GKE cluster, as provided by metadata.

func (*GCP) ClusterManagementPricing

func (gcp *GCP) ClusterManagementPricing() (string, float64, error)

func (*GCP) CombinedDiscountForNode

func (gcp *GCP) CombinedDiscountForNode(instanceType string, isPreemptible bool, defaultDiscount, negotiatedDiscount float64) float64

func (*GCP) DownloadPricingData

func (gcp *GCP) DownloadPricingData() error

DownloadPricingData fetches data from the GCP Pricing API. Requires a key-- a kubecost key is provided for quickstart, but should be replaced by a users.

func (*GCP) GetAddresses

func (gcp *GCP) GetAddresses() ([]byte, error)

func (*GCP) GetConfig

func (gcp *GCP) GetConfig() (*models.CustomPricing, error)

func (*GCP) GetDisks

func (gcp *GCP) GetDisks() ([]byte, error)

GetDisks returns the GCP disks backing PVs. Useful because sometimes k8s will not clean up PVs correctly. Requires a json config in /var/configs with key region.

func (*GCP) GetKey

func (gcp *GCP) GetKey(labels map[string]string, n *v1.Node) models.Key

func (*GCP) GetLocalStorageQuery

func (gcp *GCP) GetLocalStorageQuery(window, offset time.Duration, rate bool, used bool) string

GetLocalStorageQuery returns the cost of local storage for the given window. Setting rate=true returns hourly spend. Setting used=true only tracks used storage, not total.

func (*GCP) GetManagementPlatform

func (gcp *GCP) GetManagementPlatform() (string, error)

func (*GCP) GetOrphanedResources

func (gcp *GCP) GetOrphanedResources() ([]models.OrphanedResource, error)

func (*GCP) GetPVKey

func (gcp *GCP) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string, defaultRegion string) models.PVKey

func (*GCP) LoadBalancerPricing

func (gcp *GCP) LoadBalancerPricing() (*models.LoadBalancer, error)

func (*GCP) NetworkPricing

func (gcp *GCP) NetworkPricing() (*models.Network, error)

Stubbed NetworkPricing for GCP. Pull directly from gcp.json for now

func (*GCP) NodePricing

func (gcp *GCP) NodePricing(key models.Key) (*models.Node, models.PricingMetadata, error)

NodePricing returns GCP pricing data for a single node

func (*GCP) PVPricing

func (gcp *GCP) PVPricing(pvk models.PVKey) (*models.PV, error)

func (*GCP) PricingSourceStatus

func (gcp *GCP) PricingSourceStatus() map[string]*models.PricingSource

func (*GCP) PricingSourceSummary

func (gcp *GCP) PricingSourceSummary() interface{}

PricingSourceSummary returns the pricing source summary for the provider. The summary represents what was _parsed_ from the pricing source, not everything that was _available_ in the pricing source.

func (*GCP) Regions

func (gcp *GCP) Regions() []string

func (*GCP) ServiceAccountStatus

func (gcp *GCP) ServiceAccountStatus() *models.ServiceAccountStatus

func (*GCP) UpdateConfig

func (gcp *GCP) UpdateConfig(r io.Reader, updateType string) (*models.CustomPricing, error)

func (*GCP) UpdateConfigFromConfigMap

func (gcp *GCP) UpdateConfigFromConfigMap(a map[string]string) (*models.CustomPricing, error)

type GCPPricing

type GCPPricing struct {
	Name                string           `json:"name"`
	SKUID               string           `json:"skuId"`
	Description         string           `json:"description"`
	Category            *GCPResourceInfo `json:"category"`
	ServiceRegions      []string         `json:"serviceRegions"`
	PricingInfo         []*PricingInfo   `json:"pricingInfo"`
	ServiceProviderName string           `json:"serviceProviderName"`
	Node                *models.Node     `json:"node"`
	PV                  *models.PV       `json:"pv"`
}

GCPPricing represents GCP pricing data for a SKU

type GCPReservedCounter

type GCPReservedCounter struct {
	RemainingCPU int64
	RemainingRAM int64
	Instance     *GCPReservedInstance
}

type GCPReservedInstance

type GCPReservedInstance struct {
	ReservedRAM int64
	ReservedCPU int64
	Plan        *GCPReservedInstancePlan
	StartDate   time.Time
	EndDate     time.Time
	Region      string
}

func (*GCPReservedInstance) String

func (r *GCPReservedInstance) String() string

type GCPReservedInstancePlan

type GCPReservedInstancePlan struct {
	Name    string
	CPUCost float64
	RAMCost float64
}

type GCPResourceInfo

type GCPResourceInfo struct {
	ServiceDisplayName string `json:"serviceDisplayName"`
	ResourceFamily     string `json:"resourceFamily"`
	ResourceGroup      string `json:"resourceGroup"`
	UsageType          string `json:"usageType"`
}

GCPResourceInfo contains metadata about the node.

type PricingExpression

type PricingExpression struct {
	UsageUnit                string         `json:"usageUnit"`
	UsageUnitDescription     string         `json:"usageUnitDescription"`
	BaseUnit                 string         `json:"baseUnit"`
	BaseUnitConversionFactor int64          `json:"-"`
	DisplayQuantity          int            `json:"displayQuantity"`
	TieredRates              []*TieredRates `json:"tieredRates"`
}

PricingExpression contains metadata about a cost.

type PricingInfo

type PricingInfo struct {
	Summary                string             `json:"summary"`
	PricingExpression      *PricingExpression `json:"pricingExpression"`
	CurrencyConversionRate float64            `json:"currencyConversionRate"`
	EffectiveTime          string             `json:""`
}

PricingInfo contains metadata about a cost.

type ServiceAccountKey

type ServiceAccountKey struct {
	Key map[string]string `json:"key"`
}

func (*ServiceAccountKey) CreateGCPClientOptions

func (gkc *ServiceAccountKey) CreateGCPClientOptions() ([]option.ClientOption, error)

func (*ServiceAccountKey) Equals

func (gkc *ServiceAccountKey) Equals(config cloud.Config) bool

func (*ServiceAccountKey) MarshalJSON

func (gkc *ServiceAccountKey) MarshalJSON() ([]byte, error)

MarshalJSON custom json marshalling functions, sets properties as tagged in struct and sets the authorizer type property

func (*ServiceAccountKey) Sanitize

func (gkc *ServiceAccountKey) Sanitize() cloud.Config

func (*ServiceAccountKey) Validate

func (gkc *ServiceAccountKey) Validate() error

type TieredRates

type TieredRates struct {
	StartUsageAmount int            `json:"startUsageAmount"`
	UnitPrice        *UnitPriceInfo `json:"unitPrice"`
}

TieredRates contain data about variable pricing.

type UnitPriceInfo

type UnitPriceInfo struct {
	CurrencyCode string  `json:"currencyCode"`
	Units        string  `json:"units"`
	Nanos        float64 `json:"nanos"`
}

UnitPriceInfo contains data about the actual price being charged.

type WorkloadIdentity

type WorkloadIdentity struct{}

WorkloadIdentity passes an empty slice of client options which causes the GCP SDK to check for the workload identity in the environment

func (*WorkloadIdentity) CreateGCPClientOptions

func (wi *WorkloadIdentity) CreateGCPClientOptions() ([]option.ClientOption, error)

func (*WorkloadIdentity) Equals

func (wi *WorkloadIdentity) Equals(config cloud.Config) bool

func (*WorkloadIdentity) MarshalJSON

func (wi *WorkloadIdentity) MarshalJSON() ([]byte, error)

MarshalJSON custom json marshalling functions, sets properties as tagged in struct and sets the authorizer type property

func (*WorkloadIdentity) Sanitize

func (wi *WorkloadIdentity) Sanitize() cloud.Config

func (*WorkloadIdentity) Validate

func (wi *WorkloadIdentity) Validate() error

Jump to

Keyboard shortcuts

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