carlos / platform Public

region labels: Running's placement line always, Change fleet, the Activity line and the fleet pages (plan 1 task 10)

Labels 9 retires the rule that a home app with no eligible sibling shows no
C7 line: TestInstancesTabRegionLineForAHomeApp now expects the line, and
TestInstancesTabRegionLines expects pooled apps' RC-18c/RC-18e line instead
of silence. Both read the name map and expect labels.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 4104bb9b9a2124d6517548663d48344fc94e1c34 parent 58358b0
9 files changed, +359 −49
  • internal/console/accountfleet.go +4 −3
  • internal/console/regiondefault_test.go +48 −25
  • internal/console/regionfacts.go +52 −0
  • internal/console/regionfacts_test.go +30 −0
  • internal/console/regionlabels_test.go +134 −0
  • internal/console/server.go +49 −16
  • internal/console/store.go +36 −0
  • internal/console/templates/app_instances.html +1 −1
  • internal/console/templates/fleet.html +5 −4
diff --git a/internal/console/accountfleet.go b/internal/console/accountfleet.go
index 75d9a0ce4..27d9a51bf 100644
--- a/internal/console/accountfleet.go
+++ b/internal/console/accountfleet.go
@@ -100,9 +100,10 @@ func (s *Server) assembleAccountFleet(ctx context.Context, acct *Account) (card
card.Boxes = len(f.Boxes)
seen := map[string]bool{}
for _, b := range f.Boxes {
- if b.Region != "" && !seen[b.Region] {
- seen[b.Region] = true
- card.Regions = append(card.Regions, b.Region)
+ word := s.boxRegionWord(b.Label, b.Region)
+ if word != "" && !seen[word] {
+ seen[word] = true
+ card.Regions = append(card.Regions, word)
}
}
sort.Strings(card.Regions)
diff --git a/internal/console/regiondefault_test.go b/internal/console/regiondefault_test.go
index 3b327a150..0c3295b72 100644
--- a/internal/console/regiondefault_test.go
+++ b/internal/console/regiondefault_test.go
@@ -10,6 +10,7 @@ import (
"net/http"
"strings"
"testing"
+ "time"
"github.com/carlosframework/platform/internal/geo"
"github.com/carlosframework/platform/internal/provision"
@@ -350,19 +351,27 @@ func TestRegionsLegacyFieldsGolden(t *testing.T) {
}
// C7 only when the default is CONFIRMED available; C8 whenever it is
-// confirmed unavailable; nothing for fleet, pooled, or a default that
-// could not be read (codex plan-R1 14). Assertions compare the HTML-escaped
-// copy, both ways (codex plan-R1 8).
+// confirmed unavailable; nothing for fleet or a default that could not be
+// read (codex plan-R1 14). A pooled app says where pooled creates land
+// (region labels spec §5 row 5, RC-18c/RC-18e). The region is named by its
+// label from the console's name map (region labels spec §3). Assertions
+// compare the HTML-escaped copy, both ways (codex plan-R1 8).
func TestInstancesTabRegionLines(t *testing.T) {
- starts := html.EscapeString(fmt.Sprintf(regionCopy.StartsIn, ukPlace))
- cantUK := html.EscapeString(fmt.Sprintf(regionCopy.CantStart, "uk"))
+ starts := html.EscapeString(fmt.Sprintf(regionCopy.StartsIn, "London (uk)"))
+ cantUK := html.EscapeString(fmt.Sprintf(regionCopy.CantStart, "London (uk)"))
page := func(fx *consoleFixture) string {
_, _, body := get(t, signInPaul(t, fx), fx.u("/apps/titogo/instances"))
return body
}
anyLine := func(body string) bool { return strings.Contains(body, `id="app-region-line"`) }
+ readNames := func(fx *consoleFixture) {
+ if !fx.srv.refreshRegionNames(context.Background(), nil, time.Now()) {
+ t.Fatal("the region names were not read")
+ }
+ }
fx, _, _ := fillFixture(t, "uk")
+ readNames(fx)
fx.srv.cfg.AppRegions = true
body := page(fx)
if !strings.Contains(body, starts) {
@@ -372,7 +381,8 @@ func TestInstancesTabRegionLines(t *testing.T) {
t.Error("C7 carries the warning class")
}
retireBox(t, fx, "uk-box")
- // No box publishes uk, so its place falls back to the bare code (§14).
+ // No box publishes uk now; the name map keeps the place it last read
+ // until its next rebuild (spec §3.2).
body = page(fx)
if !strings.Contains(body, cantUK) || strings.Contains(body, starts) {
t.Fatal("want C8, not C7, when the region is absent (codex 7)")
@@ -383,11 +393,6 @@ func TestInstancesTabRegionLines(t *testing.T) {
for _, setup := range []func(*consoleFixture){
func(fx *consoleFixture) { fx.st.SetAppPlacement(OpsAccountID, "titogo", "fleet/acme") },
- func(fx *consoleFixture) {
- m := titoManifest()
- m.Pool = "tito"
- enableInstances(t, fx, "titogo", m)
- },
func(fx *consoleFixture) { corruptManifest(t, fx) },
func(fx *consoleFixture) { fx.srv.cfg.Releases = failingList{fx.rel} },
// the stored region could not be read: never claimed available.
@@ -396,39 +401,57 @@ func TestInstancesTabRegionLines(t *testing.T) {
},
} {
fx, _, _ := fillFixture(t, "uk")
+ readNames(fx)
setup(fx)
if anyLine(page(fx)) {
- t.Error("a fleet, pooled or unreadable default showed a region line")
+ t.Error("a fleet or unreadable default showed a region line")
}
}
+
+ // A pooled app: where a pooled create lands, the home, by its label.
+ fx, _, _ = fillFixture(t, "uk")
+ readNames(fx)
+ m := titoManifest()
+ m.Pool = "tito"
+ enableInstances(t, fx, "titogo", m)
+ if body := page(fx); !strings.Contains(body, "New pooled instances") || !strings.Contains(body, "Dublin (ie)") {
+ t.Error("a pooled app's line does not name where pooled creates land")
+ }
}
-// PF9, PF10: an app whose region is the home (stored "", the record
-// vocabulary's home) gets C7 only when the home has a sibling to be told
-// apart from (two eligible regions); alone it says nothing. A home the
+// PF9, PF10, region labels 9: an app whose region is the home (stored "",
+// the record vocabulary's home) is always told where it starts, by the
+// home's label, whether or not the home has a sibling. A home the
// allow-list leaves out is still C8, whatever the sibling count.
func TestInstancesTabRegionLineForAHomeApp(t *testing.T) {
- homePlace := geo.PlaceName("eu-west-1", "ie")
- starts := html.EscapeString(fmt.Sprintf(regionCopy.StartsIn, homePlace))
- cantHome := html.EscapeString(fmt.Sprintf(regionCopy.CantStart, homePlace))
+ const homeLabel = "Dublin (ie)"
+ starts := html.EscapeString(fmt.Sprintf(regionCopy.StartsIn, homeLabel))
+ cantHome := html.EscapeString(fmt.Sprintf(regionCopy.CantStart, homeLabel))
page := func(fx *consoleFixture) string {
_, _, body := get(t, signInPaul(t, fx), fx.u("/apps/titogo/instances"))
return body
}
+ fixture := func() *consoleFixture {
+ fx, _, _ := fillFixture(t, "")
+ if !fx.srv.refreshRegionNames(context.Background(), nil, time.Now()) {
+ t.Fatal("the region names were not read")
+ }
+ return fx
+ }
- fx, _, _ := fillFixture(t, "")
+ fx := fixture()
if body := page(fx); !strings.Contains(body, starts) {
- t.Errorf("two eligible regions: want C7 naming the home %q", homePlace)
+ t.Errorf("two eligible regions: want C7 naming the home %q", homeLabel)
}
- // Only the home is left: nothing to distinguish it from.
- fx, _, _ = fillFixture(t, "")
+ // Only the home is left: it is still told where it starts (labels 9).
+ fx = fixture()
retireBox(t, fx, "uk-box")
- if body := page(fx); strings.Contains(body, `id="app-region-line"`) {
- t.Error("one eligible region: a region line showed")
+ if body := page(fx); !strings.Contains(body, starts) {
+ t.Error("one eligible region: want C7 naming the home")
}
- fx, _, _ = fillFixture(t, "")
+ fx = fixture()
m := titoManifest()
m.Pool, m.Regions = "", []string{"uk"}
enableInstances(t, fx, "titogo", m)
diff --git a/internal/console/regionfacts.go b/internal/console/regionfacts.go
index 50af10db7..0fb1a78f2 100644
--- a/internal/console/regionfacts.go
+++ b/internal/console/regionfacts.go
@@ -235,3 +235,55 @@ func sortedCounts(by map[string]int) []regionCount {
sort.Slice(out, func(i, j int) bool { return out[i].Text < out[j].Text })
return out
}
+
+// boxRegionWord is a box's region for a page: its label when the name map
+// knows the box, else the box's own STATUS_BOX_REGION word.
+func (s *Server) boxRegionWord(label, word string) string {
+ if _, name := s.boxRegion(label); name != "" {
+ return name
+ }
+ return word
+}
+
+// fleetAppRegions labels the platform fleet page's apps. status/fleet.json
+// names an app but not its account, and names are unique per account only,
+// so a name every holder of which agrees on one label gets it, and a name
+// whose holders disagree, or whose facts could not be read, gets none (a
+// dash). SQLite and one registry listing; no store request.
+func (s *Server) fleetAppRegions(names []string) map[string]string {
+ rows, err := s.store.LivePlacesNamed(names)
+ if err != nil {
+ log.Printf("console: region labels: fleet apps: %v", err)
+ return nil
+ }
+ routes, routesOK := s.registryRoutes()
+ home, n := s.regionHome(), s.regionNames()
+ seen := map[string]map[string]bool{}
+ for _, r := range rows {
+ placed := r.Placement
+ if placed == "" {
+ if !routesOK {
+ seen[r.App] = map[string]bool{"": true, "?": true} // unknown: ambiguous by construction
+ continue
+ }
+ placed = fleetFromRoutes(routes, r.Sqid, r.App)
+ }
+ text := regionlabel.ForCode(r.Region, home, n).Text
+ if _, ok := registry.FleetPlacement(placed); ok {
+ text = regionlabel.ForCode(placed, home, n).Text
+ }
+ if seen[r.App] == nil {
+ seen[r.App] = map[string]bool{}
+ }
+ seen[r.App][text] = true
+ }
+ out := map[string]string{}
+ for app, texts := range seen {
+ if len(texts) == 1 {
+ for t := range texts {
+ out[app] = t
+ }
+ }
+ }
+ return out
+}
diff --git a/internal/console/regionfacts_test.go b/internal/console/regionfacts_test.go
index bd3cd14f1..7a592683d 100644
--- a/internal/console/regionfacts_test.go
+++ b/internal/console/regionfacts_test.go
@@ -147,3 +147,33 @@ func TestRegionLabelCopyHasNoEmDash(t *testing.T) {
}
}
}
+
+func TestLivePlacesNamedAndFleetAppRegions(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.srv.cfg.HomeRegion = "ie"
+ putRegionEdges(t, fx.rel, "box-uk", "uk", "eu-west-2")
+ fx.srv.refreshRegionNames(context.Background(), nil, time.Now())
+ now := time.Now()
+ if err := fx.st.CreateAccount(6161, accountSqid(6161), "Other", "o@example.com", now); err != nil {
+ t.Fatal(err)
+ }
+ for _, c := range []struct {
+ id int64
+ app, region string
+ }{{OpsAccountID, "shop", "uk"}, {OpsAccountID, "blog", ""}, {6161, "blog", "uk"}, {6161, "cart", "uk"}} {
+ if _, err := fx.st.CreateAppInRegion(c.id, c.app, "paul@keymail.dev", c.region, "chosen", now); err != nil {
+ t.Fatal(err)
+ }
+ }
+ rows, err := fx.st.LivePlacesNamed([]string{"shop", "blog"})
+ if err != nil || len(rows) != 3 {
+ t.Fatalf("LivePlacesNamed = %+v %v", rows, err)
+ }
+ got := fx.srv.fleetAppRegions([]string{"shop", "blog", "cart", "missing"})
+ if got["shop"] != "London (uk)" || got["cart"] != "London (uk)" {
+ t.Fatalf("fleet app regions = %v", got)
+ }
+ if _, has := got["blog"]; has {
+ t.Fatalf("blog is in two accounts with two regions: it must show a dash, got %q", got["blog"])
+ }
+}
diff --git a/internal/console/regionlabels_test.go b/internal/console/regionlabels_test.go
index 42d3f4649..3fd9d2539 100644
--- a/internal/console/regionlabels_test.go
+++ b/internal/console/regionlabels_test.go
@@ -2,8 +2,12 @@ package console
import (
"context"
+ "encoding/json"
"errors"
"html"
+ "net/http"
+ "net/url"
+ "regexp"
"strings"
"testing"
"time"
@@ -193,3 +197,133 @@ func TestStoredRegionUnknownOnPages(t *testing.T) {
t.Fatalf("Settings with the stored region unread:\n%s", st)
}
}
+
+// blog has no instances manifest, so it is not pooled and appDefault
+// answers available for the home. (shop's manifest is pooled and its
+// allow-list does not name the home's "", so shop's tab says nothing.)
+func TestRunningPlacementLineAlwaysNamesTheRegion(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, false)
+ if _, err := tb.fx.st.CreateAppIn(5151, "blog", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ publishRegionEdges(t, tb)
+ running := tb.text(t, "/apps/blog/instances")
+ // labels 9: a home app is told where it starts even with no sibling
+ // eligible to tell it apart from.
+ if !strings.Contains(running, "New instances start in Dublin (ie), this app's region.") {
+ t.Fatalf("Running lacks C7 with the label:\n%s", running)
+ }
+}
+
+// TestRunningPooledPlacementLines (spec §5 row 5; Astra plan finding 7): a
+// pooled app's new instances start in the home, so Running says so with the
+// home's label, and says when they cannot (the manifest's allow-list leaves
+// the home out), never nothing.
+func TestRunningPooledPlacementLines(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, false)
+ if _, err := tb.fx.st.CreateAppIn(5151, "cart", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if err := provision.PutManifest(context.Background(), tb.fx.rel, tb.sqid, "cart",
+ provision.Manifest{Schema: 1, App: "cart", Domain: "cart.example.com", Pool: "shop", Channel: "stable"}); err != nil {
+ t.Fatal(err)
+ }
+ publishRegionEdges(t, tb)
+ if got := tb.text(t, "/apps/cart/instances"); !strings.Contains(got, "New pooled instances start in Dublin (ie).") {
+ t.Fatalf("a pooled app the home may take:\n%s", got)
+ }
+ // shop's manifest is pooled with the allow-list ie, uk: the home's ""
+ // is not on it, so a pooled create cannot land.
+ if got := tb.text(t, "/apps/shop/instances"); !strings.Contains(got,
+ "New pooled instances can't start in Dublin (ie) right now. Pass a region to place one elsewhere.") {
+ t.Fatalf("a pooled app the home may not take:\n%s", got)
+ }
+}
+
+// TestRunningPlacementLineWithNoHomeNamed: Review Focus 5.
+func TestRunningPlacementLineWithNoHomeNamed(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, false)
+ if _, err := tb.fx.st.CreateAppIn(5151, "blog", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ loadRegionLabels(t, tb) // no home named, no edges files
+ running := tb.text(t, "/apps/blog/instances")
+ // The page's script has "()" of its own, so the check for an empty
+ // code reads the region line alone.
+ line := regexp.MustCompile(`<p id="app-region-line"[^>]*>([^<]*)</p>`).FindStringSubmatch(running)
+ if line == nil || line[1] != "New instances start in the home region, this app's region." || strings.Contains(line[1], "()") {
+ t.Fatalf("Running with no home named:\n%s", running)
+ }
+}
+
+func TestRunningFleetButtonSaysChangeFleet(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, false)
+ regA, err := registry.Open(tb.fx.regPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ // The account owns a fleet, so its owner sees the placement form.
+ if _, err := regA.CreateFleet(registry.Fleet{Name: "private", Account: tb.sqid, CreatedAt: time.Now().Unix()}); err != nil {
+ t.Fatal(err)
+ }
+ running := tb.text(t, "/apps/shop/instances")
+ if !strings.Contains(running, ">Change fleet</button>") || strings.Contains(running, ">Move</button>") {
+ t.Fatalf("Running's fleet button:\n%s", running)
+ }
+}
+
+func TestActivityCreateLineNamesTheLabel(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, false)
+ publishRegionEdges(t, tb)
+ tb.fx.srv.cfg.AppRegions = true
+ c, csrf := signInAs(t, tb.fx, "paul@keymail.dev", "code-labels-create")
+ status, _, _ := postForm(t, c, tb.fx.ts.URL+"/a/"+tb.sqid+"/apps/new",
+ url.Values{"csrf": {csrf}, "name": {"cart"}, "region": {"uk"}})
+ if status != http.StatusSeeOther {
+ t.Fatalf("create = %d", status)
+ }
+ events, err := tb.fx.st.Events(5151, "cart", 5)
+ if err != nil || len(events) == 0 || !strings.Contains(events[0].Detail, "created app cart in London (uk)") {
+ t.Fatalf("activity = %+v %v", events, err)
+ }
+}
+
+func TestFleetPagesUseTheBoxMap(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, false)
+ publishRegionEdges(t, tb)
+ if err := tb.fx.st.SetOperator("paul@keymail.dev", true); err != nil {
+ t.Fatal(err)
+ }
+ fleet := status.Fleet{GeneratedAt: time.Now(),
+ Boxes: []status.FleetBox{{Label: status.Label("box-b"), Region: "eu-ish"}, {Label: "box-unknown", Region: "far away"}},
+ Apps: []status.FleetApp{{Name: "shop", Instances: 1, Healthy: true, Channel: "stable", Version: "v3"}}}
+ raw, _ := json.Marshal(fleet)
+ if _, err := tb.fx.rel.Put(context.Background(), "status/fleet.json", raw, ""); err != nil {
+ t.Fatal(err)
+ }
+ page := tb.textAt(t, "/fleet")
+ for _, want := range []string{"London (uk)", "far away", "Dublin (ie)"} { // box B, an unknown box's word, shop's stored region
+ if !strings.Contains(page, want) {
+ t.Fatalf("platform fleet page lacks %q:\n%s", want, page)
+ }
+ }
+ if acct := tb.text(t, "/fleet"); !strings.Contains(acct, "London (uk)") || !strings.Contains(acct, "far away") {
+ t.Fatalf("account fleet chips:\n%s", acct)
+ }
+}
+
+// textAt GETs a path outside the account prefix.
+func (tb *twoBoxes) textAt(t *testing.T, path string) string {
+ t.Helper()
+ status, loc, body := get(t, tb.browser, tb.fx.ts.URL+path)
+ if status != http.StatusOK {
+ t.Fatalf("GET %s = %d -> %q", path, status, loc)
+ }
+ return html.UnescapeString(body)
+}
diff --git a/internal/console/server.go b/internal/console/server.go
index 90b950cfd..fe7ea6480 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -55,6 +55,7 @@ import (
"github.com/carlosframework/platform/internal/plans"
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/publicrelease"
+ "github.com/carlosframework/platform/internal/regionlabel"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/status"
@@ -2110,6 +2111,12 @@ type page struct {
// yet, no bucket handle, or a boxes read that failed are all "no detail
// to show", never a reason to fail the page.
Hosts []HostRow
+ // BoxRegions maps a box label to its region label for the fleet pages;
+ // a box absent from it keeps its own STATUS_BOX_REGION word.
+ // FleetAppRegions maps an app name on the platform fleet page to its
+ // stored region's label; absent shows a dash.
+ BoxRegions map[string]string
+ FleetAppRegions map[string]string
// /fleet/metrics: the operator dashboard (Task 11), both from LoadMetrics
// (metricsview.go) and both nil-safe to render — no boxes and no firing
@@ -3316,7 +3323,31 @@ func (s *Server) handleFleet(w http.ResponseWriter, r *http.Request) {
log.Printf("console: fleet hosts: %v", err)
hosts = nil
}
- p := page{Title: "Fleet status", Address: addr, CSRF: raw, Fleet: f, Hosts: hosts}
+ // Region labels (spec §5 rows 10, 11): box regions from the cached name
+ // map, each app's stored region from SQLite and one registry listing.
+ labels := map[string]string{}
+ if f != nil {
+ for _, b := range f.Boxes {
+ if _, name := s.boxRegion(b.Label); name != "" {
+ labels[b.Label] = name
+ }
+ }
+ }
+ for _, h := range hosts {
+ if _, name := s.boxRegion(h.Label); name != "" {
+ labels[h.Label] = name
+ }
+ }
+ var appRegions map[string]string
+ if f != nil {
+ names := make([]string, 0, len(f.Apps))
+ for _, a := range f.Apps {
+ names = append(names, a.Name)
+ }
+ appRegions = s.fleetAppRegions(names)
+ }
+ p := page{Title: "Fleet status", Address: addr, CSRF: raw, Fleet: f, Hosts: hosts,
+ BoxRegions: labels, FleetAppRegions: appRegions}
if s.storeOperator(addr) {
p.StoreQueueUnknown = true
if s.cfg.Releases != nil {
@@ -3958,22 +3989,25 @@ func (s *Server) handleAppInstances(w http.ResponseWriter, r *http.Request) {
if warn != "" && p.FlashErr == "" {
p.FlashErr = warn
}
- // The app-region note (spec §10). Available is nil for a fleet app and
- // for a policy, edges or stored region that could not be read, so those
- // show nothing: unreadable never reads as available. Pooled is excluded
- // by name.
- if d := s.appDefault(r.Context(), acct, p.AppName); d.Available != nil && d.Reason != "pooled" {
+ // The app-region note (spec §10; region labels §5 row 5, labels 9):
+ // shown whenever the stored region and where a create lands were read,
+ // with the label. Available is nil for a fleet app and for a policy,
+ // edges or stored region that could not be read, so those show
+ // nothing: unreadable never reads as available.
+ if d := s.appDefault(r.Context(), acct, p.AppName); d.Available != nil {
+ home := regionlabel.ForCode("", s.regionHome(), s.regionNames()).Text
switch {
+ case d.Reason == "pooled" && *d.Available:
+ // A pooled create lands on the home, not the stored region.
+ p.RegionLine = fmt.Sprintf(regionLabelCopy.PooledStart, home)
+ case d.Reason == "pooled":
+ // Known, and refused: the manifest's allow-list leaves the home
+ // out (regiondefault.go). Said, as C8 is.
+ p.RegionLine, p.RegionLineWarn = fmt.Sprintf(regionLabelCopy.PooledCant, home), true
case !*d.Available:
- p.RegionLine, p.RegionLineWarn = fmt.Sprintf(regionCopy.CantStart, d.Name), true
- case d.Region != s.cfg.HomeRegion:
- p.RegionLine = fmt.Sprintf(regionCopy.StartsIn, d.Name)
+ p.RegionLine, p.RegionLineWarn = fmt.Sprintf(regionCopy.CantStart, d.Label), true
default:
- // A home app is told where it starts only when the home has a
- // sibling to be told apart from.
- if files, err := s.liveEdges(r.Context()); err == nil && eligibleCount(s.regionCands(files)) >= 2 {
- p.RegionLine = fmt.Sprintf(regionCopy.StartsIn, d.Name)
- }
+ p.RegionLine = fmt.Sprintf(regionCopy.StartsIn, d.Label)
}
}
// The empty state keys off the app's UNFILTERED rows, not the filtered
@@ -4742,8 +4776,7 @@ func (s *Server) handleNewApp(w http.ResponseWriter, r *http.Request) {
detail := "created app " + name
if s.appRegionsOn() {
region, _, _ := s.store.AppRegion(acct.ID, name)
- files, _ := s.liveEdges(r.Context())
- detail = fmt.Sprintf(regionCopy.AuditCreated, name, s.placeOf(region, s.regionCands(files)))
+ detail = fmt.Sprintf(regionCopy.AuditCreated, name, regionlabel.ForCode(region, s.regionHome(), s.regionNames()).Text)
}
s.audit(acct, name, addr, "create", detail)
s.setFlash(w, "ok", "Created app "+name+" — it's yours.")
diff --git a/internal/console/store.go b/internal/console/store.go
index 0ec22d727..ede32b19b 100644
--- a/internal/console/store.go
+++ b/internal/console/store.go
@@ -2016,6 +2016,42 @@ WHERE a.deleted_at = 0 ORDER BY a.sqid, p.app`)
return scanAppRows(rows)
}
+// namedAppPlace is one live app holding a name, with its stored region and
+// placement: the platform fleet page's app table, whose rows name apps but
+// not their accounts.
+type namedAppPlace struct {
+ AccountID int64
+ Sqid, App, Region, Placement string
+}
+
+// LivePlacesNamed lists every live app holding one of names, across
+// accounts.
+func (s *Store) LivePlacesNamed(names []string) ([]namedAppPlace, error) {
+ if len(names) == 0 {
+ return nil, nil
+ }
+ args := make([]any, len(names))
+ for i, n := range names {
+ args[i] = n
+ }
+ rows, err := s.db.Query(`SELECT a.id, a.sqid, p.app, p.region, p.placement FROM apps p
+JOIN accounts a ON a.id = p.account_id
+WHERE p.deleted_at = 0 AND p.app IN (?`+strings.Repeat(",?", len(names)-1)+`) ORDER BY a.sqid, p.app`, args...)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var out []namedAppPlace
+ for rows.Next() {
+ var r namedAppPlace
+ if err := rows.Scan(&r.AccountID, &r.Sqid, &r.App, &r.Region, &r.Placement); err != nil {
+ return nil, err
+ }
+ out = append(out, r)
+ }
+ return out, rows.Err()
+}
+
// AppAccounts lists the accounts that claim an app NAME, ascending. Usually
// one; several is legitimate (names are unique per account, not globally) and
// is what makes MoveApp require an explicit source.
diff --git a/internal/console/templates/app_instances.html b/internal/console/templates/app_instances.html
index df9d52c5f..f49ec0405 100644
--- a/internal/console/templates/app_instances.html
+++ b/internal/console/templates/app_instances.html
@@ -69,7 +69,7 @@ against that copy's own peak.</p>
<option value=""{{if not .AppPlacement}} selected{{end}}>Shared fleet</option>
{{range .OwnedFleetNames}}<option value="fleet/{{.}}"{{if eq (printf "fleet/%s" .) $.AppPlacement}} selected{{end}}>fleet/{{.}}</option>{{end}}
</select>
- <button type="submit" class="btn-sm">Move</button>
+ <button type="submit" class="btn-sm">{{.RegionLabelCopy.ChangeFleet}}</button>
</form>
<p class="small">Moving changes where this app <em>serves</em>. Data does not move:
hibernated instance state stays in the old placement's bucket.</p>
diff --git a/internal/console/templates/fleet.html b/internal/console/templates/fleet.html
index 956d1f467..5a40d0d57 100644
--- a/internal/console/templates/fleet.html
+++ b/internal/console/templates/fleet.html
@@ -36,7 +36,7 @@
<div class="tablewrap">
<table>
<tr>
- <th>Label</th><th>Region</th><th>Load</th>
+ <th>Label</th><th>{{$.RegionCopy.PickerLabel}}</th><th>Load</th>
<th>Static</th><th>Resident</th><th>Hibernating</th><th>Awake</th><th>Asleep</th>
<th>Adoption</th>
<th>Config sync</th>
@@ -45,7 +45,7 @@
{{range .Fleet.Boxes}}
<tr>
<td>{{if .Name}}{{.Name}} <span class="small">{{.Label}}</span>{{else}}{{.Label}}{{end}}</td>
- <td>{{emptyOrDash .Region}}</td>
+ <td>{{with index $.BoxRegions .Label}}{{.}}{{else}}{{emptyOrDash .Region}}{{end}}</td>
<td>{{strOrDash .Load}}</td>
<td>{{.Routes.Static}}</td>
<td>{{.Routes.Resident}}</td>
@@ -65,10 +65,11 @@
{{if .Fleet.Apps}}
<div class="tablewrap">
<table>
- <tr><th>Name</th><th>Instances</th><th>Healthy</th><th>Channel</th><th>Version</th></tr>
+ <tr><th>Name</th><th>{{$.RegionCopy.PickerLabel}}</th><th>Instances</th><th>Healthy</th><th>Channel</th><th>Version</th></tr>
{{range .Fleet.Apps}}
<tr>
<td>{{.Name}}</td>
+ <td>{{with index $.FleetAppRegions .Name}}{{.}}{{else}}—{{end}}</td>
<td>{{.Instances}}</td>
<td>{{if .Healthy}}healthy{{else}}unhealthy{{end}}</td>
<td>{{.Channel}}</td>
@@ -107,7 +108,7 @@
{{range .Hosts}}
<tr>
<td>{{if .Name}}{{.Name}} <span class="small">{{.Label}}</span>{{else}}{{.Label}}{{end}}</td>
- <td>{{emptyOrDash .Region}}</td>
+ <td>{{with index $.BoxRegions .Label}}{{.}}{{else}}{{emptyOrDash .Region}}{{end}}</td>
{{if .Metrics}}
<td>{{emptyOrDash .Metrics.Release}}</td>
<td>{{emptyOrDash .Metrics.Tunnel}}</td>