region labels: label fields on the move, db forwarding and status doors (plan 1 task 9)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 files changed,
+266
−29
internal/console/apidbforward.go+12 −1internal/console/apiinstancemove.go+23 −11internal/console/apiinstancemove_offline.go+18 −7internal/console/apistatusinstances.go+11 −5internal/console/apistatuslayout.go+12 −4internal/console/regionfacts.go+12 −0internal/console/regionwire_test.go+156 −0internal/dbdoor/client.go+2 −1internal/dbdoor/client_test.go+14 −0internal/dbdoor/forward.go+6 −0
diff --git a/internal/console/apidbforward.go b/internal/console/apidbforward.go| index 2d4d9ccc8..c20fb0801 100644 |
| --- a/internal/console/apidbforward.go |
| +++ b/internal/console/apidbforward.go |
| @@ -26,6 +26,7 @@ import ( |
| "github.com/carlosframework/platform/internal/dbquery" |
| "github.com/carlosframework/platform/internal/dbreads" |
| "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/regionlabel" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -144,6 +145,7 @@ func (s *Server) dbResidency(w http.ResponseWriter, r *http.Request, rec provisi |
| writeJSON(w, http.StatusConflict, dbdoor.ForwardBody{ |
| Error: fmt.Sprintf(dbfUpdateCarlos, rec.Host, rec.Region), Forward: 1, |
| Region: rec.Region, ForwardOps: []string{dbreads.OpQuery, dbreads.OpPull}, |
| + RegionName: regionlabel.ForCode(rec.Region, s.regionHome(), s.regionNames()).Text, |
| }) |
| } |
| @@ -336,7 +338,16 @@ func (s *Server) admitDBRead(w http.ResponseWriter, r *http.Request) (dbReadAdmi |
| return none, "", false |
| } |
| if rec.Move != nil { |
| - jsonError(w, http.StatusConflict, fmt.Sprintf(dbfMoving, host)) |
| + // DBF-10, with the move's endpoints when the journal names them |
| + // (region labels spec §4): the CLI then says RC-32. A legacy journal |
| + // (no id) may not carry its origin, so it names neither. |
| + body := map[string]string{"error": fmt.Sprintf(dbfMoving, host)} |
| + if !rec.Move.Legacy() { |
| + home, names := s.regionHome(), s.regionNames() |
| + body["from_name"] = regionlabel.ForCode(rec.Move.From, home, names).Text |
| + body["to_name"] = regionlabel.ForCode(rec.Move.To, home, names).Text |
| + } |
| + writeJSON(w, http.StatusConflict, body) |
| return none, "", false |
| } |
| switch body.Op { |
diff --git a/internal/console/apiinstancemove.go b/internal/console/apiinstancemove.go| index 95fda4da5..5a51c6cb9 100644 |
| --- a/internal/console/apiinstancemove.go |
| +++ b/internal/console/apiinstancemove.go |
| @@ -8,6 +8,7 @@ import ( |
| "errors" |
| "fmt" |
| "github.com/carlosframework/platform/internal/park" |
| + "github.com/carlosframework/platform/internal/regionlabel" |
| "github.com/carlosframework/platform/internal/regionname" |
| "log" |
| "net/http" |
| @@ -160,12 +161,15 @@ const moveScopedHolder = "the instance keeps its data under a per-incarnation pa |
| // Instance-role token included (M18). With the switch off they are absent |
| // and the bytes are main's. |
| type moveView struct { |
| - State string `json:"state"` |
| - Target string `json:"target,omitempty"` |
| - UpdatedAt int64 `json:"updated_at,omitempty"` |
| - ID string `json:"id,omitempty"` |
| - Last *provision.MoveOutcome `json:"last,omitempty"` |
| - Protocol string `json:"protocol,omitempty"` |
| + State string `json:"state"` |
| + Target string `json:"target,omitempty"` |
| + // TargetName is Target's region label (region labels spec §4, labels |
| + // 6); the CLI prints it and keeps Target for commands. |
| + TargetName string `json:"target_name,omitempty"` |
| + UpdatedAt int64 `json:"updated_at,omitempty"` |
| + ID string `json:"id,omitempty"` |
| + Last *provision.MoveOutcome `json:"last,omitempty"` |
| + Protocol string `json:"protocol,omitempty"` |
| // Phase is the step within the state (movePhase), so a poller reads |
| // detail=1 only when the state or the phase changes (preflight L19). |
| Phase string `json:"phase,omitempty"` |
| @@ -197,9 +201,10 @@ func (s *Server) moveViewOf(rec *provision.Record) moveView { |
| v := moveView{State: "none"} |
| if rec != nil && rec.Move != nil { |
| v = moveView{ |
| - State: rec.Move.State, |
| - Target: s.homeRegionOut(rec.Move.To), |
| - UpdatedAt: rec.Move.UpdatedAt.Unix(), |
| + State: rec.Move.State, |
| + Target: s.homeRegionOut(rec.Move.To), |
| + TargetName: regionlabel.ForCode(rec.Move.To, s.regionHome(), s.regionNames()).Text, |
| + UpdatedAt: rec.Move.UpdatedAt.Unix(), |
| } |
| } |
| if s.cfg.MovesEnabled { |
| @@ -1439,8 +1444,13 @@ type moveDetailBody struct { |
| // From is the move's origin and Region the record's region now, each |
| // named as the caller names it (homeRegionOut), so the CLI's sentences |
| // (M-C1, M-C7, M-C9) never print the record's "" for the home. |
| - From string `json:"from,omitempty"` |
| - Region string `json:"region"` |
| + From string `json:"from,omitempty"` |
| + // FromName and ToName are the move's endpoints as the labels name them |
| + // (region labels spec §4, labels 6). The CLI prints them; its commands |
| + // keep From and the codes. |
| + FromName string `json:"from_name,omitempty"` |
| + ToName string `json:"to_name,omitempty"` |
| + Region string `json:"region"` |
| } |
| // moveSourceReport is the source report with its environment replaced by |
| @@ -1534,6 +1544,8 @@ func (s *Server) writeMoveDetail(w http.ResponseWriter, r *http.Request, acct *A |
| out := moveDetail{moveView: view, Detail: moveDetailBody{Move: rec.Move, Log: []string{}, Region: s.homeRegionOut(rec.Region)}} |
| if rec.Move != nil { |
| out.Detail.From = s.homeRegionOut(rec.Move.From) |
| + home, names := s.regionHome(), s.regionNames() |
| + out.Detail.FromName, out.Detail.ToName = regionlabel.ForCode(rec.Move.From, home, names).Text, regionlabel.ForCode(rec.Move.To, home, names).Text |
| } |
| if !obs.Absent && obs.Claim != nil { |
| op := obs.Claim.Op |
diff --git a/internal/console/apiinstancemove_offline.go b/internal/console/apiinstancemove_offline.go| index 1739c1776..21c2341c7 100644 |
| --- a/internal/console/apiinstancemove_offline.go |
| +++ b/internal/console/apiinstancemove_offline.go |
| @@ -20,6 +20,7 @@ import ( |
| "github.com/carlosframework/platform/internal/hostclaim" |
| "github.com/carlosframework/platform/internal/moves" |
| "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/regionlabel" |
| "github.com/carlosframework/platform/internal/release" |
| "github.com/carlosframework/platform/internal/status" |
| ) |
| @@ -78,6 +79,13 @@ func (s *Server) offlineName(code string) string { |
| return "home" |
| } |
| +// offlinePlace is a region as the offline doors' sentences name it: its |
| +// label (region labels spec §4, §5 row 26). offlineName stays the code the |
| +// views send in from and to. |
| +func (s *Server) offlinePlace(code string) string { |
| + return regionlabel.ForCode(code, s.regionHome(), s.regionNames()).Text |
| +} |
| + |
| // offlineDoor is what every door has by the time its own checks begin. |
| type offlineDoor struct { |
| acct *Account |
| @@ -382,7 +390,7 @@ func (f offlineFleet) boxesAt(code string) []edgesFilePlacementView { |
| // host, an empty target, the deployment's secrets key on the target and a |
| // published data bucket there. |
| func (s *Server) offlineSelect(ctx context.Context, f offlineFleet, host, from, to string) *offlineRefusal { |
| - fromName, toName := s.offlineName(from), s.offlineName(to) |
| + fromName, toName := s.offlinePlace(from), s.offlinePlace(to) |
| src, tgt := f.boxesAt(from), f.boxesAt(to) |
| if len(tgt) != 1 { |
| return &offlineRefusal{status: http.StatusConflict, msg: fmt.Sprintf("%s has %d boxes. an offline move needs exactly one box in the region it moves to", toName, len(tgt))} |
| @@ -559,7 +567,7 @@ func (s *Server) offlineBeginChecks(w http.ResponseWriter, r *http.Request, d of |
| // offlineStagedFor is the refusal of a start or a stage that names another |
| // region than the one the instance is staged for (MV-O179). |
| func (s *Server) offlineStagedFor(host, to string) *offlineRefusal { |
| - return &offlineRefusal{status: http.StatusConflict, msg: fmt.Sprintf("%s is staged for %s. abort the move to move it to another region", host, s.offlineName(to))} |
| + return &offlineRefusal{status: http.StatusConflict, msg: fmt.Sprintf("%s is staged for %s. abort the move to move it to another region", host, s.offlinePlace(to))} |
| } |
| // offlineStaged is the record's offline move when it is staging. |
| @@ -588,7 +596,7 @@ func (s *Server) offlineStageCoords(f offlineFleet, mv *provision.MoveState, hos |
| } |
| tgt := f.boxesAt(mv.To) |
| if len(tgt) != 1 || tgt[0].DataBucket != mv.StageBucket || tgt[0].DataBucketRegion != mv.StageRegion { |
| - return &offlineRefusal{status: http.StatusConflict, msg: fmt.Sprintf("%s now publishes a different data bucket or region from what was recorded when %s was staged. abort the move and stage it again", s.offlineName(mv.To), host)} |
| + return &offlineRefusal{status: http.StatusConflict, msg: fmt.Sprintf("%s now publishes a different data bucket or region from what was recorded when %s was staged. abort the move and stage it again", s.offlinePlace(mv.To), host)} |
| } |
| return nil |
| } |
| @@ -604,7 +612,7 @@ func (s *Server) offlineStagerPresent(f offlineFleet, mv *provision.MoveState, h |
| return nil |
| } |
| } |
| - return s.offlineStagerGone(mv.Stager, host, s.offlineName(mv.From)) |
| + return s.offlineStagerGone(mv.Stager, host, s.offlinePlace(mv.From)) |
| } |
| func (s *Server) handleAPIInstanceOfflineStart(w http.ResponseWriter, r *http.Request) { |
| @@ -688,7 +696,7 @@ func (s *Server) handleAPIInstanceOfflineStage(w http.ResponseWriter, r *http.Re |
| tgt := fleet.boxesAt(to)[0] |
| for _, b := range fleet.boxesAt(d.rec.Region) { |
| if b.DataBucket == tgt.DataBucket { |
| - jsonError(w, http.StatusConflict, fmt.Sprintf("%s publishes the same data bucket as %s. a staged copy there would replace the serving one", s.offlineName(to), s.offlineName(d.rec.Region))) |
| + jsonError(w, http.StatusConflict, fmt.Sprintf("%s publishes the same data bucket as %s. a staged copy there would replace the serving one", s.offlinePlace(to), s.offlinePlace(d.rec.Region))) |
| return |
| } |
| } |
| @@ -910,7 +918,7 @@ func offlineOpenMut(id string, now time.Time) func(*provision.Record) error { |
| // from the evidence. A refusal is the sentence the door answers and the |
| // status view shows as what the move waits for. |
| func (s *Server) offlineStepFor(ctx context.Context, d offlineDoor, mv *provision.MoveState, ev offlineEvidence, now time.Time) (offlineStep, *offlineRefusal) { |
| - host, from := d.host, s.offlineName(mv.From) |
| + host, from := d.host, s.offlinePlace(mv.From) |
| switch mv.State { |
| case provision.OfflineStaging: |
| // What start would check of the fleet now; its request checks |
| @@ -1223,7 +1231,7 @@ func (s *Server) handleAPIInstanceOfflineAbort(w http.ResponseWriter, r *http.Re |
| } |
| switch mv.State { |
| case provision.OfflineOpen, provision.OfflineFinishing: |
| - jsonError(w, http.StatusConflict, fmt.Sprintf("%s is already served from %s. move it back with a new move", d.host, s.offlineName(mv.To))) |
| + jsonError(w, http.StatusConflict, fmt.Sprintf("%s is already served from %s. move it back with a new move", d.host, s.offlinePlace(mv.To))) |
| return |
| case provision.OfflineReverting: |
| // Already reverting: nothing to write. |
| @@ -1274,6 +1282,8 @@ type offlineView struct { |
| ID string `json:"id,omitempty"` |
| From string `json:"from,omitempty"` |
| To string `json:"to,omitempty"` |
| + FromName string `json:"from_name,omitempty"` |
| + ToName string `json:"to_name,omitempty"` |
| Sealer string `json:"sealer,omitempty"` |
| Stager string `json:"stager,omitempty"` |
| Boxes []string `json:"boxes,omitempty"` |
| @@ -1353,6 +1363,7 @@ func (s *Server) offlineViewOf(ctx context.Context, rec *provision.Record) offli |
| now := time.Now() |
| v.State, v.ID = mv.State, mv.ID |
| v.From, v.To = s.offlineName(mv.From), s.offlineName(mv.To) |
| + v.FromName, v.ToName = s.offlinePlace(mv.From), s.offlinePlace(mv.To) |
| v.Sealer, v.Boxes, v.Stager = mv.Sealer, mv.Boxes, mv.Stager |
| v.NeverOffline = !mv.StartedOffline() |
| if mv.StagedAt != nil { |
diff --git a/internal/console/apistatusinstances.go b/internal/console/apistatusinstances.go| index b4c9bb1f9..5577e207c 100644 |
| --- a/internal/console/apistatusinstances.go |
| +++ b/internal/console/apistatusinstances.go |
| @@ -68,11 +68,16 @@ import ( |
| // the registry through routeForUnit — the same matching rule the economics |
| // pass attributes cost with, deliberately shared rather than reimplemented. |
| type apiStatusInstance struct { |
| - Box string `json:"box"` |
| - Unit string `json:"unit"` |
| - Host string `json:"host,omitempty"` |
| - Account string `json:"account"` |
| - App string `json:"app,omitempty"` |
| + Box string `json:"box"` |
| + Unit string `json:"unit"` |
| + // Region and RegionName are the box's placement code and label from |
| + // the console's cached name map (region labels spec §4, labels 4), |
| + // both absent for a box the map does not know. |
| + Region string `json:"region,omitempty"` |
| + RegionName string `json:"region_name,omitempty"` |
| + Host string `json:"host,omitempty"` |
| + Account string `json:"account"` |
| + App string `json:"app,omitempty"` |
| // CPU is a fraction of one core (0.017 = 1.7% of a core), Mem is bytes. |
| // Both are pointers because a sample can legitimately lack a reading — |
| // a unit seen for the first time has no CPU delta yet — and a missing |
| @@ -132,6 +137,7 @@ func (s *Server) handleAPIStatusInstances(w http.ResponseWriter, r *http.Request |
| for _, b := range boxes { |
| for _, u := range b.Units { |
| row := apiStatusInstance{Box: b.Box, Unit: u.Unit, CPU: u.CPUFrac, Mem: u.MemBytes} |
| + row.Region, row.RegionName = s.boxRegion(b.Box) |
| // unitOwner's two cases, taken off the match already in hand |
| // rather than by walking the whole route list a second time — |
| // same rule, same answers, one pass. |
diff --git a/internal/console/apistatuslayout.go b/internal/console/apistatuslayout.go| index 9471f25e4..88d85fa43 100644 |
| --- a/internal/console/apistatuslayout.go |
| +++ b/internal/console/apistatuslayout.go |
| @@ -35,10 +35,15 @@ type apiStatusLayoutRow struct { |
| // to, whether its snapshot is stale (status.BoxStale — the same rule every |
| // other private reader of status/boxes/ uses), and its rows. |
| type apiStatusLayoutBox struct { |
| - Box string `json:"box"` |
| - Mode string `json:"mode"` |
| - Stale bool `json:"stale"` |
| - Rows []apiStatusLayoutRow `json:"rows"` |
| + Box string `json:"box"` |
| + Mode string `json:"mode"` |
| + // Region and RegionName are the box's placement code and label from |
| + // the console's cached name map (region labels spec §4, labels 4), |
| + // both absent for a box the map does not know. |
| + Region string `json:"region,omitempty"` |
| + RegionName string `json:"region_name,omitempty"` |
| + Stale bool `json:"stale"` |
| + Rows []apiStatusLayoutRow `json:"rows"` |
| // Mixed is set when the box has a flat, foreign or external row |
| // beside a nested one, or under a nested intent. Each of those runs as the agent's uid in the |
| // agent's mount namespace, so it reaches every nested sibling's raw |
| @@ -113,8 +118,11 @@ func (s *Server) handleAPIStatusLayout(w http.ResponseWriter, r *http.Request) { |
| rows = append(rows, apiStatusLayoutRow{Host: host, Layout: rl.Layout, Reason: rl.Reason, Note: rl.Note}) |
| } |
| sort.Slice(rows, func(i, j int) bool { return rows[i].Host < rows[j].Host }) |
| + region, regionName := s.boxRegion(b.Label) |
| out = append(out, apiStatusLayoutBox{ |
| Box: b.Label, |
| + Region: region, |
| + RegionName: regionName, |
| Mode: b.Metrics.Layout.Mode, |
| Stale: status.BoxStale(b, now, status.SnapshotPeriod), |
| Rows: rows, |
diff --git a/internal/console/regionfacts.go b/internal/console/regionfacts.go| index da4f2e642..50af10db7 100644 |
| --- a/internal/console/regionfacts.go |
| +++ b/internal/console/regionfacts.go |
| @@ -175,6 +175,18 @@ func (s *Server) regionFactsFor(acct *Account, app, routeFleet string, routesOK |
| return appRegionFacts{Known: true, Label: regionlabel.ForCode(region, s.regionHome(), s.regionNames()), Source: source} |
| } |
| +// boxRegion is a box's placement as the status doors send it: its display |
| +// code and label, both "" for a box the name map does not know. |
| +func (s *Server) boxRegion(label string) (code, name string) { |
| + n := s.regionNames() |
| + c, known := n.BoxPlacement(label) |
| + if !known { |
| + return "", "" |
| + } |
| + l := regionlabel.ForCode(c, s.regionHome(), n) |
| + return l.Code, l.Text |
| +} |
| + |
| // regionCount is how many of an app's instances one label covers. |
| type regionCount struct { |
| Text string |
diff --git a/internal/console/regionwire_test.go b/internal/console/regionwire_test.go| index 08cb6c98a..b22f32f3d 100644 |
| --- a/internal/console/regionwire_test.go |
| +++ b/internal/console/regionwire_test.go |
| @@ -4,12 +4,19 @@ import ( |
| "context" |
| "encoding/json" |
| "errors" |
| + "fmt" |
| + "io" |
| "net/http" |
| + "strings" |
| "testing" |
| "time" |
| + "github.com/carlosframework/platform/internal/dbdoor" |
| + "github.com/carlosframework/platform/internal/dbreads" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/status" |
| ) |
| func decode(t *testing.T, body string, v any) { |
| @@ -222,3 +229,152 @@ func TestSidecarListCarriesLabels(t *testing.T) { |
| t.Fatalf("sidecars = %s", body) |
| } |
| } |
| + |
| +// labelMoveFixture is a console whose shop app has one non-pooled, |
| +// hibernating instance in uk (the move doors refuse a pooled or fleet |
| +// record, moveGate), the uk and au boxes published with fresh status |
| +// snapshots (the offline doors read both as complete evidence), the name map |
| +// read, an operator's CLI token, and an offline move uk -> au on the record. |
| +// It returns the fixture, the token and the instance's move URL. |
| +func labelMoveFixture(t *testing.T) (*consoleFixture, string, string) { |
| + t.Helper() |
| + fx := newConsoleFixture(t) |
| + ctx := context.Background() |
| + if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := provision.PutManifest(ctx, fx.rel, release.OpsAccount, "shop", |
| + provision.Manifest{Schema: 1, App: "shop", Domain: "shop.example.com", Channel: "stable"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + const host = "mv.shop.example.com" |
| + putShopRecord(t, fx, provision.Record{Schema: 1, Host: host, Slug: "mv", Region: "uk", Channel: "stable", CreatedAt: time.Now().UTC()}) |
| + if err := fx.st.SetOperator("paul@keymail.dev", true); err != nil { |
| + t.Fatal(err) |
| + } |
| + token := cliToken(t, fx, "paul@keymail.dev", "code-labels-move") |
| + for _, b := range []struct{ box, placement, aws string }{{"box-uk", "uk", "eu-west-2"}, {"box-au", "au", "ap-southeast-2"}} { |
| + putRegionEdges(t, fx.rel, b.box, b.placement, b.aws) |
| + if err := status.WriteBox(ctx, fx.rel, status.Box{Label: b.box, GeneratedAt: time.Now(), Metrics: &status.BoxMetrics{}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if !fx.srv.refreshRegionNames(ctx, nil, time.Now()) { |
| + t.Fatal("the region names were not read") |
| + } |
| + if _, err := provision.SetRecordMove(ctx, fx.rel, release.OpsAccount, "shop", host, |
| + provision.OfflineStart(labelMoveID, "uk", "au", "ops@example.com", time.Now())); err != nil { |
| + t.Fatal(err) |
| + } |
| + return fx, token, instancesURL(fx, release.OpsAccount, "shop") + "/" + host + "/move" |
| +} |
| + |
| +// TestMoveViewsCarryLabels (spec §4, labels 6): the Phase 1 view (its door |
| +// needs CARLOS_MOVES_PHASE1) and the offline view (its doors refuse while |
| +// Phase 1 is on) each carry the labels beside the codes, and the console's |
| +// own waiting sentence names the source by its label (Astra plan finding 4). |
| +func TestMoveViewsCarryLabels(t *testing.T) { |
| + fx, token, base := labelMoveFixture(t) |
| + t.Run("phase 1", func(t *testing.T) { |
| + fx.srv.cfg.MovesEnabled = true |
| + defer func() { fx.srv.cfg.MovesEnabled = false }() |
| + code, flat := getJSON(t, base, token) |
| + if code != http.StatusOK || flat["target"] != "au" || flat["target_name"] != "Sydney (au)" { |
| + t.Fatalf("flat = %d %v", code, flat) |
| + } |
| + code, det := getJSON(t, base+"?detail=1", token) |
| + d, _ := det["detail"].(map[string]any) |
| + if code != http.StatusOK || d["from"] != "uk" || d["from_name"] != "London (uk)" || d["to_name"] != "Sydney (au)" { |
| + t.Fatalf("detail = %d %v", code, det) |
| + } |
| + }) |
| + t.Run("offline", func(t *testing.T) { |
| + code, off := getJSON(t, base+"/offline", token) |
| + if code != http.StatusOK || off["from"] != "uk" || off["to"] != "au" || |
| + off["from_name"] != "London (uk)" || off["to_name"] != "Sydney (au)" { |
| + t.Fatalf("offline = %d %v", code, off) |
| + } |
| + // Stopping waits for the seal: the sentence names the source region, |
| + // whichever check it stops at ("no eligible box in <from> ..." or |
| + // "Waiting for <box> in <from> ..."), by its label. |
| + w, _ := off["waiting"].(string) |
| + if !strings.Contains(w, "London (uk)") || strings.Contains(w, " in uk ") { |
| + t.Fatalf("waiting = %q, want the source's label", w) |
| + } |
| + }) |
| +} |
| + |
| +func TestDBDoorsCarryLabels(t *testing.T) { |
| + fx := newDBFFixture(t, true) |
| + // The uk box as it publishes itself, with its AWS region. |
| + putFixtureObject(t, fx.rel, "control/edges/uk-1.json", []byte( |
| + `{"v":1,"box":"uk-1","eip":"203.0.113.10","region":"eu-west-2","placement":"uk","capabilities":["`+dbreads.Capability+`"],"hosts":{}}`)) |
| + fx.srv.refreshRegionNames(context.Background(), nil, time.Now()) |
| + |
| + status, _, body := rawReq(t, http.MethodGet, fx.listURL(), fx.member, "") |
| + var marker dbdoor.ForwardBody |
| + decode(t, body, &marker) |
| + if status != http.StatusConflict || marker.Region != "uk" || marker.RegionName != "London (uk)" || |
| + marker.Error != fmt.Sprintf(dbfUpdateCarlos, dbfHost, "uk") { |
| + t.Fatalf("marker = %d %s", status, body) |
| + } |
| + |
| + putShopRecord(t, fx.consoleFixture, provision.Record{Host: "moving.example.com", Region: "uk", CreatedAt: time.Now().UTC(), |
| + Move: &provision.MoveState{ID: "mv_x", From: "uk", To: "ie", State: provision.MovePreparing}}) |
| + good, _ := queryBody(t, "SELECT 1") |
| + res := fx.openRead(t, "moving.example.com", fx.member, good) |
| + raw, _ := io.ReadAll(res.Body) |
| + var refusal map[string]string |
| + decode(t, string(raw), &refusal) |
| + if res.StatusCode != http.StatusConflict || refusal["error"] != fmt.Sprintf(dbfMoving, "moving.example.com") || |
| + refusal["from_name"] != "London (uk)" || refusal["to_name"] != "ie" { |
| + t.Fatalf("moving refusal = %d %v", res.StatusCode, refusal) |
| + } |
| + // A legacy journal (no id) names no endpoints. |
| + putShopRecord(t, fx.consoleFixture, provision.Record{Host: "legacy.example.com", Region: "uk", CreatedAt: time.Now().UTC(), |
| + Move: &provision.MoveState{To: "ie", State: provision.MovePreparing}}) |
| + res = fx.openRead(t, "legacy.example.com", fx.member, good) |
| + raw, _ = io.ReadAll(res.Body) |
| + refusal = map[string]string{} |
| + decode(t, string(raw), &refusal) |
| + if _, has := refusal["from_name"]; has { |
| + t.Fatalf("a legacy move named its endpoints: %v", refusal) |
| + } |
| +} |
| + |
| +func TestStatusDoorsCarryLabels(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) |
| + } |
| + // box B's layout report, as its status tick writes it. |
| + b := status.CollectBox(nil, status.Probes{MachineID: "box-b", Region: "uk", Layout: &status.LayoutReport{ |
| + Mode: "flat", Rows: map[string]status.RowLayout{remoteHost: {Layout: "flat"}}}}, time.Now()) |
| + if err := status.WriteBox(context.Background(), tb.fx.rel, b); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, inst := getJSON(t, tb.fx.ts.URL+"/api/cli/status/instances", tb.token) |
| + ok := false |
| + for _, e := range inst["instances"].([]any) { |
| + m := e.(map[string]any) |
| + if m["box"] == status.Label("box-b") { |
| + ok = m["region"] == "uk" && m["region_name"] == "London (uk)" |
| + } |
| + } |
| + if !ok { |
| + t.Fatalf("status instances = %v", inst) |
| + } |
| + _, lay := getJSON(t, tb.fx.ts.URL+"/api/cli/status/layout", tb.token) |
| + ok = false |
| + for _, e := range lay["boxes"].([]any) { |
| + m := e.(map[string]any) |
| + if m["box"] == status.Label("box-b") { |
| + ok = m["region"] == "uk" && m["region_name"] == "London (uk)" |
| + } |
| + } |
| + if !ok { |
| + t.Fatalf("status layout = %v", lay) |
| + } |
| +} |
diff --git a/internal/dbdoor/client.go b/internal/dbdoor/client.go| index cd2a44225..f1009a8c9 100644 |
| --- a/internal/dbdoor/client.go |
| +++ b/internal/dbdoor/client.go |
| @@ -177,13 +177,14 @@ func doorError(res *http.Response) error { |
| Error string `json:"error"` |
| Forward int `json:"forward"` |
| Region string `json:"region"` |
| + RegionName string `json:"region_name"` |
| ForwardOps []string `json:"forward_ops"` |
| } |
| e := &DoorError{Status: res.StatusCode} |
| if json.Unmarshal(raw, &body) == nil { |
| e.Message = strings.TrimSpace(body.Error) |
| if res.StatusCode == http.StatusConflict && body.Forward == 1 && forwardRegion.MatchString(body.Region) { |
| - e.Forward = &Forward{Region: body.Region, Ops: body.ForwardOps} |
| + e.Forward = &Forward{Region: body.Region, RegionName: body.RegionName, Ops: body.ForwardOps} |
| } |
| } |
| // Seconds only (the door never sends a date), capped so a hostile or |
diff --git a/internal/dbdoor/client_test.go b/internal/dbdoor/client_test.go| index 8b3952258..84206c84c 100644 |
| --- a/internal/dbdoor/client_test.go |
| +++ b/internal/dbdoor/client_test.go |
| @@ -310,3 +310,17 @@ func TestClientCapsRetryAfter(t *testing.T) { |
| } |
| } |
| } |
| + |
| +func TestDoorErrorReadsTheRegionName(t *testing.T) { |
| + t.Parallel() |
| + err := doorError(doorResponse(http.StatusConflict, |
| + `{"error":"x","forward":1,"region":"uk","region_name":"London (uk)","forward_ops":["query"]}`)) |
| + var de *DoorError |
| + if !errors.As(err, &de) || de.Forward == nil || de.Forward.Region != "uk" || de.Forward.RegionName != "London (uk)" { |
| + t.Fatalf("%#v", err) |
| + } |
| + err = doorError(doorResponse(http.StatusConflict, `{"error":"x","forward":1,"region":"uk","forward_ops":["query"]}`)) |
| + if !errors.As(err, &de) || de.Forward == nil || de.Forward.RegionName != "" { |
| + t.Fatalf("an older console's marker: %#v", err) |
| + } |
| +} |
diff --git a/internal/dbdoor/forward.go b/internal/dbdoor/forward.go| index 75a86cfbf..1f059ebc0 100644 |
| --- a/internal/dbdoor/forward.go |
| +++ b/internal/dbdoor/forward.go |
| @@ -11,6 +11,9 @@ type ForwardBody struct { |
| Forward int `json:"forward"` |
| Region string `json:"region"` |
| ForwardOps []string `json:"forward_ops"` |
| + // RegionName is the console's label for Region (region labels spec |
| + // §4): "London (uk)". An older console sends none. |
| + RegionName string `json:"region_name,omitempty"` |
| } |
| // Forward is a DoorError's marker: where the data is, and which operations |
| @@ -18,6 +21,9 @@ type ForwardBody struct { |
| type Forward struct { |
| Region string |
| Ops []string |
| + // RegionName is the console's label for Region (region labels spec |
| + // §4); "" from an older console. Raw: a printer cleans it. |
| + RegionName string |
| } |
| // forwardRegion is dbreads.ValidRegion's shape. dbreads imports this |