Documentation ¶
Index ¶
- Constants
- func ConvertBigQueryConfigToConfig(bqc BigQueryConfig) cloud.KeyedConfig
- func GetWhereConjuncts(start time.Time, end time.Time) []string
- func IsK8s(labels map[string]string) bool
- func ParseGCPProjectID(id string) string
- func ParseProviderID(id string) string
- func SelectCategory(service, description string) string
- type Authorizer
- type BigQueryConfig
- type BigQueryConfiguration
- func (bqc *BigQueryConfiguration) Equals(config cloud.Config) bool
- func (bqc *BigQueryConfiguration) GetBigQueryClient(ctx context.Context) (*bigquery.Client, error)
- func (bqc *BigQueryConfiguration) GetBillingDataDataset() string
- func (bqc *BigQueryConfiguration) Key() string
- func (bqc *BigQueryConfiguration) Provider() string
- func (bqc *BigQueryConfiguration) Sanitize() cloud.Config
- func (bqc *BigQueryConfiguration) UnmarshalJSON(b []byte) error
- func (bqc *BigQueryConfiguration) Validate() error
- type BigQueryIntegration
- type BigQueryQuerier
- type CloudCostLoader
- type FlexibleCUDCostTotalsLoader
- type FlexibleCUDCreditTotalsLoader
- type FlexibleCUDRates
- type GCP
- func (gcp *GCP) AllNodePricing() (interface{}, error)
- func (gcp *GCP) ApplyReservedInstancePricing(nodes map[string]*models.Node)
- func (gcp *GCP) ClusterInfo() (map[string]string, error)
- func (gcp *GCP) ClusterManagementPricing() (string, float64, error)
- func (gcp *GCP) CombinedDiscountForNode(instanceType string, isPreemptible bool, ...) float64
- func (gcp *GCP) DownloadPricingData() error
- func (gcp *GCP) GetAddresses() ([]byte, error)
- func (gcp *GCP) GetConfig() (*models.CustomPricing, error)
- func (gcp *GCP) GetDisks() ([]byte, error)
- func (gcp *GCP) GetKey(labels map[string]string, n *v1.Node) models.Key
- func (gcp *GCP) GetLocalStorageQuery(window, offset time.Duration, rate bool, used bool) string
- func (gcp *GCP) GetManagementPlatform() (string, error)
- func (gcp *GCP) GetOrphanedResources() ([]models.OrphanedResource, error)
- func (gcp *GCP) GetPVKey(pv *v1.PersistentVolume, parameters map[string]string, defaultRegion string) models.PVKey
- func (gcp *GCP) LoadBalancerPricing() (*models.LoadBalancer, error)
- func (gcp *GCP) NetworkPricing() (*models.Network, error)
- func (gcp *GCP) NodePricing(key models.Key) (*models.Node, models.PricingMetadata, error)
- func (gcp *GCP) PVPricing(pvk models.PVKey) (*models.PV, error)
- func (gcp *GCP) PricingSourceStatus() map[string]*models.PricingSource
- func (gcp *GCP) PricingSourceSummary() interface{}
- func (gcp *GCP) Regions() []string
- func (gcp *GCP) ServiceAccountStatus() *models.ServiceAccountStatus
- func (gcp *GCP) UpdateConfig(r io.Reader, updateType string) (*models.CustomPricing, error)
- func (gcp *GCP) UpdateConfigFromConfigMap(a map[string]string) (*models.CustomPricing, error)
- type GCPPricing
- type GCPReservedCounter
- type GCPReservedInstance
- type GCPReservedInstancePlan
- type GCPResourceInfo
- type PricingExpression
- type PricingInfo
- type ServiceAccountKey
- func (gkc *ServiceAccountKey) CreateGCPClientOptions() ([]option.ClientOption, error)
- func (gkc *ServiceAccountKey) Equals(config cloud.Config) bool
- func (gkc *ServiceAccountKey) MarshalJSON() ([]byte, error)
- func (gkc *ServiceAccountKey) Sanitize() cloud.Config
- func (gkc *ServiceAccountKey) Validate() error
- type TieredRates
- type UnitPriceInfo
- type WorkloadIdentity
Constants ¶
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" )
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" )
const ( GCPReservedInstanceResourceTypeRAM string = "MEMORY" GCPReservedInstanceResourceTypeCPU string = "VCPU" GCPReservedInstanceStatusActive string = "ACTIVE" GCPReservedInstancePlanOneYear string = "TWELVE_MONTH" GCPReservedInstancePlanThreeYear string = "THIRTY_SIX_MONTH" )
const BigqueryUpdateType = "bigqueryupdate"
const BillingAPIURLFmt = "https://cloudbilling.googleapis.com/v1/services/6F81-5844-456A/skus?key=%s¤cyCode=%s"
const BiqQueryWhereDateFmt = `usage_start_time >= "%s" AND usage_start_time < "%s"`
const BiqQueryWherePartitionFmt = `DATE(_PARTITIONTIME) >= "%s" AND DATE(_PARTITIONTIME) < "%s"`
const GKE_GPU_TAG = "cloud.google.com/gke-accelerator"
const ServiceAccountKeyAuthorizerType = "GCPServiceAccountKey"
const WorkloadIdentityAuthorizerType = "GCPWorkloadIdentity"
Variables ¶
This section is empty.
Functions ¶
func ConvertBigQueryConfigToConfig ¶
func ConvertBigQueryConfigToConfig(bqc BigQueryConfig) cloud.KeyedConfig
func GetWhereConjuncts ¶ added in v1.108.0
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 ParseGCPProjectID ¶
func ParseProviderID ¶
func SelectCategory ¶
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 (*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) 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 }
type FlexibleCUDCostTotalsLoader ¶ added in v1.108.0
type FlexibleCUDCostTotalsLoader struct {
// contains filtered or unexported fields
}
type FlexibleCUDCreditTotalsLoader ¶ added in v1.108.0
type FlexibleCUDCreditTotalsLoader struct {
// contains filtered or unexported fields
}
type FlexibleCUDRates ¶ added in v1.108.0
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 ¶
AllNodePricing returns the GCP pricing objects stored
func (*GCP) ApplyReservedInstancePricing ¶
func (*GCP) ClusterInfo ¶
ClusterInfo returns information on the GKE cluster, as provided by metadata.
func (*GCP) ClusterManagementPricing ¶
func (*GCP) CombinedDiscountForNode ¶
func (*GCP) DownloadPricingData ¶
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) GetDisks ¶
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) GetLocalStorageQuery ¶
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) GetOrphanedResources ¶
func (gcp *GCP) GetOrphanedResources() ([]models.OrphanedResource, error)
func (*GCP) LoadBalancerPricing ¶
func (gcp *GCP) LoadBalancerPricing() (*models.LoadBalancer, error)
func (*GCP) NetworkPricing ¶
Stubbed NetworkPricing for GCP. Pull directly from gcp.json for now
func (*GCP) NodePricing ¶
NodePricing returns GCP pricing data for a single node
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) ServiceAccountStatus ¶
func (gcp *GCP) ServiceAccountStatus() *models.ServiceAccountStatus
func (*GCP) UpdateConfig ¶
func (*GCP) UpdateConfigFromConfigMap ¶
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 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 ¶
func (*ServiceAccountKey) CreateGCPClientOptions ¶
func (gkc *ServiceAccountKey) CreateGCPClientOptions() ([]option.ClientOption, error)
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) 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