carlos / platform Public

region labels: the account app list, overview, Settings and Deployments (plan 1 task 7)

The store-call budget test was watched to fail with a probe read in appPage.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 251e62a7898cec9325d92c7f0eee1e6e1a74f834 parent c52759a
7 files changed, +152 −3
  • internal/console/deployments.go +20 −0
  • internal/console/regionlabels_test.go +101 −0
  • internal/console/server.go +16 −1
  • internal/console/templates/app_deployments.html +1 −1
  • internal/console/templates/app_overview.html +5 −0
  • internal/console/templates/app_settings.html +7 −0
  • internal/console/templates/apps.html +2 −1
diff --git a/internal/console/deployments.go b/internal/console/deployments.go
index 973747de8..92a4c3d92 100644
--- a/internal/console/deployments.go
+++ b/internal/console/deployments.go
@@ -3,6 +3,7 @@ package console
import (
"net/http"
"sort"
+ "strings"
)
type deploymentTarget struct {
@@ -13,6 +14,8 @@ type deploymentTarget struct {
Total int
Unknown int
Versions []deploymentObservedVersion
+ // Regions counts the target's instances by region label (RC-20).
+ Regions []regionCount
}
type deploymentObservedVersion struct {
Version string
@@ -38,6 +41,7 @@ func assembleDeploymentTargets(view *AppView, account string) []deploymentTarget
groups[ch.Name] = &deploymentTarget{Channel: ch.Name, Target: ch.Version, TargetErr: ch.Err, HasHistory: ch.HasHistory}
}
versions := map[string]map[string]int{}
+ regions := map[string]map[string]int{}
for _, rt := range view.Routes {
if rt.Account != account || rt.Platform {
continue
@@ -51,6 +55,12 @@ func assembleDeploymentTargets(view *AppView, account string) []deploymentTarget
}
group := groups[ch]
group.Total++
+ if rt.Region.Text != "" {
+ if regions[ch] == nil {
+ regions[ch] = map[string]int{}
+ }
+ regions[ch][rt.Region.Text]++
+ }
if (rt.Kind != "" && rt.Kind != "instance") || rt.Version == "" {
group.Unknown++
continue
@@ -76,11 +86,21 @@ func assembleDeploymentTargets(view *AppView, account string) []deploymentTarget
for _, v := range vs {
group.Versions = append(group.Versions, deploymentObservedVersion{Version: v, Count: versions[name][v]})
}
+ group.Regions = sortedCounts(regions[name])
out = append(out, *group)
}
return out
}
+// RegionsText is RC-20: "3 in Dublin (ie)", joined with ", ", "" with none.
+func (d deploymentTarget) RegionsText() string {
+ parts := make([]string, 0, len(d.Regions))
+ for _, c := range d.Regions {
+ parts = append(parts, c.InLine())
+ }
+ return strings.Join(parts, regionLabelCopy.CountJoin)
+}
+
func releaseBackTab(r *http.Request) string {
switch r.FormValue("back") {
case "releases":
diff --git a/internal/console/regionlabels_test.go b/internal/console/regionlabels_test.go
index 09be06df5..42d3f4649 100644
--- a/internal/console/regionlabels_test.go
+++ b/internal/console/regionlabels_test.go
@@ -2,12 +2,14 @@ package console
import (
"context"
+ "errors"
"html"
"strings"
"testing"
"time"
"github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/status"
)
@@ -92,3 +94,102 @@ func TestRegionLabelsBeforeTheMapIsRead(t *testing.T) {
t.Fatalf("before a read the label must be the code:\n%s", running)
}
}
+
+func TestRegionLabelsOnAccountOverviewSettingsDeployments(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, true)
+ now := time.Now()
+ if _, err := tb.fx.st.CreateAppInRegion(5151, "blog", "paul@keymail.dev", "uk", "timezone", now); err != nil {
+ t.Fatal(err)
+ }
+ publishRegionEdges(t, tb)
+
+ home := tb.text(t, "/")
+ for _, want := range []string{"Region</th>", "Dublin (ie)", "also in London (uk): 1 instance", "London (uk)"} {
+ if !strings.Contains(home, want) {
+ t.Fatalf("account app list lacks %q:\n%s", want, home)
+ }
+ }
+ ov := tb.text(t, "/apps/shop")
+ for _, want := range []string{"<h2>Region</h2>", "Dublin (ie)", "also in London (uk): 1 instance"} {
+ if !strings.Contains(ov, want) {
+ t.Fatalf("overview lacks %q:\n%s", want, ov)
+ }
+ }
+ if st := tb.text(t, "/apps/shop/settings"); !strings.Contains(st, "This app's region is Dublin (ie).") ||
+ !strings.Contains(st, "See Running for where new instances start.") {
+ t.Fatalf("Settings lacks the region section:\n%s", st)
+ }
+ if st := tb.text(t, "/apps/blog/settings"); !strings.Contains(st, "This app's region is London (uk).") ||
+ !strings.Contains(st, "From your timezone when the app was created.") {
+ t.Fatalf("blog's Settings lacks its region and source:\n%s", st)
+ }
+ if dep := tb.text(t, "/apps/shop/deployments"); !strings.Contains(dep, "1 in Dublin (ie), 1 in London (uk)") {
+ t.Fatalf("Deployments lacks the regions with the count:\n%s", dep)
+ }
+}
+
+// TestDeploymentsNameTheOneRegion (labels 9): one region still says where.
+func TestDeploymentsNameTheOneRegion(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, false)
+ publishRegionEdges(t, tb)
+ if dep := tb.text(t, "/apps/shop/deployments"); !strings.Contains(dep, "1 in London (uk)") {
+ t.Fatalf("Deployments with one region:\n%s", dep)
+ }
+}
+
+// TestLegacyFleetPlacementOnPages (labels R3-3): empty store placement,
+// rows carrying fleet/private.
+func TestLegacyFleetPlacementOnPages(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, false)
+ if _, err := tb.fx.st.CreateAppIn(5151, "legacy", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ regA, err := registry.Open(tb.fx.regPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := regA.Upsert(registry.Route{Host: "legacy.shop.example.com", Kind: "instance", App: "legacy",
+ Account: tb.sqid, Region: "fleet/private"}); err != nil {
+ t.Fatal(err)
+ }
+ publishRegionEdges(t, tb)
+ if home := tb.text(t, "/"); !strings.Contains(home, "fleet private") {
+ t.Fatalf("account app list:\n%s", home)
+ }
+ if ov := tb.text(t, "/apps/legacy"); !strings.Contains(ov, "fleet private") {
+ t.Fatalf("overview:\n%s", ov)
+ }
+ if st := tb.text(t, "/apps/legacy/settings"); !strings.Contains(st, "This app runs on your fleet private.") {
+ t.Fatalf("Settings:\n%s", st)
+ }
+}
+
+// TestStoredRegionUnknownOnPages (spec §3.4): a stored region that cannot be
+// read is a dash in the account list and the overview tile, and Settings
+// says it could not read where the app runs; never the home, never a stale
+// guess. A registry that cannot be read fails these pages in Assemble before
+// any label, exactly as at the base (Declined plan findings, #2); /list's
+// dash for an unreadable registry is Task 8's TestAppListCarriesStoredRegions.
+func TestStoredRegionUnknownOnPages(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.setUp(t, true)
+ publishRegionEdges(t, tb)
+ tb.fx.srv.appRegionOf = func(int64, string) (string, string, error) {
+ return "", "", errors.New("database is locked")
+ }
+ home := tb.text(t, "/")
+ if !strings.Contains(home, "Region</th>") || strings.Contains(home, "Dublin (ie)") || strings.Contains(home, "also in") {
+ t.Fatalf("account list with the stored region unread:\n%s", home)
+ }
+ ov := tb.text(t, "/apps/shop")
+ if !strings.Contains(ov, "<h2>Region</h2>\n <p class=\"tile-value\">—</p>") {
+ t.Fatalf("overview tile with the stored region unread:\n%s", ov)
+ }
+ st := tb.text(t, "/apps/shop/settings")
+ if !strings.Contains(st, "Could not read where this app runs.") || strings.Contains(st, "This app's region is") {
+ t.Fatalf("Settings with the stored region unread:\n%s", st)
+ }
+}
diff --git a/internal/console/server.go b/internal/console/server.go
index b82e24a37..90b950cfd 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -1957,6 +1957,11 @@ type page struct {
// §10); "" shows nothing. RegionLineWarn marks C8.
RegionLine string
RegionLineWarn bool
+ // StoredRegion is the app's stored region or fleet (regionfacts.go),
+ // filled by appPage for every app tab; StoredElsewhere is RC-15's
+ // counts from the rows the page holds.
+ StoredRegion appRegionFacts
+ StoredElsewhere []regionCount
InstanceDetail *instanceDetail
InstanceGroups []instanceGroup
@@ -2338,6 +2343,10 @@ type appRow struct {
VerdictLabel string // Deployed | Needs attention | Not deployed yet | Can't tell right now
Deployment DeploymentStatus
CanaryN int // count of canary/* channels
+ // Region is the app's stored region or fleet (regionfacts.go) and
+ // Elsewhere RC-15's counts of its instances in other regions.
+ Region appRegionFacts
+ Elsewhere []regionCount
}
func (s *Server) render(w http.ResponseWriter, status int, name string, p page) {
@@ -3447,7 +3456,11 @@ func (s *Server) handleAccountHome(w http.ResponseWriter, r *http.Request) {
return
}
for _, v := range views {
- p.Apps = append(p.Apps, summarize(v, acct.Sqid))
+ row := summarize(v, acct.Sqid)
+ // Assemble listed the registry: its rows give the legacy fleet.
+ row.Region = s.regionFactsFor(acct, v.App, v.routeFleet, true)
+ row.Elsewhere = elsewhereCounts(v.Routes, acct.Sqid, row.Region)
+ p.Apps = append(p.Apps, row)
}
}
// The Trash link, and only when there is something in it. Best-effort: a
@@ -3619,6 +3632,8 @@ func (s *Server) appPage(w http.ResponseWriter, r *http.Request, tab string) (pa
p.ActiveTab = tab
p.ActiveNav = "apps"
p.Detail = &views[0]
+ p.StoredRegion = s.regionFactsFor(acct, app, views[0].routeFleet, true)
+ p.StoredElsewhere = elsewhereCounts(views[0].Routes, acct.Sqid, p.StoredRegion)
end := perf.Span(r, "db")
life, err := s.store.AppLife(acct.ID, app)
end()
diff --git a/internal/console/templates/app_deployments.html b/internal/console/templates/app_deployments.html
index 61cfebdfd..314ff3bb2 100644
--- a/internal/console/templates/app_deployments.html
+++ b/internal/console/templates/app_deployments.html
@@ -18,7 +18,7 @@
<td><code>{{.Channel}}</code></td>
<td>{{if .TargetErr}}Can't tell right now{{else if .Target}}<a href="{{$.Nav}}/apps/{{$.AppName}}/releases#version-{{.Target}}"><code>{{.Target}}</code></a>{{else}}{{$.DeploymentsCopy.NoTarget}}{{end}}</td>
<td>{{range .Versions}}<div>{{.Count}} × <a href="{{$.Nav}}/apps/{{$.AppName}}/releases#version-{{.Version}}"><code>{{.Version}}</code></a></div>{{end}}{{if .Unknown}}<div>{{.Unknown}} × —</div>{{end}}{{if eq .Total 0}}—{{end}}</td>
- <td>{{.Total}} <a href="{{$.Nav}}/apps/{{$.AppName}}/instances?channel={{.Channel}}">{{$.DeploymentsCopy.Instances}}</a></td>
+ <td>{{.Total}} <a href="{{$.Nav}}/apps/{{$.AppName}}/instances?channel={{.Channel}}">{{$.DeploymentsCopy.Instances}}</a>{{with .RegionsText}}<br><span class="small">{{.}}</span>{{end}}</td>
<td>{{if and $.CanPromote .HasHistory (not .TargetErr) (or $.Detail.Pipeline $.IsOwner (ne .Channel "stable"))}}
<form method="post" action="{{$.Base}}/apps/{{$.AppName}}/rollback">
<input type="hidden" name="csrf" value="{{$.CSRF}}"><input type="hidden" name="channel" value="{{.Channel}}"><input type="hidden" name="back" value="deployments">
diff --git a/internal/console/templates/app_overview.html b/internal/console/templates/app_overview.html
index 3654ded31..3a0c3fc66 100644
--- a/internal/console/templates/app_overview.html
+++ b/internal/console/templates/app_overview.html
@@ -51,6 +51,11 @@
<p class="tile-value">{{.DomainTotal}}</p>
<p class="tile-detail">{{if eq .DomainTotal 0}}one appears after your first deploy{{else if .DomainAttention}}<span class="error">{{.DomainAttention}} need{{if eq .DomainAttention 1}}s{{end}} attention</span>{{else if .DomainUnknown}}no data right now{{else}}DNS &amp; certs OK{{end}}</p>
</a>
+ <a class="tile" href="{{$.Nav}}/apps/{{$.AppName}}/settings">
+ <h2>{{$.RegionCopy.PickerLabel}}</h2>
+ <p class="tile-value">{{if $.StoredRegion.Known}}{{$.StoredRegion.Text}}{{else}}—{{end}}</p>
+ <p class="tile-detail">{{range $i, $c := $.StoredElsewhere}}{{if $i}} · {{end}}{{$c.Line}}{{end}}</p>
+ </a>
<a class="tile" href="{{$.Nav}}/apps/{{$.AppName}}/releases">
<h2>{{$.DeploymentsCopy.History}}</h2>
<p class="tile-value">{{.ReleaseCount}}{{if .ReleasesCapped}}+{{end}}</p>
diff --git a/internal/console/templates/app_settings.html b/internal/console/templates/app_settings.html
index e2f3a8321..bc7647b2a 100644
--- a/internal/console/templates/app_settings.html
+++ b/internal/console/templates/app_settings.html
@@ -18,6 +18,13 @@
</div>
<p class="small"><a href="{{.Nav}}/apps/{{.Detail.App}}/settings/pipeline">Release pipeline</a> — the channels a
release moves through, and what each one takes to promote onto.</p>
+<h2>{{.RegionCopy.PickerLabel}}</h2>
+{{if .StoredRegion.Known}}
+<p>{{.StoredRegion.Sentence}}{{with .StoredRegion.SourceSentence}} {{.}}{{end}}</p>
+<p class="small"><a href="{{.Nav}}/apps/{{.Detail.App}}/instances#app-region-line">{{.RegionLabelCopy.SeeRunning}}</a></p>
+{{else}}
+<p class="small">Could not read where this app runs.</p>
+{{end}}
{{if .IsOwner}}
{{if .Settings.ControlPlane}}
<p class="small">This app is marked as the <strong>control plane</strong> — it
diff --git a/internal/console/templates/apps.html b/internal/console/templates/apps.html
index adc59fe07..1d67fa06b 100644
--- a/internal/console/templates/apps.html
+++ b/internal/console/templates/apps.html
@@ -6,11 +6,12 @@
<h1>{{.Account.Name}}</h1>
<div class="tablewrap">
<table>
- <tr><th scope="col">App</th><th scope="col">Running at</th><th scope="col">Health</th><th scope="col">{{$.StatusCopy.ObservedLabel}}</th></tr>
+ <tr><th scope="col">App</th><th scope="col">Running at</th><th scope="col">{{$.RegionCopy.PickerLabel}}</th><th scope="col">Health</th><th scope="col">{{$.StatusCopy.ObservedLabel}}</th></tr>
{{range .Apps}}
<tr>
<td><a href="{{$.Nav}}/apps/{{.App}}">{{.App}}</a></td>
<td>{{if .URL}}<a href="https://{{.URL}}">{{.URL}}</a>{{else}}—{{end}}</td>
+ <td>{{if .Region.Known}}{{.Region.Text}}{{range .Elsewhere}}<br><span class="small">{{.Line}}</span>{{end}}{{else}}—{{end}}</td>
<td><span class="chip chip-health-{{.Verdict}}">{{.VerdictLabel}}</span></td>
<td>{{if .Deployment.Mixed}}{{$.StatusCopy.Mixed}}{{else if .Deployment.UniformVersion}}<code>{{.Deployment.UniformVersion}}</code>{{else}}—{{end}}{{if .CanaryN}} <span class="chip chip-canary">{{.CanaryN}} test version{{if ne .CanaryN 1}}s{{end}}</span>{{end}}</td>
</tr>