gcs

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportBucketInfo

func ExportBucketInfo(ctx context.Context, client *BucketClient, projects []string, cachedBuckets *BucketCache, m *Metrics) error

ExportBucketInfo will list all buckets for a given project and export the data as a prometheus metric. If there are any errors listing buckets, it will export the cached buckets for the project.

func ExportGCPCostData

func ExportGCPCostData(ctx context.Context, client *billingv1.CloudCatalogClient, serviceName string, m *Metrics) float64

ExportGCPCostData will collect all the pricing information for the passed in serviceName and export cost related metrics for each sku

func ExportRegionalDiscounts

func ExportRegionalDiscounts(ctx context.Context, client RegionsClient, projectID string, discount int, m *Metrics) error

func ExporterOperationsDiscounts

func ExporterOperationsDiscounts(m *Metrics)

func OpClassFromSkuDescription

func OpClassFromSkuDescription(s string) string

OpClassFromSkuDescription normalizes sku description to one of the following: - If the opsclass contains Class A, it's "class-a" - If the opsclass contains Class B, it's "class-b" - Otherwise, return the original opsclass

func RegionNameSameAsStackdriver

func RegionNameSameAsStackdriver(s string) string

RegionNameSameAsStackdriver will normalize region collectorName to be the same as what Stackdriver uses. Google Cost API returns region names exactly the same how they are referred in StackDriver metrics except one case: For Europe multi-region: API returns "europe", while Stackdriver uses "eu" label value.

func StorageClassFromSkuDescription

func StorageClassFromSkuDescription(s string, region string) string

StorageClassFromSkuDescription normalize sku description to match the output from stackdriver exporter

Types

type BucketCache

type BucketCache struct {
	Buckets map[string][]*storage.BucketAttrs
	// contains filtered or unexported fields
}

func NewBucketCache

func NewBucketCache() *BucketCache

func (*BucketCache) Get

func (c *BucketCache) Get(project string) []*storage.BucketAttrs

func (*BucketCache) Set

func (c *BucketCache) Set(project string, buckets []*storage.BucketAttrs)

type BucketClient

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

func NewBucketClient

func NewBucketClient(client StorageClientInterface) *BucketClient

func (*BucketClient) List

func (bc *BucketClient) List(ctx context.Context, project string) ([]*storage.BucketAttrs, error)

TODO: Return an interface of the storage.BucketAttrs

type Collector

type Collector struct {
	ProjectID string
	Projects  []string

	CachedBuckets *BucketCache
	// contains filtered or unexported fields
}

func New

func New(config *Config, cloudCatalogClient *billingv1.CloudCatalogClient, regionsClient RegionsClient, storageClient StorageClientInterface) (*Collector, error)

func (*Collector) CheckReadiness added in v0.3.0

func (c *Collector) CheckReadiness() bool

func (*Collector) Collect

func (c *Collector) Collect(ch chan<- prometheus.Metric) error

func (*Collector) CollectMetrics

func (c *Collector) CollectMetrics(ch chan<- prometheus.Metric) float64

CollectMetrics is by `c.Collect` and can likely be refactored directly into `c.Collect`

func (*Collector) Describe

func (c *Collector) Describe(ch chan<- *prometheus.Desc) error

func (*Collector) Name

func (c *Collector) Name() string

func (*Collector) Register

func (c *Collector) Register(registry provider.Registry) error

Register is called when the collector is created and is responsible for registering the metrics with the registry

type Config

type Config struct {
	ProjectId       string
	Projects        string
	DefaultDiscount int
	ScrapeInterval  time.Duration
}

type Metrics

type Metrics struct {
	StorageGauge            *prometheus.GaugeVec
	StorageDiscountGauge    *prometheus.GaugeVec
	OperationsGauge         *prometheus.GaugeVec
	OperationsDiscountGauge *prometheus.GaugeVec
	BucketInfo              *prometheus.GaugeVec
	BucketListHistogram     *prometheus.HistogramVec
	BucketListStatus        *prometheus.CounterVec
	NextScrapeGauge         prometheus.Gauge
}

func NewMetrics

func NewMetrics() *Metrics

type RegionsClient

type RegionsClient interface {
	List(ctx context.Context, req *computepb.ListRegionsRequest, opts ...gax.CallOption) *compute.RegionIterator
}

type StorageClientInterface

type StorageClientInterface interface {
	Buckets(ctx context.Context, projectID string) *storage.BucketIterator
}

Jump to

Keyboard shortcuts

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