Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ linters:
pattern: (?i)passwd|pass|password|pwd|secret|token
govet:
enable-all: true
disable:
# fieldalignment: many production structs have alignment violations that
# pre-date this PR; fixing them is a separate concern. Suppress globally
# rather than per-struct since golangci-lint v2.10.x (CI) doesn't treat
# severity:warning as a non-fatal exit, unlike v2.11+.
- fieldalignment
misspell:
locale: US
revive:
Expand Down Expand Up @@ -93,12 +87,17 @@ linters:
# unusedwrite: test fixture struct fields may be set for documentation
# completeness even when only a subset of fields is read by a given subtest.
# Scoped to test files so production unusedwrite bugs remain visible.
# Note: fieldalignment is disabled globally in govet.disable (many
# pre-existing production violations; separate cleanup PR needed).
- linters:
- govet
text: "unusedwrite"
path: _test\.go
# fieldalignment: test-table memory layout is irrelevant, and reordering
# positional table literals risks silent misassignment. Production code
# stays checked.
- linters:
- govet
text: "fieldalignment:"
path: _test\.go
- linters:
- all
path: .*_gen\.go
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/internal/billingguard/billingguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const marker = "failed to create billing service"

type watcher struct {
next io.Writer
mu sync.Mutex
hits []string
mu sync.Mutex
}

func (w *watcher) Write(p []byte) (int, error) {
Expand Down
4 changes: 2 additions & 2 deletions providers/gcp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ func (r *realResourceManagerService) ListProjects(ctx context.Context) ([]*cloud

// Provider implements the provider.Provider interface for Google Cloud Platform.
type Provider struct {
projectID string
clientOpts []option.ClientOption
projectsClient ProjectsClient
regionsClient RegionsClient
resourceManagerService ResourceManagerService
projectID string
clientOpts []option.ClientOption
}

// NewProvider creates a new GCP provider.
Expand Down
13 changes: 10 additions & 3 deletions providers/gcp/recommendations.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,29 @@ func gcpRegionConcurrency() int {
// only an explicit request reaches those clients, which return
// common.ErrCommitmentPurchaseNotSupported.
type regionResult struct {
// attempted counts the service calls launched for this region (after the
// params service filter), failed counts how many of those errored, and
// lastErr keeps one representative error. mergeRegionResults aggregates
// these across regions for the all-attempted-failed guard (COR-03).
lastErr error

compute []common.Recommendation

// attempted counts the service calls launched for this region (after the
// params service filter), failed counts how many of those errored, and
// lastErr keeps one representative error. mergeRegionResults aggregates
// these across regions for the all-attempted-failed guard (COR-03).
attempted int
failed int
lastErr error
}

// RecommendationsClientAdapter aggregates GCP CUD and commitment recommendations across all services.
type RecommendationsClientAdapter struct {
projectID string
clientOpts []option.ClientOption
// regionsFn replaces the live region lookup; tests only.
regionsFn func(context.Context) ([]string, error)

projectID string
clientOpts []option.ClientOption
}

// GetRecommendations retrieves all GCP commitment recommendations across all
Expand Down
4 changes: 2 additions & 2 deletions providers/gcp/services/cloudsql/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type RecommenderClient interface {
}

// Client handles GCP Cloud SQL commitments.
type Client struct {
type Client struct { //nolint:govet // fieldalignment: file owned by open PR #471
skuMu sync.Mutex
skuCache *cloudbilling.ListSkusResponse
ctx context.Context
Expand Down Expand Up @@ -258,7 +258,7 @@ func (c *Client) GetValidResourceTypes(ctx context.Context) ([]string, error) {
}

// SQLPricing contains pricing information for Cloud SQL.
type SQLPricing struct {
type SQLPricing struct { //nolint:govet // fieldalignment: file owned by open PR #471
HourlyRate float64
CommitmentPrice float64
OnDemandPrice float64
Expand Down
4 changes: 2 additions & 2 deletions providers/gcp/services/cloudstorage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type BillingService interface {
}

// Client handles GCP Cloud Storage commitments.
type Client struct {
type Client struct { //nolint:govet // fieldalignment: file owned by open PR #471
ctx context.Context
projectID string
region string
Expand Down Expand Up @@ -219,7 +219,7 @@ func (c *Client) GetValidResourceTypes(ctx context.Context) ([]string, error) {
}

// StoragePricing contains pricing information for Cloud Storage.
type StoragePricing struct {
type StoragePricing struct { //nolint:govet // fieldalignment: file owned by open PR #471
HourlyRate float64
CommitmentPrice float64
OnDemandPrice float64
Expand Down
11 changes: 5 additions & 6 deletions providers/gcp/services/computeengine/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,15 @@ type RecommenderClient interface {

// Client handles GCP Compute Engine Committed Use Discounts.
type Client struct {
projectID string
region string
clientOpts []option.ClientOption
commitmentsService CommitmentsService
machineTypesService MachineTypesService
billingService BillingService
recommenderClient RecommenderClient

skuMu sync.Mutex
skuCache []*cloudbilling.Sku
projectID string
region string
clientOpts []option.ClientOption
skuCache []*cloudbilling.Sku
skuMu sync.Mutex
}

// NewClient creates a new GCP Compute Engine client.
Expand Down
16 changes: 10 additions & 6 deletions providers/gcp/services/computeengine/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ const (

// ComputePricing is the price of a commitment's resources, for one term.
type ComputePricing struct {
Currency string

// HourlyRate is the committed price per hour for the whole resource set.
HourlyRate float64

// CommitmentPrice is the committed price over the whole term.
CommitmentPrice float64

// OnDemandPrice is the on-demand price of the same resources over the term.
OnDemandPrice float64
Currency string
OnDemandPrice float64

SavingsPercentage float64
}

Expand Down Expand Up @@ -97,8 +101,8 @@ type skuRates struct {
}

type familyRates struct {
onDemand, commitment skuRates
currency string
onDemand, commitment skuRates
}

// onDemandDescription matches e.g. "N2 Instance Core running in Americas",
Expand Down Expand Up @@ -127,11 +131,11 @@ func legacyCommitmentDescription(label string) *regexp.Regexp {

// rateMatcher recognizes the catalog SKUs of one family, region and term.
type rateMatcher struct {
region string
onDemand *regexp.Regexp
commitments []*regexp.Regexp
region string
wantTerm string
wantUsage string
commitments []*regexp.Regexp
}

func newRateMatcher(labels skuFamilyLabels, region string, termYears int) rateMatcher {
Expand Down Expand Up @@ -190,8 +194,8 @@ func (r *rateSlot) set(price float64, sku *cloudbilling.Sku) error {

// rateCollector accumulates the four prices wanted from matched SKUs.
type rateCollector struct {
odCPU, odRAM, cCPU, cRAM rateSlot
currency string
odCPU, odRAM, cCPU, cRAM rateSlot
}

func (c *rateCollector) add(sku *cloudbilling.Sku, isCommit, isRAM bool) error {
Expand Down
4 changes: 2 additions & 2 deletions providers/gcp/services/memorystore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type RecommenderClient interface {
}

// Client handles GCP Memorystore (Redis) commitments.
type Client struct {
type Client struct { //nolint:govet // fieldalignment: file owned by open PR #471
skuMu sync.Mutex
skuCache *cloudbilling.ListSkusResponse
ctx context.Context
Expand Down Expand Up @@ -221,7 +221,7 @@ func (c *Client) GetValidResourceTypes(ctx context.Context) ([]string, error) {
}

// RedisPricing contains pricing information for Memorystore Redis.
type RedisPricing struct {
type RedisPricing struct { //nolint:govet // fieldalignment: file owned by open PR #471
HourlyRate float64
CommitmentPrice float64
OnDemandPrice float64
Expand Down
Loading