test(aws/recs): cover SizeInMiB-nil + assert no NextPage on canceled ctx; drop em-dashes#842
test(aws/recs): cover SizeInMiB-nil + assert no NextPage on canceled ctx; drop em-dashes#842cristim wants to merge 4 commits into
Conversation
📝 WalkthroughWalkthrough
ChangesPointer-based recommendation parameter update
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
Coordination note: PR #816 (closes #218) implements the same DescribeInstanceTypes VCPU/MemoryGB population path independently. The two PRs are effectively duplicates. Whichever lands first should be merged; the other should be closed (or rebased to a tightening-only delta). Both currently open; flagging so the merger doesn't accidentally land both. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
Extract ec2Tenancy, ec2Scope, and enrichEC2Compute helpers from parseEC2Details to bring its cyclomatic complexity from 14 down to 6, passing the gocyclo <=10 gate.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
Rate Limit Exceeded
|
Extract ec2Tenancy, ec2Scope, and enrichEC2Compute helpers from parseEC2Details to bring its cyclomatic complexity from 14 down to 6, passing the gocyclo <=10 gate.
|
pr-iterate: rebased on feat/multicloud-web-frontend (resolved conflict in providers/aws/recommendations/parser_services.go and parser_services_test.go - merged the base branch ResourceType guard with the PR context.Context threading). PR is otherwise progressing (mergeStateStatus will refresh). Re-invoke |
|
Verification note: this PR (closes #99) and PR #816 (closes #218) both populate ComputeDetails VCPU/MemoryGB via EC2 DescribeInstanceTypes on the same base branch. They are duplicate solutions and will conflict. Recommend merging ONE and closing the other's issue as a duplicate. The code here is correct on its own merits. Leaving the pick for a human. |
Extract ec2Tenancy, ec2Scope, and enrichEC2Compute helpers from parseEC2Details to bring its cyclomatic complexity from 14 down to 6, passing the gocyclo <=10 gate.
a6ab935 to
867b4c6
Compare
|
pr-iterate: rebased on Resolution detail (semantic, not mechanical): the base branch had independently extracted the EC2 helpers this PR added, but under the fail-loud names
Verification: Note (unchanged, for the human): this PR (#99) and PR #816 (#218) are duplicate solutions for the same ComputeDetails VCPU/MemoryGB enrichment. Merge one and close the other's issue as a duplicate. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
@coderabbitai full review |
|
Repurpose summary: This branch has been reset to
Build: @coderabbitai full review |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
gh pr view 842 --repo LeanerCloud/CUDly --json title,body,headRefName,baseRefName,state,mergeable,files
echo "---DIFF---"
gh pr diff 842 --repo LeanerCloud/CUDlyLength of output: 5310
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@providers/gcp/recommendations.go`:
- Around line 97-98: Add a nil guard at the beginning of the GetRecommendations
method in RecommendationsClientAdapter before the line that dereferences the
pointer parameter p (where params := *p occurs). Check if p is nil and return an
appropriate error instead of proceeding with the dereference to prevent a
potential nil-pointer panic at runtime.
In `@providers/gcp/services/cloudsql/client.go`:
- Around line 142-143: The GetRecommendations method in CloudSQLClient
dereferences the pointer parameter p without first checking if it is nil, which
will cause a panic if a caller passes nil. Add a nil guard check at the
beginning of the GetRecommendations method that validates p is not nil, and
return an appropriate error (such as "recommendation params cannot be nil") if
the check fails before attempting to dereference p with params := *p.
In `@providers/gcp/services/cloudstorage/client.go`:
- Around line 162-163: The GetRecommendations method in CloudStorageClient
dereferences the pointer parameter p without first checking if it is nil, which
will cause a panic if nil is passed. Add a nil guard at the beginning of the
GetRecommendations method to check if p is nil, and return an appropriate error
value before attempting to dereference it with the params := *p statement.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bdfd6c52-bd98-4c41-9b00-87c02b7dabec
📒 Files selected for processing (56)
cmd/multi_service_coverage_test.gocmd/multi_service_helpers.gocmd/multi_service_test.gocmd/multi_service_test_common_test.gointernal/purchase/mocks_test.gointernal/scheduler/scheduler.gointernal/scheduler/scheduler_test.gopkg/provider/interface.goproviders/aws/recommendations/client.goproviders/aws/recommendations/client_test.goproviders/aws/recommendations/sku.goproviders/aws/recommendations/sku_test.goproviders/aws/service_client.goproviders/aws/service_client_test.goproviders/aws/services/ec2/client.goproviders/aws/services/ec2/client_test.goproviders/aws/services/elasticache/client.goproviders/aws/services/elasticache/client_test.goproviders/aws/services/memorydb/client.goproviders/aws/services/memorydb/client_test.goproviders/aws/services/opensearch/client.goproviders/aws/services/opensearch/client_test.goproviders/aws/services/rds/client.goproviders/aws/services/rds/client_test.goproviders/aws/services/redshift/client.goproviders/aws/services/redshift/client_test.goproviders/aws/services/savingsplans/client.goproviders/aws/services/savingsplans/client_test.goproviders/azure/recommendations.goproviders/azure/recommendations_test.goproviders/azure/services/cache/client.goproviders/azure/services/cache/client_test.goproviders/azure/services/compute/client.goproviders/azure/services/compute/client_test.goproviders/azure/services/cosmosdb/client.goproviders/azure/services/cosmosdb/client_test.goproviders/azure/services/database/client.goproviders/azure/services/database/client_test.goproviders/azure/services/managedredis/client.goproviders/azure/services/managedredis/client_test.goproviders/azure/services/savingsplans/client.goproviders/azure/services/savingsplans/client_test.goproviders/azure/services/search/client.goproviders/azure/services/search/client_test.goproviders/azure/services/synapse/client.goproviders/azure/services/synapse/client_test.goproviders/gcp/recommendations.goproviders/gcp/recommendations_test.goproviders/gcp/services/cloudsql/client.goproviders/gcp/services/cloudsql/client_test.goproviders/gcp/services/cloudstorage/client.goproviders/gcp/services/cloudstorage/client_test.goproviders/gcp/services/computeengine/client.goproviders/gcp/services/computeengine/client_test.goproviders/gcp/services/memorystore/client.goproviders/gcp/services/memorystore/client_test.go
|
@coderabbitai The three GCP nil-pointer-dereference findings are false positives. Evidence:
Verification: No code change is warranted. Requesting re-review of those three threads. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Tip For best results, initiate chat on the files or code changes.
No code change is needed there; please consider those three threads withdrawn. (・x・) ✏️ Learnings added
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
…ctx; drop em-dashes The ComputeDetails VCPU/MemoryGB implementation landed via the merged duplicate PR #816 (closes #218). This commit grafts the two test-coverage gaps that #816 missed, plus a comment cleanup: - TestExtractInstanceTypeSKUEntry: add sub-case "MemoryInfo present but SizeInMiB nil" -- expects VCPU populated, MemGB 0.0. - TestFetchInstanceTypeCatalogue_ContextCanceled: assert that pager.callCount remains 0 after a pre-canceled ctx returns nil (the stub already tracks the count via atomic; this makes the no-NextPage contract explicit). - Replace em-dashes (U+2014) with "--" in sku.go warn messages and in the client.go instanceTypeLookup comment. parser_services.go em-dashes left for a follow-up (out of scope here). Closes #99
Fix all lint issues in client.go, sku.go, and sku_test.go per the 3b step in the review brief: - misspell: catalogue -> catalog in comments and string literals (function identifiers fetchInstanceTypeCatalogue/skuCatalog untouched) - misspell: Behaviour -> Behavior in GetAllRecommendations comment - godot: add trailing periods to CostExplorerAPI, Client, NewClient, NewClientWithAPI, and GetRecommendations doc comments - govet/fieldalignment: reorder skuCatalog fields (m before once: 24 -> 20 bytes) and serviceResult fields (err before name before recs: 56 -> 40 bytes); Client and serviceResult updated accordingly - gocritic/rangeValCopy: populateInstanceTypeSKUMap now iterates by index to avoid copying the large InstanceTypeInfo struct; change extractInstanceTypeSKUEntry signature to *ec2types.InstanceTypeInfo - gocritic/hugeParam: suppress via //nolint:gocritic on NewClient (aws.Config 696 bytes, SDK value-type convention) and GetRecommendations (RecommendationParams 200 bytes, public API) - gocritic/rangeValCopy: mergeServiceResults range loops converted to index-based to avoid copying the 56-byte serviceResult struct
…ove gocritic nolints Remove two gocritic hugeParam nolints from providers/aws/recommendations/client.go by changing both hotspot parameters to pointer types: - NewClient(cfg *aws.Config): cascaded to all 2 callers in aws/service_client.go and aws/recommendations/client_test.go - GetRecommendations(ctx, params *common.RecommendationParams): cascaded through the ServiceClient and RecommendationsClient interfaces in pkg/provider/interface.go to all 25+ implementations across AWS, Azure, and GCP modules, plus all mock/test callers in cmd/ and internal/ No behaviour change; internal helpers that receive a value copy dereference the pointer at the function boundary (params := *p).
Pointer-izing RecommendationParams (prev commit) exposed five GCP GetRecommendations implementations that dereference p without a nil check, which would panic if a caller passes nil. Add a nil guard at the function boundary in all five GCP service clients: RecommendationsClientAdapter, CloudSQLClient, CloudStorageClient, ComputeEngineClient, and MemorystoreClient. Extract resolveRecommenderClient helpers from the four leaf clients to keep GetRecommendations cyclomatic complexity at 10 (pre-commit limit) after the nil-guard branch is added.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
providers/gcp/services/computeengine/client.go (1)
216-227: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoffDuplicated
resolveRecommenderClientacross service clients.Identical logic (including doc comment) is also added in
providers/gcp/services/memorystore/client.go(lines 154-165), and likely in the cloudsql/cloudstorage clients per this cohort's file list. Consider extracting a shared helper (e.g., accepting the injected client, a constructor func, and clientOpts) into a common internal package to avoid maintaining four copies of the same resolution logic.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@providers/gcp/services/computeengine/client.go` around lines 216 - 227, The resolveRecommenderClient logic is duplicated across multiple GCP service clients, including ComputeEngineClient and the same pattern in MemorystoreClient, so extract the shared resolution flow into a common internal helper. Move the injected-client check and constructor fallback into a reusable function that accepts the existing client field, a constructor func, and clientOpts, then have each service client call that helper from its resolveRecommenderClient method.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@providers/gcp/services/computeengine/client.go`:
- Around line 216-227: The resolveRecommenderClient logic is duplicated across
multiple GCP service clients, including ComputeEngineClient and the same pattern
in MemorystoreClient, so extract the shared resolution flow into a common
internal helper. Move the injected-client check and constructor fallback into a
reusable function that accepts the existing client field, a constructor func,
and clientOpts, then have each service client call that helper from its
resolveRecommenderClient method.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 34fc773f-03e9-417d-976c-497dc8db4c40
📒 Files selected for processing (56)
cmd/multi_service_coverage_test.gocmd/multi_service_helpers.gocmd/multi_service_test.gocmd/multi_service_test_common_test.gointernal/purchase/mocks_test.gointernal/scheduler/scheduler.gointernal/scheduler/scheduler_test.gopkg/provider/interface.goproviders/aws/recommendations/client.goproviders/aws/recommendations/client_test.goproviders/aws/recommendations/sku.goproviders/aws/recommendations/sku_test.goproviders/aws/service_client.goproviders/aws/service_client_test.goproviders/aws/services/ec2/client.goproviders/aws/services/ec2/client_test.goproviders/aws/services/elasticache/client.goproviders/aws/services/elasticache/client_test.goproviders/aws/services/memorydb/client.goproviders/aws/services/memorydb/client_test.goproviders/aws/services/opensearch/client.goproviders/aws/services/opensearch/client_test.goproviders/aws/services/rds/client.goproviders/aws/services/rds/client_test.goproviders/aws/services/redshift/client.goproviders/aws/services/redshift/client_test.goproviders/aws/services/savingsplans/client.goproviders/aws/services/savingsplans/client_test.goproviders/azure/recommendations.goproviders/azure/recommendations_test.goproviders/azure/services/cache/client.goproviders/azure/services/cache/client_test.goproviders/azure/services/compute/client.goproviders/azure/services/compute/client_test.goproviders/azure/services/cosmosdb/client.goproviders/azure/services/cosmosdb/client_test.goproviders/azure/services/database/client.goproviders/azure/services/database/client_test.goproviders/azure/services/managedredis/client.goproviders/azure/services/managedredis/client_test.goproviders/azure/services/savingsplans/client.goproviders/azure/services/savingsplans/client_test.goproviders/azure/services/search/client.goproviders/azure/services/search/client_test.goproviders/azure/services/synapse/client.goproviders/azure/services/synapse/client_test.goproviders/gcp/recommendations.goproviders/gcp/recommendations_test.goproviders/gcp/services/cloudsql/client.goproviders/gcp/services/cloudsql/client_test.goproviders/gcp/services/cloudstorage/client.goproviders/gcp/services/cloudstorage/client_test.goproviders/gcp/services/computeengine/client.goproviders/gcp/services/computeengine/client_test.goproviders/gcp/services/memorystore/client.goproviders/gcp/services/memorystore/client_test.go
✅ Files skipped from review due to trivial changes (4)
- providers/aws/services/opensearch/client_test.go
- providers/gcp/services/cloudstorage/client_test.go
- providers/gcp/services/computeengine/client_test.go
- providers/azure/services/cache/client_test.go
🚧 Files skipped from review as they are similar to previous changes (50)
- providers/aws/services/elasticache/client_test.go
- providers/azure/recommendations_test.go
- providers/azure/services/search/client.go
- internal/scheduler/scheduler_test.go
- providers/aws/services/savingsplans/client_test.go
- providers/azure/services/managedredis/client.go
- pkg/provider/interface.go
- providers/azure/services/compute/client_test.go
- providers/aws/services/redshift/client.go
- providers/azure/services/savingsplans/client.go
- providers/aws/services/ec2/client.go
- cmd/multi_service_test_common_test.go
- providers/aws/services/redshift/client_test.go
- providers/aws/services/rds/client_test.go
- providers/azure/services/savingsplans/client_test.go
- providers/azure/services/search/client_test.go
- internal/scheduler/scheduler.go
- providers/azure/services/synapse/client_test.go
- providers/azure/services/database/client_test.go
- providers/aws/services/memorydb/client.go
- providers/azure/services/cosmosdb/client_test.go
- providers/azure/services/database/client.go
- providers/gcp/recommendations_test.go
- providers/aws/services/savingsplans/client.go
- providers/gcp/services/memorystore/client_test.go
- cmd/multi_service_coverage_test.go
- providers/aws/services/ec2/client_test.go
- providers/aws/services/rds/client.go
- providers/aws/services/memorydb/client_test.go
- providers/azure/services/synapse/client.go
- providers/aws/recommendations/client_test.go
- providers/aws/services/opensearch/client.go
- providers/azure/recommendations.go
- providers/azure/services/compute/client.go
- providers/aws/services/elasticache/client.go
- providers/aws/service_client.go
- providers/aws/service_client_test.go
- providers/azure/services/cosmosdb/client.go
- providers/azure/services/cache/client.go
- providers/gcp/services/cloudsql/client.go
- providers/azure/services/managedredis/client_test.go
- cmd/multi_service_helpers.go
- cmd/multi_service_test.go
- providers/gcp/recommendations.go
- providers/gcp/services/cloudstorage/client.go
- providers/gcp/services/cloudsql/client_test.go
- internal/purchase/mocks_test.go
- providers/aws/recommendations/sku_test.go
- providers/aws/recommendations/sku.go
- providers/aws/recommendations/client.go
Summary
The ComputeDetails VCPU/MemoryGB implementation (issue #99) landed via the merged duplicate PR #816
(
feat(aws/recs): populate ComputeDetails.VCPU/MemoryGB via DescribeInstanceTypes, closes #218).This PR is repurposed to carry the remaining test-coverage gaps that #816 missed, plus a comment
cleanup -- nothing net-new in production code.
What is grafted on top of the already-merged #816 implementation:
TestExtractInstanceTypeSKUEntry: new sub-case "MemoryInfo present but SizeInMiB nil" -- verifiesVCPU is populated (8) while MemGB stays 0.0 when the API returns a MemoryInfo struct but omits
the SizeInMiB pointer.
TestFetchInstanceTypeCatalogue_ContextCanceled: after the pre-canceled ctx returns nil, alsoassert
pager.callCount == 0-- the stub already tracks this atomically; the assertion makesthe no-NextPage-on-canceled-ctx contract explicit and regression-tested.
Em-dash (U+2014) cleanup: replaced
--in two Warnf messages insku.goand in theinstanceTypeLookupcomment inclient.go. Em-dashes inparser_services.goare left for afollow-up (out of scope here).
What was intentionally dropped from the original #842 branch (cosmetic churn not worth the diff
noise on top of the already-clean #816 implementation):
assert.InDelta->assert.Equalswaps,requiremessage removals, struct-literal refactor ofextractInstanceTypeSKUEntry, pagerrenaming.
Closes #99
Summary by CodeRabbit