Skip to content

fix(gcp): skip a recommendation with a bad amount and cap string VCPU amounts - #255

Merged
cristim merged 2 commits into
mainfrom
fix/gcp-bad-amount-skip-with-warning
Oct 6, 2026
Merged

cristim merged 2 commits into
mainfrom
fix/gcp-bad-amount-skip-with-warning

Conversation

@cristim

@cristim cristim commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Closes #237

  • A malformed or oversized VCPU/MEMORY amount on one row is skipped with a log warning; the other rows are returned. Structural payload errors (unknown resource type, missing VCPU, duplicate amounts) still abort the batch; the existing SDK test pins that and fix(gcp): keep CPU and memory recommendation amounts on the same resource #165 covers that area.
  • recommendationAmount caps string amounts at 2^53-1 for VCPU too (previously only MEMORY, VCPU was bounded by MaxInt). The MaxInt guard stays for 32-bit ints.
  • Tests: one bad row among good rows for malformed/oversized VCPU and MEMORY (fail before, pass after); VCPU table updated for the new cap.

Gates (providers/gcp): go test -race -short -mod=readonly ./... pass, gocyclo clean, go mod tidy -diff clean. golangci-lint panics locally (needs go1.27, built with go1.26).

Summary by CodeRabbit

  • Bug Fixes
    • Recommendations with malformed, non-positive, fractional, or out-of-range CPU and memory amounts are now skipped, allowing other valid recommendations to be returned.
    • Structural issues that prevent a recommendation from being converted still cause the request to fail rather than returning partial results.
    • Large resource amounts that cannot be represented exactly are rejected to avoid inaccurate values.

… amounts

A malformed VCPU or MEMORY amount on one Recommender row aborted GetRecommendations and dropped every other row. Such a row is now skipped with a warning, like the AWS and Azure paths. Structural payload errors (unknown resource type, missing VCPU, duplicate amounts) still abort.

recommendationAmount now caps string amounts at 2^53-1 for VCPU as well as MEMORY, so the MEMORY-only check is removed.

Closes #237
@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
@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: ab23cc51-eed9-4bb9-ac83-8654a6f67914
📥 Commits

Reviewing files that changed from the base of the PR and between d881edf and 97460a1.

📒 Files selected for processing (2)
  • providers/gcp/services/computeengine/client.go
  • providers/gcp/services/computeengine/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

GCP recommendation amount parsing now rejects malformed and oversized values. GetRecommendations logs and skips recommendations with amount errors while retaining valid rows. Structural conversion errors still abort the call.

Changes

GCP recommendation amounts

Layer / File(s) Summary
Validate recommendation amounts
providers/gcp/services/computeengine/client.go, providers/gcp/services/computeengine/client_test.go
The shared parser marks invalid amounts with errBadAmount and rejects string amounts above 2^53-1. Memory validation uses the shared parser. Tests check the VCPU boundary at 2^53-1.
Skip recommendations with bad amounts
providers/gcp/services/computeengine/client.go, providers/gcp/services/computeengine/client_test.go
GetRecommendations logs and skips recommendations whose conversion returns errBadAmount. Tests verify that valid rows remain and structural conversion errors still return an error with no recommendations.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant GetRecommendations
  participant convertOrSkipBadAmount
  participant convertGCPRecommendation
  participant recommendationAmount
  participant logger
  GetRecommendations->>convertOrSkipBadAmount: pass recommendation
  convertOrSkipBadAmount->>convertGCPRecommendation: convert recommendation
  convertGCPRecommendation->>recommendationAmount: parse resource amount
  recommendationAmount-->>convertGCPRecommendation: amount or errBadAmount
  convertGCPRecommendation-->>convertOrSkipBadAmount: conversion result or error
  convertOrSkipBadAmount->>logger: log and skip errBadAmount
  convertOrSkipBadAmount-->>GetRecommendations: return result or propagate other error
Loading

Merge Risk: ⚪ Minimal · up to 97460

No actionable merge-blocking risk is identified; the change is mergeable after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the GCP recommendation fix: skip rows with invalid amounts and cap string VCPU amounts.
Linked Issues check ✅ Passed Issue [#237] requires row-level handling for malformed or oversized VCPU and MEMORY amounts, a 2^53−1 cap for string VCPU amounts, and tests for both behaviors. The PR summary reports that GetRecommen…
Out of Scope Changes check ✅ Passed The reported changes are limited to recommendation amount handling and related tests. The structural-error tests support [#237] by checking that the new row-level skip does not suppress batch-aborting…
  • 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.

…batch

Wrap the ParseInt cause with a second %w for errorlint.
@cristim
cristim merged commit e04c227 into main Oct 6, 2026
15 checks passed
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.

fix(gcp): unify bad-amount handling into skip-with-warning and cap VCPU amounts

1 participant