Skip to content

fix(azure/gcp/aws): ctx.Err guards + page cap on 22 pagination loops (closes #691) - #800

Merged
cristim merged 3 commits into
feat/multicloud-web-frontendfrom
fix/691-wave2
May 31, 2026
Merged

cristim merged 3 commits into
feat/multicloud-web-frontendfrom
fix/691-wave2

Conversation

@cristim

@cristim cristim commented May 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add ctx.Err() early-return guards at the top of every pagination loop (Azure for pager.More(), GCP for { it.Next() }, AWS for { token }) so a cancelled or deadline-expired context terminates immediately with an error instead of silently producing a partial result set.
  • Add a maxPages budget cap per loop with a log warning or returned error when the limit is hit, preventing infinite loops against stalled or unexpectedly deep AWS/Azure/GCP APIs.
  • Fix three collect* helper functions in Azure cache and cosmosdb that previously returned map[string]bool without an error channel, causing context cancellations to silently produce partial SKU sets. Signatures changed to (map[string]bool, error) and callers updated.

Total: 14 Azure loops + 6 GCP loops + 2 AWS loops = 22 loops covered.

Test plan

  • go build ./... clean in providers/azure, providers/gcp, providers/aws
  • go test ./... green in all three provider modules (85+ tests passing)
  • Regression test: Azure cache GetValidResourceTypes ctx-cancel returns error (not partial result)
  • Regression test: Azure cache GetValidResourceTypes page cap terminates and falls back to common SKUs
  • Regression test: GCP computeengine GetRecommendations ctx-cancel returns error
  • Regression test: GCP computeengine GetRecommendations page cap returns error
  • Regression test: AWS fetchCoveragePaged ctx-cancel returns error

Summary by CodeRabbit

  • Bug Fixes

    • Pagination now promptly respects context cancellation across providers, aborting work and surfacing an error instead of returning partial results.
    • Pagination loops gain explicit safety caps to avoid unbounded iteration; when caps fire, operations fail fast or fall back predictably.
  • Tests

    • Added regression tests ensuring context-cancellation surfaces as errors during pagination.
    • Added tests validating pagination caps terminate iteration when limits are reached.

…loses #691)

Add ctx.Err() early-return guards and maxPages budget caps to all unbounded
pagination loops across Azure (14 loops), GCP (6 loops), and AWS (2 loops).

Context cancellation now terminates loops immediately with a wrapped error
instead of either continuing or silently returning a partial result set,
matching the pattern from PR #690 and the feedback_ctx_cancel_terminal rule.

Fixes in collect* helpers (cache, cosmosdb) and the inline search loop that
previously used ctx.Err()+break (silently partial) -- changed to return the
error so callers propagate it. Also fixes two nil-context test calls in
cache/client_test.go that panicked after the ctx.Err() guard was introduced.

Regression tests added: Azure cache GetValidResourceTypes ctx-cancel + page
cap, GCP computeengine GetRecommendations ctx-cancel + page cap, AWS
fetchCoveragePaged ctx-cancel.
@cristim cristim added triaged Item has been triaged priority/p1 Next up; this sprint severity/high Significant harm urgency/now Drop other things impact/all-users Affects every user effort/s Hours type/bug Defect labels May 28, 2026
@cristim

cristim commented May 28, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7e57d700-6f3d-4d8e-bfa0-afefb6062c4d

📥 Commits

Reviewing files that changed from the base of the PR and between 65b0c66 and 394058f.

📒 Files selected for processing (2)
  • providers/aws/recommendations/utilization.go
  • providers/azure/services/search/client.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • providers/aws/recommendations/utilization.go
  • providers/azure/services/search/client.go

📝 Walkthrough

Walkthrough

Adds context-cancellation checks and explicit pagination caps to recommendation and resource-enumeration loops across AWS, Azure, and GCP providers, converting unbounded pager/iterator loops into index-based iterations that abort on canceled contexts or when configured page caps are exceeded.

Changes

Pagination Safety Hardening Across Cloud Providers

Layer / File(s) Summary
AWS recommendations pagination safety
providers/aws/recommendations/coverage.go, providers/aws/recommendations/utilization.go, providers/aws/recommendations/coverage_test.go
Cost Explorer pagination loops in fetchCoveragePaged and GetRIUtilization now check ctx.Err() before fetching subsequent pages. New test validates that a cancelled context aborts pagination instead of proceeding with partial results.
Azure cache pagination safety
providers/azure/services/cache/client.go, providers/azure/services/cache/client_test.go
Cache client adds page-cap constants and converts recommendations, reservations, and SKU-enumeration loops to page-indexed iteration with context-cancellation checks. collectSKUsFromCaches now returns (map[string]bool, error) and propagates cancellation errors; GetValidResourceTypes returns errors when SKU collection fails. Tests validate cancellation and page-cap enforcement.
Azure compute pagination safety
providers/azure/services/compute/client.go
Compute client adds page-cap constants and converts recommendations, VM reservations, VM SKU sizes, and SKU catalogue loops to page-indexed iteration with context-cancellation checks. Cancellations return errors; cap breaches log warnings or return errors as appropriate.
Azure CosmosDB pagination safety
providers/azure/services/cosmosdb/client.go
CosmosDB client adds page-cap constants and converts recommendations, reservation-details, and account-capabilities loops to page-indexed iteration with context-cancellation checks. collectCapabilitiesFromAccounts returns (skuSet, error) and cancellation is propagated to GetValidResourceTypes.
Azure database pagination safety
providers/azure/services/database/client.go
Database client adds page-cap constants and converts recommendations and SQL-reservations loops to page-indexed iteration with per-page context-cancellation checks and cap enforcement returning explicit errors when exceeded.
Azure search pagination safety
providers/azure/services/search/client.go
Search client adds page-cap constants and converts recommendations, reservations, and services listing loops to page-indexed iteration with context-cancellation checks and cap enforcement; SKU-collection helper accumulates names and returns errors on cancellation or stops with logged warnings when caps fire.
GCP Cloud SQL pagination safety
providers/gcp/services/cloudsql/client.go
Cloud SQL client adds a page-cap constant and converts recommender iteration to a counter-based loop with ctx cancellation checks and cap enforcement; iterator.Done and iterator errors still propagate.
GCP Compute Engine pagination safety
providers/gcp/services/computeengine/client.go, providers/gcp/services/computeengine/client_test.go
Compute Engine client adds iteration caps and converts recommendations, commitments, and machine-types loops to indexed iteration with ctx cancellation checks and cap enforcement. Tests add infinite-iterator scaffolding and validate cancellation and cap-limit behavior.
GCP Memorystore pagination safety
providers/gcp/services/memorystore/client.go
Memorystore client adds a page-cap constant and converts recommendations iteration to index-based loop with ctx cancellation checks and cap enforcement while preserving iterator.Done semantics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Suggested labels

bug, urgency/this-sprint, effort/m

Poem

🐇 I hopped through loops both wide and deep,
Counted pages where pagers never sleep,
I sniffed the context, and when it said "stop",
I folded my ears and I called the next drop,
Caps on the trail—no infinite leap.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.64% which is insufficient. The required threshold is 80.00%. 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 accurately summarizes the main change: adding context cancellation guards and page caps to 22 pagination loops across AWS, GCP, and Azure providers, addressing issue #691.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/691-wave2

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

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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/services/computeengine/client.go`:
- Around line 656-662: GetValidResourceTypes currently treats
maxMachineTypesPages as a page cap while MachineTypesIterator.Next() yields one
machine type per call, so fix the semantics by switching to an item-based cap:
rename or replace maxMachineTypesPages with maxMachineTypes (or
maxMachineTypeItems), use a descriptive counter like itemIdx (instead of
pageIdx) to count Next() iterations, and update the error message in the check
inside GetValidResourceTypes to reflect an item cap (e.g., "computeengine:
GetValidResourceTypes iteration cap (%d items) reached") so the constant name
and message match the actual behavior of MachineTypesIterator.Next().
🪄 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: 3ccf2039-ca1e-4d31-a971-fc5a876bce06

📥 Commits

Reviewing files that changed from the base of the PR and between 4956d66 and f84e946.

📒 Files selected for processing (13)
  • providers/aws/recommendations/coverage.go
  • providers/aws/recommendations/coverage_test.go
  • providers/aws/recommendations/utilization.go
  • providers/azure/services/cache/client.go
  • providers/azure/services/cache/client_test.go
  • providers/azure/services/compute/client.go
  • providers/azure/services/cosmosdb/client.go
  • providers/azure/services/database/client.go
  • providers/azure/services/search/client.go
  • providers/gcp/services/cloudsql/client.go
  • providers/gcp/services/computeengine/client.go
  • providers/gcp/services/computeengine/client_test.go
  • providers/gcp/services/memorystore/client.go

Comment thread providers/gcp/services/computeengine/client.go Outdated
MachineTypesIterator.Next() yields one machine type per call, not one
page. Rename maxMachineTypesPages -> maxMachineTypeItems and
pageIdx -> itemIdx so the names and error message match the actual
iteration semantics.
@cristim

cristim commented May 30, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

The ctx.Err pagination guards added in this PR pushed two functions
just over the project's gocyclo > 10 ceiling, failing pre-commit:

- providers/azure/services/search/client.go GetValidResourceTypes (12)
- providers/aws/recommendations/utilization.go GetRIUtilization (11)

Each is split into a thin entry point plus a focused helper:
- GetValidResourceTypes -> resolveServicesPager + collectSKUsFromPager
- GetRIUtilization      -> buildUtilizations for the agg-to-slice tail

Behaviour unchanged; 323 tests pass across the two packages.
@cristim

cristim commented May 31, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim
cristim merged commit f4d7cdd into feat/multicloud-web-frontend May 31, 2026
4 checks passed
@cristim
cristim deleted the fix/691-wave2 branch June 3, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/s Hours impact/all-users Affects every user priority/p1 Next up; this sprint severity/high Significant harm triaged Item has been triaged type/bug Defect urgency/now Drop other things

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant