region labels: the deploy watch says where each host went live (plan 2 task 4)
watchDeployed takes the places map after main's gated-hosts map.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+72
−11
deploy.go+25 −3deploywatch.go+10 −8region_labels_test.go+37 −0
CI failed — run details
diff --git a/deploy.go b/deploy.go| index 9c4279606..9e4e3f33b 100644 |
| --- a/deploy.go |
| +++ b/deploy.go |
| @@ -517,8 +517,9 @@ func runDeploy(args []string) { |
| // exactly as before. |
| printWatchNote(probe, true, *app) |
| targets := make([]watchTarget, 0, len(hosts)) |
| + places := hostPlaces(recs) |
| for _, h := range hosts { |
| - targets = append(targets, watchTarget{Host: h, Origin: watchOrigin(h), Probe: probe}) |
| + targets = append(targets, watchTarget{Host: h, Origin: watchOrigin(h), Probe: probe, Place: places[h]}) |
| } |
| targets = passGatedTargets(stdout, targets, gatedHosts(recs), *ver, channel, |
| func(host string) (string, error) { return sess.instanceGatePass(ctx, acct, *app, host) }) |
| @@ -532,7 +533,7 @@ func runDeploy(args []string) { |
| } |
| // An instance deploy follows each box's rollout of the build (spec §9.1, |
| // deploywatch.go), and is today's URL watch when no box reports one. |
| - if err := watchDeployed(ctx, sess, acct, *app, *ver, channel, hosts, gatedHosts(recs), probe, *timeout); err != nil { |
| + if err := watchDeployed(ctx, sess, acct, *app, *ver, channel, hosts, gatedHosts(recs), hostPlaces(recs), probe, *timeout); err != nil { |
| log.Fatalf("deploy: %v", err) |
| } |
| } |
| @@ -1524,6 +1525,27 @@ type watchTarget struct { |
| Cookie string |
| Gated bool |
| PassErr string |
| + // Place is the host's label as the console's instance list named it |
| + // (region labels §5 row 20), "" when it sent none. |
| + Place string |
| +} |
| + |
| +// tail is RC-17's " in <place>", or nothing. |
| +func (t watchTarget) tail() string { |
| + if t.Place == "" { |
| + return "" |
| + } |
| + return " in " + t.Place |
| +} |
| + |
| +// hostPlaces maps each record's host to the label the console sent for it, |
| +// "" for a record with none (an older console). |
| +func hostPlaces(recs []apiInstanceRecord) map[string]string { |
| + out := make(map[string]string, len(recs)) |
| + for _, r := range recs { |
| + out[r.Host] = cleanPlace(r.RegionName) |
| + } |
| + return out |
| } |
| // gatedHosts is the set of instance hosts the console says carry a password |
| @@ -1662,7 +1684,7 @@ func watchVersion(w io.Writer, targets []watchTarget, ver string, timeout, inter |
| for i, r := range results { |
| host := pending[i].Host |
| if r.live { |
| - fmt.Fprintf(w, "%s https://%s\n", colorFor(w).ok("live"), host) |
| + fmt.Fprintf(w, "%s https://%s%s\n", colorFor(w).ok("live"), host, pending[i].tail()) |
| continue |
| } |
| last[host] = r.diag |
diff --git a/deploywatch.go b/deploywatch.go| index 33aceb59e..8c21087a4 100644 |
| --- a/deploywatch.go |
| +++ b/deploywatch.go |
| @@ -577,20 +577,22 @@ func stayedOn(r *apiRollout) string { |
| } |
| func (rw rolloutWatch) printHost(c colors, h *watchedHost) { |
| - host := h.t.Host |
| + // tail is RC-17's " in <place>" (region labels §5 row 20), "" when the |
| + // console sent no label. |
| + host, tail := h.t.Host, h.t.tail() |
| if h.mode == modeURL { |
| - fmt.Fprintf(rw.w, "%s https://%s\n", c.ok("live"), host) |
| + fmt.Fprintf(rw.w, "%s https://%s%s\n", c.ok("live"), host, tail) |
| return |
| } |
| switch h.state { |
| case rolloutSwapped: |
| - fmt.Fprintf(rw.w, "%s https://%s\n", c.ok(watchWordSwapped), host) |
| + fmt.Fprintf(rw.w, "%s https://%s%s\n", c.ok(watchWordSwapped), host, tail) |
| case rolloutAsleep: |
| - fmt.Fprintf(rw.w, "%s https://%s (%s)\n", c.ok(watchWordInstalled), host, watchAsleepTail) |
| + fmt.Fprintf(rw.w, "%s https://%s%s (%s)\n", c.ok(watchWordInstalled), host, tail, watchAsleepTail) |
| case rolloutFailed: |
| - fmt.Fprintf(rw.w, "%s https://%s: %s\n", c.warn(watchWordFailed), host, rolloutwords.Reason(h.fin.Reason)) |
| + fmt.Fprintf(rw.w, "%s https://%s%s: %s\n", c.warn(watchWordFailed), host, tail, rolloutwords.Reason(h.fin.Reason)) |
| case rolloutHeld: |
| - fmt.Fprintf(rw.w, "%s https://%s: %s\n", c.warn(watchWordHeld), host, fmt.Sprintf(watchHeldTail, stayedOn(h.fin), rw.ver)) |
| + fmt.Fprintf(rw.w, "%s https://%s%s: %s\n", c.warn(watchWordHeld), host, tail, fmt.Sprintf(watchHeldTail, stayedOn(h.fin), rw.ver)) |
| } |
| } |
| @@ -690,10 +692,10 @@ func (rw rolloutWatch) timedOut(hosts []*watchedHost, boxes map[string][]*watche |
| // watchDeployed is the watch for an instance (non-static) deploy of ver onto |
| // channel. |
| -func watchDeployed(ctx context.Context, sess *apiSession, acct apiAcct, app, ver, channel string, hosts []string, gated map[string]bool, probe string, timeout time.Duration) error { |
| +func watchDeployed(ctx context.Context, sess *apiSession, acct apiAcct, app, ver, channel string, hosts []string, gated map[string]bool, places map[string]string, probe string, timeout time.Duration) error { |
| targets := make([]watchTarget, 0, len(hosts)) |
| for _, h := range hosts { |
| - targets = append(targets, watchTarget{Host: h, Origin: watchOrigin(h), Probe: probe}) |
| + targets = append(targets, watchTarget{Host: h, Origin: watchOrigin(h), Probe: probe, Place: places[h]}) |
| } |
| return newDeployWatch(ctx, sess, acct, app, ver, channel, probe, timeout, gated).run(targets) |
| } |
diff --git a/region_labels_test.go b/region_labels_test.go| index 35f6b1918..24674b67d 100644 |
| --- a/region_labels_test.go |
| +++ b/region_labels_test.go |
| @@ -1,6 +1,7 @@ |
| package main |
| import ( |
| + "bytes" |
| "encoding/json" |
| "fmt" |
| "strings" |
| @@ -115,3 +116,39 @@ func TestAppsListLongLabel(t *testing.T) { |
| t.Fatalf("an unknown region is a dash: %q", got) |
| } |
| } |
| + |
| +func TestDeployWatchLinesSayWhere(t *testing.T) { |
| + var b bytes.Buffer |
| + rw := rolloutWatch{w: &b, ver: "v2"} |
| + c := colorFor(&b) |
| + at := watchTarget{Host: "a.shop.example.com", Place: "London (uk)"} |
| + for _, h := range []*watchedHost{ |
| + {t: at, mode: modeURL}, |
| + {t: at, state: rolloutSwapped}, |
| + {t: at, state: rolloutAsleep}, |
| + {t: at, state: rolloutFailed, fin: &apiRollout{Reason: "health"}}, |
| + {t: at, state: rolloutHeld, fin: &apiRollout{Serving: "v1"}}, |
| + } { |
| + rw.printHost(c, h) |
| + } |
| + for _, want := range []string{ |
| + "live https://a.shop.example.com in London (uk)\n", |
| + "swapped https://a.shop.example.com in London (uk)\n", |
| + "installed https://a.shop.example.com in London (uk) (", |
| + "failed https://a.shop.example.com in London (uk): ", |
| + "held https://a.shop.example.com in London (uk): ", |
| + } { |
| + if !strings.Contains(b.String(), want) { |
| + t.Fatalf("watch output lacks %q:\n%s", want, b.String()) |
| + } |
| + } |
| + // An older console: no place, today's line. |
| + b.Reset() |
| + rw.printHost(c, &watchedHost{t: watchTarget{Host: "a.shop.example.com"}, mode: modeURL}) |
| + if b.String() != "live https://a.shop.example.com\n" { |
| + t.Fatalf("older console: %q", b.String()) |
| + } |
| + if p := hostPlaces([]apiInstanceRecord{{Host: "a.shop.example.com", Region: "uk", RegionName: "London (uk)"}, {Host: "b.shop.example.com", Region: "uk"}}); p["a.shop.example.com"] != "London (uk)" || p["b.shop.example.com"] != "" { |
| + t.Fatalf("hostPlaces = %v", p) |
| + } |
| +} |