Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions internal/cmd/compute/url/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,13 @@ func (p *progress) check(ctx context.Context, c client.Client, workloadName stri
return nil, false, nil
}

if info.Backends.Healthy > 0 {
p.line("Backends", fmt.Sprintf("%d healthy across %s", info.Backends.Healthy, strings.Join(servingCities(info), ", ")))
// Report the backends stage whenever a NetworkService backs the URL, even
// with nothing healthy yet. A redeploy of an already-live URL can return on
// the first poll, before the new instance registers, so the healthy count
// can be zero here. The line still belongs in the output, which a caller
// such as a rollout gate reads.
if info.Service != nil {
p.line("Backends", backendsStage(info))
}
if info.EdgeProgrammed {
p.line("Edge", "programmed")
Expand All @@ -241,6 +246,18 @@ func (p *progress) check(ctx context.Context, c client.Client, workloadName stri
return nil, false, nil
}

// backendsStage renders the backends progress value: how many members are
// healthy and the cities taking traffic. The cities are dropped when the
// platform has reported no location yet, so the value never ends in a bare
// "across".
func backendsStage(info *Info) string {
stage := fmt.Sprintf("%d healthy", info.Backends.Healthy)
if cities := servingCities(info); len(cities) > 0 {
stage += " across " + strings.Join(cities, ", ")
}
return stage
}

// line prints one progress row, skipping rows already printed with the same
// value. A count that changes as instances register is worth reprinting; a
// repeat of the same fact is not.
Expand Down
27 changes: 27 additions & 0 deletions internal/cmd/compute/url/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,33 @@ func TestPublishReturnsWhenTheURLIsLive(t *testing.T) {
}
}

// TestPublishReportsBackendsBeforeAnyRegister pins the output a redeploy owes.
// The URL is already live from the previous deploy, so the wait returns on its
// first poll while the NetworkService still reports no healthy member. The
// backends line must still appear, because a caller such as a rollout gate
// reads the deploy output for it.
func TestPublishReportsBackendsBeforeAnyRegister(t *testing.T) {
c := newFakeClient(t,
publishedProxy(testWorkloadName, testCanonical),
publishedService(testWorkloadName, 8080, location("DFW", 1, 0, false)),
)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

var out bytes.Buffer
info, err := Publish(ctx, &out, c, workloadNamed(testWorkloadName), testPortName, 8080, false, nil)
if err != nil {
t.Fatalf("Publish returned error: %v", err)
}
if info == nil || !info.Live() {
t.Fatalf("info = %+v, want the live URL left by the previous deploy", info)
}
if got := out.String(); !strings.Contains(got, "Backends 0 healthy across DFW") {
t.Errorf("output missing the backends line:\n%s", got)
}
}

func TestPublishUpdatesAChangedPort(t *testing.T) {
rec := &recorder{}
c := interceptor.NewClient(newFakeClient(t,
Expand Down
Loading