Add subscribe API support for azure#2118
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughImplements Azure BYOC Subscribe: adds cloud API helpers (ACA revisions, ACR runs), tracks CD start times in ByocAzure, implements Subscribe orchestration with concurrent CD/ACR/revision pollers and gating, and adds integration/unit tests and a small CLI log message. ChangesAzure Deployment Event Streaming
Sequence DiagramsequenceDiagram
participant Client
participant Subscribe as ByocAzure.Subscribe
participant Aggregator as Event Aggregator
participant PollCD as pollCD goroutine
participant PollRevisions as pollRevision goroutine
participant PollBuilds as pollBuilds goroutine
Client->>Subscribe: Subscribe(ctx, request)
Subscribe->>Subscribe: Validate CD run active
Subscribe->>Subscribe: Check ETag match
Subscribe->>Aggregator: Create event multiplexer
Aggregator->>PollCD: Launch concurrent poller
Aggregator->>PollRevisions: Launch per-service pollers
Aggregator->>PollBuilds: Launch build poller
par Concurrent Polling
PollCD->>PollCD: Poll job execution status
PollRevisions->>PollRevisions: Poll revision states
PollBuilds->>PollBuilds: Poll ACR run history
end
PollCD-->>Aggregator: CD success/failure event
PollRevisions-->>Aggregator: Revision state change event
PollBuilds-->>Aggregator: Build status event
Aggregator->>Aggregator: Gate ready behind CD success
Aggregator->>Aggregator: Track per-service terminal states
loop Until all services terminal
Aggregator-->>Client: SubscribeResponse stream
end
Aggregator->>Client: Stream ends
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=warning msg="The linter 'gomodguard' is deprecated (since v2.12.0) due to: new major version. Replaced by gomodguard_v2." Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
src/pkg/cli/client/byoc/azure/subscribe_test.go (1)
251-276: ⚡ Quick winCollapse
mapRevisionStateunit tests into a table-driven test.These three tests are repetitive and should be table-driven for consistency and easier case expansion.
As per coding guidelines:
**/*_test.go: Use table-driven tests for comprehensive test coverage in unit tests.🤖 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 `@src/pkg/cli/client/byoc/azure/subscribe_test.go` around lines 251 - 276, Replace the three repetitive tests (TestMapRevisionState_NotFound, TestMapRevisionState_Healthy, TestMapRevisionState_FailedProvisioning) with a single table-driven test that iterates a slice of cases (each with a name, input *aca.RevisionState, expected defangv1.ServiceState value, and expected terminal bool), calling mapRevisionState for each case inside t.Run; include the three cases: nil → UPDATE_QUEUED/terminal=false, &aca.RevisionState{NotFound:true} → UPDATE_QUEUED/terminal=false, healthyRevision() → DEPLOYMENT_COMPLETED/terminal=true, and &aca.RevisionState{ProvisioningState: armappcontainersv3.RevisionProvisioningStateFailed} → DEPLOYMENT_FAILED/terminal=true, and assert expected state and terminal for each case.
🤖 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 `@src/pkg/cli/client/byoc/azure/subscribe_test.go`:
- Line 230: The test currently ignores the error returned by drain when calling
got, _ := drain(t, t.Context(), subscribeInputs{...}); update the call in the
build-state test to capture and assert the error (e.g., err := drain(...)) and
fail the test when err != nil using the test helper (t.Fatal/t.Fatalf or the
test harness’s equivalent). Ensure you reference the drain function and
subscribeInputs invocation so the test fails on any stream/drain errors instead
of silently passing.
In `@src/pkg/cli/client/byoc/azure/subscribe.go`:
- Around line 139-144: The loop in subscribe.go currently treats ev.err
non-terminal by calling yield(nil, ev.err) and then continuing; change the
control flow so that after emitting an error via yield (when ev.err != nil) the
subscription loop breaks/returns immediately instead of continuing, ensuring
pollers stop and the iterator completes; locate the block handling ev.err in the
subscription loop (the section that calls yield(nil, ev.err)) and replace the
continue with a terminal exit (return or break) so errors are treated as
terminal by the Subscribe/iterator logic.
In `@src/pkg/clouds/azure/aca/revisions.go`:
- Around line 24-27: Wrap the raw errors returned from the credential/setup
calls with contextual messages using fmt.Errorf and %w: replace direct returns
of err from the c.NewCreds() call (the cred, err := c.NewCreds() path) and the
other setup return around the 35-38 block with something like fmt.Errorf("setup
<describe operation>: %w", err) so callers see which operation failed; add the
fmt import if missing and ensure the message names the operation (e.g.,
"creating Azure creds" or "initializing subscription").
In `@src/pkg/clouds/azure/acr/runs.go`:
- Around line 38-41: Wrap and annotate raw errors returned from setup/discovery
paths so callers keep context: in the functions/methods ensureClients (where you
call r.NewCreds()), findRegistry, and the ListRunsSince entry path, replace bare
"return err" with fmt.Errorf including a short contextual message and %w to wrap
the original error (e.g., "ensureClients: failed to get creds: %w"). Use
fmt.Errorf consistently for each failing call site referenced (including the
spots around the r.NewCreds() call and the other locations at the review comment
ranges) so the error chain preserves original error values while adding
operation context.
- Around line 109-117: The early-exit check uses a zero-valued create when
run.Properties.CreateTime is nil, causing create.Before(since) to be true and
prematurely stopping pagination; modify the logic in the block handling
run.Properties.CreateTime so the "if !since.IsZero() && create.Before(since)"
check only runs when run.Properties.CreateTime != nil (i.e., move the since
comparison inside the CreateTime non-nil branch or otherwise skip the
early-return when CreateTime is nil) to avoid skipping newer runs.
---
Nitpick comments:
In `@src/pkg/cli/client/byoc/azure/subscribe_test.go`:
- Around line 251-276: Replace the three repetitive tests
(TestMapRevisionState_NotFound, TestMapRevisionState_Healthy,
TestMapRevisionState_FailedProvisioning) with a single table-driven test that
iterates a slice of cases (each with a name, input *aca.RevisionState, expected
defangv1.ServiceState value, and expected terminal bool), calling
mapRevisionState for each case inside t.Run; include the three cases: nil →
UPDATE_QUEUED/terminal=false, &aca.RevisionState{NotFound:true} →
UPDATE_QUEUED/terminal=false, healthyRevision() →
DEPLOYMENT_COMPLETED/terminal=true, and &aca.RevisionState{ProvisioningState:
armappcontainersv3.RevisionProvisioningStateFailed} →
DEPLOYMENT_FAILED/terminal=true, and assert expected state and terminal for each
case.
🪄 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: 89863da9-0416-4dd9-a371-2c745552b027
📒 Files selected for processing (6)
src/pkg/cli/client/byoc/azure/byoc.gosrc/pkg/cli/client/byoc/azure/byoc_test.gosrc/pkg/cli/client/byoc/azure/subscribe.gosrc/pkg/cli/client/byoc/azure/subscribe_test.gosrc/pkg/clouds/azure/aca/revisions.gosrc/pkg/clouds/azure/acr/runs.go
Description
So defang cli only exits when all services are up correctly.
Linked Issues
#2073
Checklist
Summary by CodeRabbit
New Features
Tests