Skip to content

fix(gcp): match SKUs by whole tier token and explicit region - #244

Merged
cristim merged 2 commits into
mainfrom
fix/gcp-sku-matching-97
Oct 6, 2026
Merged

cristim merged 2 commits into
mainfrom
fix/gcp-sku-matching-97

Conversation

@cristim

@cristim cristim commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

What

Cloud SQL, Memorystore and Compute Engine SKU matching now (1) requires the tier or machine type to appear as a whole token in the description and (2) applies a SKU to a region only when that region is listed in ServiceRegions, or when the list is empty and GeoTaxonomy.Type is GLOBAL. Both rules live in the new providers/gcp/internal/skumatch.

Why

A SKU with nil ServiceRegions priced every region, and the tier test was a plain substring (db-n1-standard-1 matched db-n1-standard-16, STANDARD matched STANDARD_HA).

The catalog docs say an empty region list means global: "This field is empty for Global SKUs since they are associated with all Google Cloud regions" (cloud.google.com/billing/v1/how-tos/catalog-api) and "Empty for Global skus, which are associated with all Google Cloud regions" (services.skus.list reference). The SDK's GeoTaxonomy.Type documents GLOBAL, REGIONAL and MULTI_REGIONAL (google.golang.org/api v0.274.0, cloudbilling/v1/cloudbilling-gen.go:611-624). So an empty list is trusted only with a GLOBAL taxonomy. Empty regions with REGIONAL, MULTI_REGIONAL, unspecified or a missing taxonomy is ambiguous and no longer matches.

Behaviour change

Callers get no match where a region-less SKU of unknown scope used to match every region.

Limits

Real catalog descriptions do not contain tiers or machine types (for example "Cloud SQL for MySQL: Regional - 1 vCPU + 3.75GB RAM in Americas", see cloud.google.com/skus/sku-groups/cloud-sql-cud-eligible-skus). Real lookups are therefore unchanged by this PR and still return no pricing for the token-matched services; the whole-token matching is correct on synthetic strings only. This PR does not claim a price correction. The real-data matching problem is tracked separately. Cloud Storage is untouched because #205 edits that file.

Verification

  • Tests cover nil, empty and named regions across GLOBAL, REGIONAL, MULTI_REGIONAL, unspecified and missing taxonomy, plus decoy descriptions.
  • Mutations of InRegion (inverted GLOBAL check; REGIONAL treated as global) each fail the skumatch tests.
  • go vet ./..., go test ./..., golangci-lint run ./... in providers/gcp all exit 0.

Refs #97

A SKU with no ServiceRegions priced every region and the tier test was a plain substring, so db-n1-standard-1 matched db-n1-standard-16 and STANDARD matched STANDARD_HA. Cloud SQL, Memorystore and Compute Engine now share skumatch: the tier must appear as a whole token and the region must be listed explicitly. Cloud Storage is left for a follow-up because it is being edited elsewhere.
@cristim cristim added priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged urgency/this-quarter Within the quarter impact/few Limited audience effort/s Hours type/bug Defect labels Oct 6, 2026
@cristim

cristim commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-go/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 95514c40-aeb9-4159-be75-1824644848ae
📥 Commits

Reviewing files that changed from the base of the PR and between be54dfa and cf4874b.

📒 Files selected for processing (9)
  • providers/gcp/internal/skumatch/skumatch.go
  • providers/gcp/internal/skumatch/skumatch_test.go
  • providers/gcp/services/cloudsql/client.go
  • providers/gcp/services/cloudsql/client_test.go
  • providers/gcp/services/computeengine/client.go
  • providers/gcp/services/computeengine/client_test.go
  • providers/gcp/services/memorystore/client.go
  • providers/gcp/services/memorystore/client_coverage_test.go
  • providers/gcp/services/memorystore/client_test.go

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.


📝 Walkthrough

Walkthrough

The change adds shared helpers for matching SKU description tokens and service regions. Cloud SQL, Compute Engine, and Memorystore use these helpers. Tests cover token boundaries, region matching, and Cloud SQL pricing extraction.

Changes

GCP SKU Matching

Layer / File(s) Summary
Shared SKU matching helpers
providers/gcp/internal/skumatch/*
Adds case-insensitive service-region matching and token matching that rejects partial matches. Tests cover exact and case-insensitive matches, token boundaries, empty tokens, and absent regions.
Service SKU matching
providers/gcp/services/cloudsql/*, providers/gcp/services/computeengine/*, providers/gcp/services/memorystore/*
The three services use the shared matching helpers. Tests cover regionless SKUs and tier-prefix decoys. Cloud SQL pricing extraction is tested with exact-tier, larger-tier, and regionless SKUs.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to cf487

This change makes GCP SKU matching stricter, so tiers and regions are matched exactly. No actionable merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: matching SKUs by whole tier tokens and explicitly listed regions.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

…gnostic

The catalog leaves the region list empty for global SKUs, so an empty list with GeoTaxonomy.Type GLOBAL applies in every region. Empty regions with any other or a missing taxonomy still match nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/s Hours impact/few Limited audience priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged type/bug Defect urgency/this-quarter Within the quarter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant