carlos / platform Public

region labels: labels and move phrases on Running, the instance page and the flow (plan 1 task 6)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev c52759af1e2980ea619cb496c55aee1cc2b5f73a parent 676888a
9 files changed, +143 −5
  • internal/console/flow.go +3 −0
  • internal/console/overview.go +6 −0
  • internal/console/regionlabels_test.go +94 −0
  • internal/console/remoteinstances.go +10 −1
  • internal/console/templates/app_instance.html +1 −0
  • internal/console/templates/app_instances.html +3 −2
  • internal/console/templates/flow.html +2 −0
  • internal/console/templates/layout.html +1 −0
  • internal/console/view.go +23 −2
diff --git a/internal/console/flow.go b/internal/console/flow.go
index 55bd0b4f7..fa138bad6 100644
--- a/internal/console/flow.go
+++ b/internal/console/flow.go
@@ -107,6 +107,8 @@ type FlowAddress struct {
// working, and colouring it as a problem trains owners to ignore the
// colour that means an actual problem.
Tone string
+ // Region is the address's region label text, "" when unlabelled.
+ Region string
}
// addressTone maps healthWord's vocabulary onto the four tones. An
@@ -202,6 +204,7 @@ func assembleFlow(view *AppView, rows []InstanceRow, latest, latestAt, instances
Health: r.HealthWord,
Version: r.Version,
Tone: addressTone(r.HealthWord),
+ Region: r.Region,
})
}
chans := make(map[string]ChannelView, len(view.Channels))
diff --git a/internal/console/overview.go b/internal/console/overview.go
index fc1b260fc..cfde971f7 100644
--- a/internal/console/overview.go
+++ b/internal/console/overview.go
@@ -267,6 +267,10 @@ type InstanceRow struct {
// plain word — the column's whole job.
HealthWord string
Restartable bool
+ // Region is the row's region label text and Moving its move phrase,
+ // "" with none (region labels spec §3).
+ Region string
+ Moving string
}
// assembleInstanceRows joins the app's routes with the sweep's readings, in
@@ -302,6 +306,8 @@ func assembleInstanceRows(view *AppView, acct *Account, metrics []InstanceMetric
Metrics: byHost[rt.Host],
Restartable: rt.Restartable,
HealthWord: health,
+ Region: rt.Region.Text,
+ Moving: rt.Moving,
})
}
return rows
diff --git a/internal/console/regionlabels_test.go b/internal/console/regionlabels_test.go
new file mode 100644
index 000000000..09be06df5
--- /dev/null
+++ b/internal/console/regionlabels_test.go
@@ -0,0 +1,94 @@
+package console
+
+import (
+ "context"
+ "html"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/status"
+)
+
+const labelMoveID = "mv_abcdefghijklmnopqrstuvwxyz"
+
+// writeRegionEdges names the console's home ie and writes the edges files
+// the boxes publish: box A (the console's box, the home's "") in
+// eu-west-1, box B in uk (eu-west-2), and a box in au (ap-southeast-2)
+// that hosts nothing. Written after setUp, so the create door's placement
+// gate saw the fixture exactly as remoteinstances_test.go builds it.
+func writeRegionEdges(t *testing.T, tb *twoBoxes) {
+ t.Helper()
+ tb.fx.srv.cfg.HomeRegion = "ie"
+ putRegionEdges(t, tb.fx.rel, status.Label("box-a"), "", "eu-west-1")
+ putRegionEdges(t, tb.fx.rel, status.Label("box-b"), "uk", "eu-west-2")
+ putRegionEdges(t, tb.fx.rel, status.Label("box-c"), "au", "ap-southeast-2")
+}
+
+func loadRegionLabels(t *testing.T, tb *twoBoxes) {
+ t.Helper()
+ if !tb.fx.srv.refreshRegionNames(context.Background(), nil, time.Now()) {
+ t.Fatal("the region names were not read")
+ }
+}
+
+func publishRegionEdges(t *testing.T, tb *twoBoxes) {
+ t.Helper()
+ writeRegionEdges(t, tb)
+ loadRegionLabels(t, tb)
+}
+
+func (tb *twoBoxes) text(t *testing.T, path string) string {
+ t.Helper()
+ return html.UnescapeString(tb.page(t, path))
+}
+
+func TestRegionLabelsOnRunningInstanceAndFlow(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, true)
+ publishRegionEdges(t, tb)
+
+ running := tb.text(t, "/apps/shop/instances")
+ for _, want := range []string{"<th scope=\"col\">Region</th>", "Dublin (ie)", "London (uk)"} {
+ if !strings.Contains(running, want) {
+ t.Fatalf("Running lacks %q:\n%s", want, running)
+ }
+ }
+ if inst := tb.text(t, "/apps/shop/instances/"+remoteHost); !strings.Contains(inst, "<dt>Region</dt><dd>London (uk)") {
+ t.Fatalf("instance page lacks the Region fact:\n%s", inst)
+ }
+ if ov := tb.text(t, "/apps/shop"); !strings.Contains(ov, remoteHost) || !strings.Contains(ov, "London (uk)") {
+ t.Fatalf("overview addresses lack the label:\n%s", ov)
+ }
+}
+
+// TestRegionLabelsShowAMoveInFlight: the label stays the record's region,
+// with the phrase beside it (§3.3).
+func TestRegionLabelsShowAMoveInFlight(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, false)
+ publishRegionEdges(t, tb)
+ if _, err := provision.SetRecordMove(context.Background(), tb.fx.rel, tb.sqid, "shop", remoteHost,
+ provision.OfflineStart(labelMoveID, "uk", "au", "ops@example.com", time.Now())); err != nil {
+ t.Fatal(err)
+ }
+ running := tb.text(t, "/apps/shop/instances")
+ if !strings.Contains(running, "London (uk)") || !strings.Contains(running, "moving to Sydney (au)") {
+ t.Fatalf("Running lacks the label and move phrase:\n%s", running)
+ }
+ if inst := tb.text(t, "/apps/shop/instances/"+remoteHost); !strings.Contains(inst, "moving to Sydney (au)") {
+ t.Fatalf("instance page lacks the move phrase:\n%s", inst)
+ }
+}
+
+// TestRegionLabelsBeforeTheMapIsRead: Review Focus 2 on a page: codes.
+func TestRegionLabelsBeforeTheMapIsRead(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, true)
+ writeRegionEdges(t, tb) // home named, files written, map never read
+ running := tb.text(t, "/apps/shop/instances")
+ if strings.Contains(running, "London (uk)") || !strings.Contains(running, ">uk<") {
+ t.Fatalf("before a read the label must be the code:\n%s", running)
+ }
+}
diff --git a/internal/console/remoteinstances.go b/internal/console/remoteinstances.go
index f3cfcc612..60bf9f849 100644
--- a/internal/console/remoteinstances.go
+++ b/internal/console/remoteinstances.go
@@ -37,6 +37,7 @@ import (
"time"
"github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/regionlabel"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/status"
@@ -368,6 +369,11 @@ type remoteRows struct {
// records reads app's records (pageRecords).
records func(app string) ([]provision.Record, error)
facts func(app string) appFacts
+ // labels says rows get region labels (Server.remoteSource sets it),
+ // from home and the name map as they were when the view began.
+ labels bool
+ home string
+ names regionlabel.Names
}
// remoteRoute folds one record that has no row in the console box's registry
@@ -522,7 +528,10 @@ func (s *Server) remoteSource(ctx context.Context, acct string) *remoteRows {
defer cancel()
return s.pageRecords(rctx, acct, app)
},
- facts: func(app string) appFacts { return s.remoteFacts(ctx, acct, app) },
+ facts: func(app string) appFacts { return s.remoteFacts(ctx, acct, app) },
+ labels: true,
+ home: s.regionHome(),
+ names: s.regionNames(),
}
}
diff --git a/internal/console/templates/app_instance.html b/internal/console/templates/app_instance.html
index 39b2d37fb..b4c402457 100644
--- a/internal/console/templates/app_instance.html
+++ b/internal/console/templates/app_instance.html
@@ -12,6 +12,7 @@
</form>{{end}}
<dl class="instance-facts">
<dt>Health</dt><dd>{{.Row.HealthWord}}</dd>
+ {{if .Row.Region}}<dt>{{$.RegionCopy.PickerLabel}}</dt><dd>{{.Row.Region}}{{if .Row.Moving}}, {{.Row.Moving}}{{end}}</dd>{{end}}
<dt>{{$.InstanceCopy.LastReading}}</dt><dd>{{if .Row.Metrics.ObservedAt.IsZero}}—{{else}}<time title="{{fmtTime .Row.Metrics.ObservedAt}}">{{ago .Row.Metrics.ObservedAt}}</time>{{end}}</dd>
<dt>Channel</dt><dd><code>{{.Row.Channel}}</code></dd>
<dt>Layout</dt><dd>{{.Layout}}</dd>
diff --git a/internal/console/templates/app_instances.html b/internal/console/templates/app_instances.html
index b3904fcbb..df9d52c5f 100644
--- a/internal/console/templates/app_instances.html
+++ b/internal/console/templates/app_instances.html
@@ -31,11 +31,11 @@
{{if .InstanceRows}}
<div class="tablewrap">
<table class="instances">
- <thead><tr><th scope="col">Address</th><th scope="col">Health</th><th scope="col">Version</th><th scope="col">Channel</th><th scope="col">CPU</th><th scope="col">Memory</th></tr></thead>
+ <thead><tr><th scope="col">Address</th><th scope="col">{{.RegionCopy.PickerLabel}}</th><th scope="col">Health</th><th scope="col">Version</th><th scope="col">Channel</th><th scope="col">CPU</th><th scope="col">Memory</th></tr></thead>
{{if .InstanceQuery.Group}}
{{range .InstanceGroups}}
<tbody>
- <tr class="instance-group"><th colspan="6" scope="rowgroup"><code>{{.Channel}}</code> <span class="small">{{$.InstanceCopy.Target}}: {{if .TargetErr}}—{{else if .TargetVersion}}<code>{{.TargetVersion}}</code>{{else}}—{{end}} · Instances: {{len .Rows}} / {{.Total}}</span></th></tr>
+ <tr class="instance-group"><th colspan="7" scope="rowgroup"><code>{{.Channel}}</code> <span class="small">{{$.InstanceCopy.Target}}: {{if .TargetErr}}—{{else if .TargetVersion}}<code>{{.TargetVersion}}</code>{{else}}—{{end}} · Instances: {{len .Rows}} / {{.Total}}</span></th></tr>
{{range .Rows}}{{template "instance_row" (instanceRowPage $ .)}}{{end}}
</tbody>
{{end}}
@@ -102,6 +102,7 @@ hibernated instance state stays in the old placement's bucket.</p>
{{define "instance_row"}}
<tr>
<td class="instance-address"><a href="{{.Page.Nav}}/apps/{{.Page.AppName}}/instances/{{.Row.Host}}{{.Page.InstanceQuerySuffix}}">{{.Row.Host}}</a> <a class="instance-open" href="https://{{.Row.Host}}" aria-label="{{.Page.InstanceCopy.Open}} {{.Row.Host}}">{{icon "external-link"}}</a></td>
+ <td>{{if .Row.Region}}{{.Row.Region}}{{else}}—{{end}}{{if .Row.Moving}}<br><span class="small">{{.Row.Moving}}</span>{{end}}</td>
<td><span class="chip chip-health-{{healthTone .Row.HealthWord}}">{{.Row.HealthWord}}</span></td>
<td>{{if .Row.Version}}<code>{{.Row.Version}}</code>{{else}}—{{end}}</td>
<td><code>{{.Row.Channel}}</code></td>
diff --git a/internal/console/templates/flow.html b/internal/console/templates/flow.html
index 0596ec050..9617def99 100644
--- a/internal/console/templates/flow.html
+++ b/internal/console/templates/flow.html
@@ -35,6 +35,7 @@
{{range .Addresses}}
<li class="flow-addr flow-tone-{{.Tone}}">
<a href="https://{{.Host}}">{{.Host}}</a>
+ {{if .Region}}<span class="flow-region">{{.Region}}</span>{{end}}
<span class="flow-health">{{if eq .Tone "bad"}}{{icon "triangle-alert"}}{{end}}{{.Health}}</span>
</li>
{{end}}
@@ -46,6 +47,7 @@
{{range .Addresses}}
<li class="flow-addr flow-tone-{{.Tone}}">
<a href="https://{{.Host}}">{{.Host}}</a>
+ {{if .Region}}<span class="flow-region">{{.Region}}</span>{{end}}
<span class="flow-health">{{if eq .Tone "bad"}}{{icon "triangle-alert"}}{{end}}{{.Health}}</span>
</li>
{{end}}
diff --git a/internal/console/templates/layout.html b/internal/console/templates/layout.html
index b9fecac85..8535af211 100644
--- a/internal/console/templates/layout.html
+++ b/internal/console/templates/layout.html
@@ -354,6 +354,7 @@
}
.flow-addr { font-size: 0.82rem; line-height: 1.35; }
.flow-addr a { display: block; overflow-wrap: anywhere; }
+ .flow-region { color: var(--muted); margin-right: 0.35rem; }
.flow-health { display: inline-flex; align-items: center; gap: 0.2rem; color: var(--muted); }
.flow-health .icon { width: 0.9em; height: 0.9em; flex: none; }
.flow-tone-ok .flow-health { color: var(--good); }
diff --git a/internal/console/view.go b/internal/console/view.go
index 1258ac62b..f2ad09b40 100644
--- a/internal/console/view.go
+++ b/internal/console/view.go
@@ -40,6 +40,10 @@ type AppView struct {
// Production is the app's production-flag state (release.ProductionFlag)
// as the console shows it — see ProductionView.
Production ProductionView
+ // routeFleet is the first fleet placement among this app's rows in the
+ // console box's registry (fleetFromRoutes): appPlacement's legacy
+ // fallback, folded from the listing Assemble already made.
+ routeFleet string
// RouteAccount is the account the app's ROUTES say it belongs to, when
// that disagrees with the account whose page this is; "" when they agree
// or there are no routes. It is the first mismatched account (kept for
@@ -635,7 +639,7 @@ func Assemble(ctx context.Context, regPath string, s release.Store, pub ed25519.
// assembleOverview leans on that to account-filter domain rows
// (DomainView carries no account of its own). Splitting these
// appends apart breaks that join silently.
- byApp[rt.App] = append(byApp[rt.App], RouteView{
+ rv := RouteView{
Host: rt.Host, Kind: rt.Kind, Status: rt.Status,
Version: rt.Version, Channel: ch, Hibernate: rt.Hibernate,
Platform: rt.Platform,
@@ -644,7 +648,13 @@ func Assemble(ctx context.Context, regPath string, s release.Store, pub ed25519.
Caps: capsFor,
Unit: rt.Unit, Backing: rt.Backing, Provisioned: rt.Provisioned,
Restartable: release.Adoptable(rt),
- })
+ }
+ if remote != nil && remote.labels {
+ // The row's own label; addRemoteRows replaces it with the
+ // record's, which also carries a move.
+ rv.Region = regionlabel.ForRoute(rt, remote.home, remote.names)
+ }
+ byApp[rt.App] = append(byApp[rt.App], rv)
domainsByApp[rt.App] = append(domainsByApp[rt.App], domainView(rt, dns))
}
now := time.Now()
@@ -687,6 +697,7 @@ func Assemble(ctx context.Context, regPath string, s release.Store, pub ed25519.
// Ladder from the corrected Channels once it has one.
Ladder: assembleLadder(channels, byApp[app], nil, now),
Production: pv,
+ routeFleet: fleetFromRoutes(routes, acct, app),
})
}
return out, nil
@@ -727,10 +738,20 @@ func addRemoteRows(remote *remoteRows, acct, app string, localHosts map[string]b
// hostname left samples under the same unit name.
if i, ok := ownLocal[rec.Host]; ok {
routes[i].since, routes[i].bounded = rec.CreatedAt, true
+ if remote.labels {
+ // The record says where the instance is, and carries
+ // its move.
+ routes[i].Region = regionlabel.ForRecord(rec, remote.home, remote.names)
+ routes[i].Moving = regionlabel.MovePhrase(rec, remote.home, remote.names)
+ }
}
continue
}
rv, dv := remoteRoute(rec, facts.host(rec), facts, acct, dns)
+ if remote.labels {
+ rv.Region = regionlabel.ForRecord(rec, remote.home, remote.names)
+ rv.Moving = regionlabel.MovePhrase(rec, remote.home, remote.names)
+ }
routes = append(routes, rv)
domains = append(domains, dv)
added = true