Skip to content

fix(azure/managedredis): pass subscription scope not filter to recommendations pager (follow-up to #1455) - #1475

Merged
cristim merged 1 commit into
mainfrom
fix/1455-followup-managedredis-pager
Jul 20, 2026
Merged

fix(azure/managedredis): pass subscription scope not filter to recommendations pager (follow-up to #1455)#1475
cristim merged 1 commit into
mainfrom
fix/1455-followup-managedredis-pager

Conversation

@cristim

@cristim cristim commented Jul 20, 2026

Copy link
Copy Markdown
Member

Follow-up to #1455 — HIGH (Fable adversarial sweep)

Azure Managed Redis reservation recommendations are entirely broken on main: GetRecommendations calls NewListPager(filter, ...), but the first argument is the billing scope, not the ODATA filter. The wrong shape produces a malformed URL where every request errors (the exact failure mode documented in compute/client.go). The sibling cache/client.go has the correct shape.

Fix

  • Pass /subscriptions/<id> as the scope; move the filter into ClientListOptions.Filter.
  • Add the pagination cap (maxRecsPages) + per-page ctx.Err() check every other Azure service client has.
  • Extracted recommendationsListArgs() so a unit test asserts the subscription-scope shape without a real Azure client (the injected mock pager bypasses NewListPager, which is why the bug slipped through green tests).

Verification

  • go build ./..., go vet, managedredis suite green.
  • New TestRecommendationsListArgs_UsesSubscriptionScope fails if the filter is passed as scope again.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected Azure Managed Redis recommendation retrieval to use the proper subscription scope and filters.
    • Improved pagination handling, including cancellation checks and a limit on the number of pages processed.
    • Added safeguards to prevent excessive recommendation requests.

…mmendations pager (follow-up to #1455)

NewListPager's first argument is the billing scope; managedredis passed the
ODATA filter string there, producing a malformed URL where every request
errored -- Azure Managed Redis reservation recommendations were entirely broken
on main. The filter belongs in ClientListOptions.Filter (the sibling
cache/client.go has the correct shape). Also add the pagination cap +
per-page ctx.Err() check every other Azure service client has.

Extracted recommendationsListArgs() so a unit test can assert the subscription
scope shape without a real Azure client (the injected mock pager bypasses
NewListPager, which is why the wrong shape slipped through green tests).
@cristim cristim added triaged Item has been triaged priority/p1 Next up; this sprint severity/high Significant harm urgency/now Drop other things impact/many Affects most users effort/s Hours type/bug Defect labels Jul 20, 2026
@cristim

cristim commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

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 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 24ef6489-268d-4485-af5c-5060c612ae9d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Managed Redis recommendation retrieval now constructs subscription-scoped Azure pager arguments, passes the resource-type filter separately, checks cancellation during pagination, and enforces a maximum page count. A regression test verifies the pager argument wiring.

Changes

Managed Redis recommendations

Layer / File(s) Summary
Build recommendation pager arguments
providers/azure/services/managedredis/client.go, providers/azure/services/managedredis/client_test.go
Adds maxRecsPages and recommendationsListArgs(), with a test confirming subscription scope and ODATA filter placement.
Apply bounded recommendation pagination
providers/azure/services/managedredis/client.go
Creates real pagers with the helper, checks context cancellation per page, and returns a capped error after the page limit.

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

Possibly related PRs

  • LeanerCloud/CUDly#620: Adds the Managed Redis recommendation pagination and pager-argument changes this PR builds on.

Suggested labels: impact/internal

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: using subscription scope instead of the filter for the Managed Redis recommendations pager.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1455-followup-managedredis-pager

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

@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.

🧹 Nitpick comments (2)
providers/azure/services/managedredis/client_test.go (2)

340-348: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add regression coverage for cancellation and the page cap.

The changed GetRecommendations path now has two important guards, but this test only covers argument construction. Add tests for a canceled context and a pager with more than maxRecsPages pages.

As per coding guidelines, *_test.go should prefer mock-first tests for new code.

🤖 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/azure/services/managedredis/client_test.go` around lines 340 - 348,
Extend the managed Redis recommendations tests beyond recommendationsListArgs to
cover GetRecommendations with a canceled context and a pager exposing more than
maxRecsPages pages. Use mock-first setup for the pager/client dependencies,
asserting cancellation returns promptly and the implementation stops after the
configured page cap while preserving collected results up to that limit.

Source: Coding guidelines


340-348: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert both required OData filter clauses.

This test only checks resourceType; it would still pass if properties/scope eq 'Shared' were accidentally removed.

Proposed assertion
  assert.Contains(t, *opts.Filter, "resourceType eq 'RedisCache'")
+ assert.Contains(t, *opts.Filter, "properties/scope eq 'Shared'")
🤖 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/azure/services/managedredis/client_test.go` around lines 340 - 348,
Update TestRecommendationsListArgs_UsesSubscriptionScope to assert that
opts.Filter contains both required OData clauses: the existing resourceType
condition and the properties/scope condition for 'Shared'.
🤖 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/azure/services/managedredis/client_test.go`:
- Around line 340-348: Extend the managed Redis recommendations tests beyond
recommendationsListArgs to cover GetRecommendations with a canceled context and
a pager exposing more than maxRecsPages pages. Use mock-first setup for the
pager/client dependencies, asserting cancellation returns promptly and the
implementation stops after the configured page cap while preserving collected
results up to that limit.
- Around line 340-348: Update TestRecommendationsListArgs_UsesSubscriptionScope
to assert that opts.Filter contains both required OData clauses: the existing
resourceType condition and the properties/scope condition for 'Shared'.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0afb5ad5-f13f-4c76-98d1-9cc7d9fa5516

📥 Commits

Reviewing files that changed from the base of the PR and between 299b6fd and 6891a84.

📒 Files selected for processing (2)
  • providers/azure/services/managedredis/client.go
  • providers/azure/services/managedredis/client_test.go

@cristim
cristim merged commit 2c67850 into main Jul 20, 2026
19 checks passed
@cristim
cristim deleted the fix/1455-followup-managedredis-pager branch July 27, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/s Hours impact/many Affects most users 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