Regional domains (#447) Task 4: RegionalTarget, regional_domains, derivation, aliases_read
- release.RegionalTarget: the one eligibility predicate (spec 7.2, D10),
for the derivation now and the edge's Reload in Task 5.
- registry: regional_domains table, ListRegional/UpsertRegional/
DeleteRegional (local and remote: RD request field, Regional response
field). UpsertRegional keeps created_at. Fingerprint hashes host,
target, account, app, region under its own section, written only when a
row exists, so a registry without regional rows digests as before.
- domains: AliasReport.Region input. A regional claim derives its apex row
and, with Wildcard and Catchall, its star row on every box, naming the
box region's placement only where it is local and RegionalTarget holds
("" otherwise), whether or not a real route holds the key; its
wildcard_domains row only where bound (same cap). Undesired rows are
deleted, except rows whose claim is listed but unread: kept, pass
incomplete. Write failures make the pass incomplete. An instance
catch-all under a regional parent is inert.
- status: Probes.AliasesRead and BoxMetrics.AliasesRead
("aliases_read"), which attaches the metrics block on its own.
- host: statusTick sets AliasesRead only when ListAliases succeeded;
aliasPassReporting takes the box region (cfg.Region at both legs).
- W2 goldens for W1 (Task 5): internal/edgesfile/testdata/
regional-box.golden.json (annie, home) and regional-box-uk.golden.json
(betty, uk), pinned by TestEdgesFileNeverPublishesRegionalNames,
rewritten with -update.
Tests: internal/release/regionaltarget_test.go,
internal/registry/regional_test.go, internal/domains/regional_derive_test.go,
internal/status/snapshot_test.go, internal/host/aliasesread_test.go,
internal/host/edgesfile_test.go.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 files changed,
+1,173
−15
internal/domains/aliases.go+133 −2internal/domains/regional_derive_test.go+376 −0internal/edgesfile/testdata/regional-box-uk.golden.json+13 −0internal/edgesfile/testdata/regional-box.golden.json+13 −0internal/host/agent.go+13 −5internal/host/aliasesread_test.go+72 −0internal/host/assetpublish_test.go+4 −4internal/host/changeindex.go+1 −1internal/host/edgesfile_test.go+141 −0internal/registry/regional_test.go+123 −0internal/registry/registry.go+112 −1internal/registry/remote_dispatch.go+8 −0internal/release/regionaltarget.go+37 −0internal/release/regionaltarget_test.go+81 −0internal/status/snapshot.go+15 −2internal/status/snapshot_test.go+31 −0
Intent
Human
<cross-session-message from="uds:/run/user/1001/cc-socks/1118974.sock" from-name="platform-01" from-mode="bypass"> v0.30.3 is done: dev and flagship boxes and both consoles run it, rolled by 11:15Z. You're free to release and roll again. The log is ~/.cache/release-v0.30.3/roll-log.md. </cross-session-message>
diff --git a/internal/domains/aliases.go b/internal/domains/aliases.go| index 6184b3420..960ac57e6 100644 |
| --- a/internal/domains/aliases.go |
| +++ b/internal/domains/aliases.go |
| @@ -158,6 +158,12 @@ func deriveInstanceAliases(claims []Claim, listed map[string]bool, routes []regi |
| if apex, held := claimed[parent]; !held || apex.Account != c.Account || apex.Pending { |
| sayInstanceCatchallOnce(c.Host, "inert: its parent "+parent+" is not claimed by account "+c.Account) |
| continue |
| + } else if apex.Regional() { |
| + // A regional parent (#447) is not held for this purpose: a name |
| + // under it would be served from whichever box has the |
| + // instance, whatever the region. |
| + sayInstanceCatchallOnce(c.Host, "inert: its parent "+parent+" is regional") |
| + continue |
| } |
| var hostsOf map[string]int |
| var unknownOf map[string]bool |
| @@ -261,6 +267,11 @@ func deriveInstanceAliases(claims []Claim, listed map[string]bool, routes []regi |
| // seconds cadence, on every serial bump — so the difference is one bucket |
| // call against one plus a GET per claim in the deployment, every few |
| // seconds, on every box. nil is legal and means today's uncached fold. |
| +// |
| +// With no report there is no Region input, so regional claims (#447) derive |
| +// as on a home-region box. A box in another region must call |
| +// ReconcileAliasesReport with AliasReport.Region set, as the agent's |
| +// aliasPassReporting does. |
| func ReconcileAliases(ctx context.Context, s release.Store, reg *registry.Registry, now func() time.Time, deploymentRoutes map[string]bool, cache *ClaimCache) error { |
| return ReconcileAliasesReport(ctx, s, reg, now, deploymentRoutes, cache, nil) |
| } |
| @@ -286,6 +297,11 @@ type AliasReport struct { |
| // map is non-nil and still used, but it may be missing the very route a |
| // claim conflicts with, so the pass cannot vouch for it. |
| DeploymentRoutesPartial bool |
| + // Region is an INPUT, set by the caller before the pass: this box's |
| + // region code (ReconcileConfig.Region, "" for the home region). A |
| + // regional claim (#447) derives its regional_domains rows for this |
| + // region's placement. |
| + Region string |
| } |
| // relevantDropped returns the hosts of the listed-but-unread claims that the |
| @@ -349,6 +365,8 @@ func relevantDropped(dropped []droppedClaim, routes []registry.Route, aliases [] |
| // - the label count for an instance catch-all failed |
| // - an alias, instance alias, catch-all alias, wildcard or path upsert failed |
| // - an alias, wildcard or path delete failed |
| +// - a regional_domains upsert or delete failed, or a regional row was kept |
| +// because its claim was listed but not read this pass |
| // - a listed claim yielded no claim and the pass cannot rule it out |
| // (relevantDropped: any read error, unparseable body or newer schema; a |
| // not-found body only when its account owns a route on this box) |
| @@ -382,6 +400,10 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry. |
| if err != nil { |
| return err |
| } |
| + existingRegional, err := reg.ListRegional() |
| + if err != nil { |
| + return err |
| + } |
| if h := relevantDropped(dropped, routes, existing); len(h) > 0 { |
| log.Printf("domains: %d claim(s) listed but unreadable this pass (e.g. %s) — the pass is incomplete", len(h), h[0]) |
| incomplete = true |
| @@ -389,6 +411,11 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry. |
| desired := map[string]bool{} |
| desiredWild := map[string]registry.WildcardDomain{} |
| desiredPaths := map[string]registry.RoutePath{} // key: host + "\x00" + prefix |
| + desiredRegional := map[string]registry.RegionalDomain{} |
| + boxRegion := "" |
| + if rep != nil { |
| + boxRegion = rep.Region |
| + } |
| wildCount := 0 |
| for _, c := range claims { |
| // A pending claim (#215) is a reservation by someone who has not |
| @@ -400,9 +427,21 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry. |
| if c.Pending { |
| continue |
| } |
| - // A regional claim (#447) is never a plain alias of its Route, a |
| - // wildcard parent or a prefix map: it derives nothing here. |
| + // A regional claim (#447, spec §7.2) derives regional_domains rows |
| + // and, where it is bound here, its wildcard parent; then it |
| + // continues, so the plain-alias, paths and catch-all halves below |
| + // never see it. |
| if c.Regional() { |
| + if deriveRegional(c, byHost, boxRegion, desiredRegional, now) && c.Wildcard { |
| + if wildCount >= maxWildcardDomains { |
| + log.Printf("domains: wildcard %s dropped: per-box cap %d reached", c.Host, maxWildcardDomains) |
| + } else { |
| + wildCount++ |
| + desiredWild[c.Host] = registry.WildcardDomain{ |
| + Host: c.Host, Account: c.Account, App: c.App, CreatedAt: now().Unix(), |
| + } |
| + } |
| + } |
| continue |
| } |
| // Plain alias derivation (#164): a routeless (first-route) claim is |
| @@ -697,6 +736,20 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry. |
| } |
| } |
| + // regional_domains is wholly pass-owned too, with one exception: a row |
| + // whose claim the listing shows but whose body this pass did not read |
| + // (a failed GET, an unparseable body, a not-found) is kept exactly as |
| + // it is, and the pass is incomplete. Reload judges a kept row again |
| + // against the routes it serves (spec §7.3), so keeping it never binds a |
| + // target that has stopped qualifying. |
| + unread := make(map[string]bool, len(dropped)) |
| + for _, d := range dropped { |
| + unread[d.host] = true |
| + } |
| + if writeRegional(reg, existingRegional, desiredRegional, unread) { |
| + incomplete = true |
| + } |
| + |
| // wildcard_domains is wholly pass-owned, like route_aliases. |
| existingWild, err := reg.ListWildcardDomains() |
| if err != nil { |
| @@ -754,3 +807,81 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry. |
| } |
| return nil |
| } |
| + |
| +// deriveRegional adds a regional claim's desired regional_domains rows (#447, |
| +// spec §7.2) for a box in boxRegion: the claim's host and, with Wildcard and |
| +// Catchall, "*.<host>", each naming the claim's placement for boxRegion when |
| +// that route is on this box and release.RegionalTarget accepts it, and "" |
| +// (deny here) otherwise. The rows are desired on every box, bound or not, and |
| +// whether or not a real route holds the key: the edge's Reload gives the key |
| +// a deny entry over such a route (ruling 5b), so the row is never shadowed. |
| +// |
| +// A regional claim's capabilities are fixed from its creation (ruling 6), so |
| +// the set of keys never changes: the first pass that reads the claim writes |
| +// the apex and the star together. |
| +// |
| +// It reports whether this box is bound (a target was kept). A claim host that |
| +// is not a normalised hostname, or is under the reserved sidecar suffix, |
| +// derives nothing: the key would become an edge routing key. |
| +func deriveRegional(c Claim, byHost map[string]registry.Route, boxRegion string, desired map[string]registry.RegionalDomain, now func() time.Time) (bound bool) { |
| + if n, ok := NormalizeAliasHost(c.Host); !ok || n != c.Host || strings.HasSuffix(c.Host, sidecarSuffix) { |
| + log.Printf("domains: regional %s refused: not a normalised hostname", c.Host) |
| + return false |
| + } |
| + t := c.PlacementFor(boxRegion) |
| + if rt, ok := byHost[t]; t == "" || !ok || !release.RegionalTarget(rt, c.Account, c.App, boxRegion) { |
| + t = "" |
| + } |
| + keys := []string{c.Host} |
| + if c.Wildcard && c.Catchall { |
| + keys = append(keys, "*."+c.Host) |
| + } |
| + for _, k := range keys { |
| + desired[k] = registry.RegionalDomain{ |
| + Host: k, Target: t, Account: c.Account, App: c.App, Region: boxRegion, |
| + CreatedAt: now().Unix(), |
| + } |
| + } |
| + return t != "" |
| +} |
| + |
| +// writeRegional brings regional_domains to desired: a row that differs (or is |
| +// missing) is upserted, and a row not desired is deleted unless its claim |
| +// (the row's host, or for "*.<apex>" the apex) is in unread, in which case it |
| +// is kept as it is. It reports whether the result is incomplete: a write |
| +// failed, or a row was kept. |
| +func writeRegional(reg *registry.Registry, existing []registry.RegionalDomain, desired map[string]registry.RegionalDomain, unread map[string]bool) (incomplete bool) { |
| + have := make(map[string]registry.RegionalDomain, len(existing)) |
| + for _, d := range existing { |
| + have[d.Host] = d |
| + } |
| + keys := make([]string, 0, len(desired)) |
| + for k := range desired { |
| + keys = append(keys, k) |
| + } |
| + sort.Strings(keys) |
| + for _, k := range keys { |
| + d := desired[k] |
| + if h, ok := have[k]; ok && h.Target == d.Target && h.Account == d.Account && h.App == d.App && h.Region == d.Region { |
| + continue // already the row we want: no write |
| + } |
| + if err := reg.UpsertRegional(d); err != nil { |
| + log.Printf("domains: upsert regional %s: %v", k, err) |
| + incomplete = true |
| + } |
| + } |
| + for _, d := range existing { |
| + if _, ok := desired[d.Host]; ok { |
| + continue |
| + } |
| + if unread[strings.TrimPrefix(d.Host, "*.")] { |
| + incomplete = true |
| + continue |
| + } |
| + if err := reg.DeleteRegional(d.Host); err != nil { |
| + log.Printf("domains: remove regional %s: %v", d.Host, err) |
| + incomplete = true |
| + } |
| + } |
| + return incomplete |
| +} |
diff --git a/internal/domains/regional_derive_test.go b/internal/domains/regional_derive_test.go| new file mode 100644 |
| index 000000000..2d99653d2 |
| --- /dev/null |
| +++ b/internal/domains/regional_derive_test.go |
| @@ -0,0 +1,376 @@ |
| +package domains |
| + |
| +import ( |
| + "context" |
| + "os" |
| + "reflect" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// W3 (#447, spec §7.2): the alias pass's derivation of regional_domains. |
| +// Every claim here is written by the real writer (SetClaimPlacements), and |
| +// every pass is the real ReconcileAliasesReport with the box's region as |
| +// its input. |
| + |
| +const ( |
| + rdApex = "shop.example.com" |
| + rdStar = "*.shop.example.com" |
| + rdIE = "shop-ie.example.net" |
| + rdUK = "shop-uk.example.net" |
| +) |
| + |
| +// regionalCatchall is regionalClaim with the wildcard and catch-all |
| +// capabilities, which a regional claim carries from its creation. |
| +func regionalCatchall() Claim { |
| + c := regionalClaim() |
| + c.Wildcard, c.Catchall = true, true |
| + return c |
| +} |
| + |
| +// regionalInstance adds a route that RegionalTarget accepts for the claim's |
| +// account and app in region: a ready, provisioned, socket-served instance. |
| +func regionalInstance(t *testing.T, reg *registry.Registry, host, region string, mod ...func(*registry.Route)) { |
| + t.Helper() |
| + rt := registry.Route{Host: host, Kind: "instance", Socket: "/run/carlos/" + host + ".sock", Status: "ready", |
| + Account: "bab", App: "shop", Region: region, Provisioned: true} |
| + for _, m := range mod { |
| + m(&rt) |
| + } |
| + if err := reg.Upsert(rt); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.SetProvisioned(host, rt.Provisioned); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// regionalPass runs one pass as the box in region would and returns its |
| +// report. The deployment's routes are known (an empty, read answer). |
| +func regionalPass(t *testing.T, s release.Store, reg *registry.Registry, region string, cache *ClaimCache) AliasReport { |
| + t.Helper() |
| + rep := AliasReport{Complete: true, Region: region} |
| + if err := ReconcileAliasesReport(context.Background(), s, reg, aliasNow(), map[string]bool{}, cache, &rep); err != nil { |
| + t.Fatal(err) |
| + } |
| + return rep |
| +} |
| + |
| +func regionalRows(t *testing.T, reg *registry.Registry) map[string]registry.RegionalDomain { |
| + t.Helper() |
| + rows, err := reg.ListRegional() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + out := map[string]registry.RegionalDomain{} |
| + for _, d := range rows { |
| + d.CreatedAt = 0 // not part of any decision |
| + out[d.Host] = d |
| + } |
| + return out |
| +} |
| + |
| +func wantRegionalRows(t *testing.T, reg *registry.Registry, region, target string, keys ...string) { |
| + t.Helper() |
| + want := map[string]registry.RegionalDomain{} |
| + for _, k := range keys { |
| + want[k] = registry.RegionalDomain{Host: k, Target: target, Account: "bab", App: "shop", Region: region} |
| + } |
| + if got := regionalRows(t, reg); !reflect.DeepEqual(got, want) { |
| + t.Fatalf("regional rows =\n%+v\nwant\n%+v", got, want) |
| + } |
| +} |
| + |
| +func wildcardHosts(t *testing.T, reg *registry.Registry) []string { |
| + t.Helper() |
| + rows, err := reg.ListWildcardDomains() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var out []string |
| + for _, w := range rows { |
| + out = append(out, w.Host) |
| + } |
| + return out |
| +} |
| + |
| +// A regional claim is never a plain alias of its Route, a prefix map or a |
| +// catch-all alias: even on the box that serves its bound target, the pass |
| +// writes no route_aliases and no route_paths row for it. |
| +func TestRegionalClaimDerivesNoAliasOrPathRow(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + putRegional(t, s, regionalCatchall()) |
| + reg := aliasRegWith(t) |
| + regionalInstance(t, reg, rdIE, "") |
| + if rep := regionalPass(t, s, reg, "", nil); !rep.Complete { |
| + t.Fatal("a clean pass reported incomplete") |
| + } |
| + if got := aliasMap(t, reg); len(got) != 0 { |
| + t.Fatalf("a regional claim derived alias rows: %+v", got) |
| + } |
| + paths, err := reg.ListPaths() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(paths) != 0 { |
| + t.Fatalf("a regional claim derived path rows: %+v", paths) |
| + } |
| + wantRegionalRows(t, reg, "", rdIE, rdApex, rdStar) |
| +} |
| + |
| +// Every box writes both rows for every regional claim, naming its own |
| +// region's bound host only when that route is local and RegionalTarget |
| +// holds, and "" otherwise. |
| +func TestRegionalRowOnEveryBox(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + putRegional(t, s, regionalCatchall()) |
| + |
| + home := aliasRegWith(t) |
| + regionalInstance(t, home, rdIE, "") |
| + regionalPass(t, s, home, "", nil) |
| + wantRegionalRows(t, home, "", rdIE, rdApex, rdStar) |
| + |
| + uk := aliasRegWith(t) |
| + // No local route for uk's bound host: deny. |
| + regionalPass(t, s, uk, "uk", nil) |
| + wantRegionalRows(t, uk, "uk", "", rdApex, rdStar) |
| + // The home region's target on a uk box is not uk's. |
| + regionalInstance(t, uk, rdIE, "") |
| + regionalPass(t, s, uk, "uk", nil) |
| + wantRegionalRows(t, uk, "uk", "", rdApex, rdStar) |
| + // Local but not eligible, one reason at a time. |
| + for name, mod := range map[string]func(*registry.Route){ |
| + "not ready": func(r *registry.Route) { r.Status = "starting" }, |
| + "not provisioned": func(r *registry.Route) { r.Provisioned = false }, |
| + "other region": func(r *registry.Route) { r.Region = "de" }, |
| + "other account": func(r *registry.Route) { r.Account = "zzz" }, |
| + "tcp upstream": func(r *registry.Route) { r.Socket, r.Addr = "", "127.0.0.1:9" }, |
| + } { |
| + regionalInstance(t, uk, rdUK, "uk", mod) |
| + regionalPass(t, s, uk, "uk", nil) |
| + if got := regionalRows(t, uk)[rdApex].Target; got != "" { |
| + t.Fatalf("%s: target = %q, want none", name, got) |
| + } |
| + } |
| + // Eligible: bound. |
| + regionalInstance(t, uk, rdUK, "uk") |
| + regionalPass(t, s, uk, "uk", nil) |
| + wantRegionalRows(t, uk, "uk", rdUK, rdApex, rdStar) |
| + |
| + // A box in a region the claim has no placement in denies. |
| + de := aliasRegWith(t) |
| + regionalInstance(t, de, rdUK, "uk") |
| + regionalPass(t, s, de, "de", nil) |
| + wantRegionalRows(t, de, "de", "", rdApex, rdStar) |
| +} |
| + |
| +// Ruling 6: a regional claim's capabilities are fixed, so a catch-all |
| +// claim's first derivation writes the apex and the star together, on a box |
| +// with a target and on one without. |
| +func TestRegionalCatchallDerivesStarWithApex(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + putRegional(t, s, regionalCatchall()) |
| + bound := aliasRegWith(t) |
| + regionalInstance(t, bound, rdUK, "uk") |
| + regionalPass(t, s, bound, "uk", nil) |
| + wantRegionalRows(t, bound, "uk", rdUK, rdApex, rdStar) |
| + bare := aliasRegWith(t) |
| + regionalPass(t, s, bare, "uk", nil) |
| + wantRegionalRows(t, bare, "uk", "", rdApex, rdStar) |
| + |
| + // Without the catch-all, the apex alone. |
| + s2 := release.NewDirStore(t.TempDir()) |
| + c := regionalClaim() |
| + c.Wildcard = true |
| + putRegional(t, s2, c) |
| + apexOnly := aliasRegWith(t) |
| + regionalInstance(t, apexOnly, rdUK, "uk") |
| + regionalPass(t, s2, apexOnly, "uk", nil) |
| + wantRegionalRows(t, apexOnly, "uk", rdUK, rdApex) |
| +} |
| + |
| +// notFoundKeyStore answers one listed key's read with not-found, as a claim |
| +// detached between the listing and the read does. |
| +type notFoundKeyStore struct { |
| + *release.DirStore |
| + key string |
| +} |
| + |
| +func (f notFoundKeyStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if key == f.key { |
| + return nil, "", os.ErrNotExist |
| + } |
| + return f.DirStore.Get(ctx, key) |
| +} |
| + |
| +// A claim the listing shows but whose body this pass could not read keeps |
| +// its rows exactly as they were, even though the routes would now derive |
| +// something else, and the pass says it is incomplete. |
| +func TestRegionalRowsKeptWhenClaimUnreadable(t *testing.T) { |
| + dir := release.NewDirStore(t.TempDir()) |
| + putRegional(t, dir, regionalCatchall()) |
| + for name, s := range map[string]release.Store{ |
| + "read error": unreadableKeyStore{dir, ClaimKey(rdApex)}, |
| + "not found": notFoundKeyStore{dir, ClaimKey(rdApex)}, |
| + } { |
| + for leg, cache := range map[string]*ClaimCache{"uncached": nil, "cached": {}} { |
| + t.Run(name+" "+leg, func(t *testing.T) { |
| + reg := aliasRegWith(t) |
| + regionalInstance(t, reg, rdUK, "uk") |
| + if rep := regionalPass(t, dir, reg, "uk", nil); !rep.Complete { |
| + t.Fatal("setup pass incomplete") |
| + } |
| + wantRegionalRows(t, reg, "uk", rdUK, rdApex, rdStar) |
| + // The target goes away: a pass that read the claim would |
| + // now write "" for both keys. |
| + if err := reg.Delete(rdUK); err != nil { |
| + t.Fatal(err) |
| + } |
| + if rep := regionalPass(t, s, reg, "uk", cache); rep.Complete { |
| + t.Fatal("a pass that kept unread rows reported complete") |
| + } |
| + wantRegionalRows(t, reg, "uk", rdUK, rdApex, rdStar) |
| + }) |
| + } |
| + } |
| +} |
| + |
| +// Detach: the claim is gone from the listing, so every row it derived goes |
| +// on the next pass, the wildcard parent too, and the pass is complete. |
| +func TestRegionalRowsDeletedOnDetach(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + putRegional(t, s, regionalCatchall()) |
| + reg := aliasRegWith(t) |
| + regionalInstance(t, reg, rdUK, "uk") |
| + regionalPass(t, s, reg, "uk", nil) |
| + wantRegionalRows(t, reg, "uk", rdUK, rdApex, rdStar) |
| + if got := wildcardHosts(t, reg); !reflect.DeepEqual(got, []string{rdApex}) { |
| + t.Fatalf("wildcard rows = %v", got) |
| + } |
| + deleteClaim(t, s, rdApex) |
| + if rep := regionalPass(t, s, reg, "uk", nil); !rep.Complete { |
| + t.Fatal("the detach pass reported incomplete") |
| + } |
| + if got := regionalRows(t, reg); len(got) != 0 { |
| + t.Fatalf("rows survived the detach: %+v", got) |
| + } |
| + if got := wildcardHosts(t, reg); len(got) != 0 { |
| + t.Fatalf("wildcard rows survived the detach: %v", got) |
| + } |
| +} |
| + |
| +// A real route at the apex or the star does not stop the row (ruling 5b: |
| +// Reload denies the key over the route). The routes themselves are left as |
| +// they are. |
| +func TestRegionalRowWrittenOverARealRoute(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + putRegional(t, s, regionalCatchall()) |
| + reg := aliasRegWith(t, |
| + registry.Route{Host: rdApex, Kind: "service", Addr: "127.0.0.1:9", Status: "ready"}, |
| + registry.Route{Host: rdStar, Kind: "service", Addr: "127.0.0.1:9", Status: "ready"}, |
| + ) |
| + regionalInstance(t, reg, rdUK, "uk") |
| + if rep := regionalPass(t, s, reg, "uk", nil); !rep.Complete { |
| + t.Fatal("pass incomplete") |
| + } |
| + wantRegionalRows(t, reg, "uk", rdUK, rdApex, rdStar) |
| + for _, h := range []string{rdApex, rdStar} { |
| + if rt, err := reg.Get(h); err != nil || rt == nil { |
| + t.Fatalf("route %s: %+v %v", h, rt, err) |
| + } |
| + } |
| + // The same with deploymentRoutes naming both: another box's routes do |
| + // not stop it either. |
| + rep := AliasReport{Region: "uk"} |
| + if err := ReconcileAliasesReport(context.Background(), s, reg, aliasNow(), map[string]bool{rdApex: true, rdStar: true}, nil, &rep); err != nil { |
| + t.Fatal(err) |
| + } |
| + wantRegionalRows(t, reg, "uk", rdUK, rdApex, rdStar) |
| +} |
| + |
| +// An instance catch-all whose parent is a regional claim of its own account |
| +// derives nothing: the regional parent counts as not held. The control is |
| +// the same catch-all under a single-mode parent, which derives the name. |
| +func TestInstanceCatchallUnderRegionalParentDerivesNothing(t *testing.T) { |
| + catchall := Claim{Host: "*." + rdApex, Account: "bab", App: "shop", Instances: true} |
| + |
| + control := release.NewDirStore(t.TempDir()) |
| + putClaim(t, control, Claim{Host: rdApex, Account: "bab", App: "shop-site"}) |
| + putClaim(t, control, catchall) |
| + creg := aliasRegWith(t) |
| + addInstance(t, creg, "acme.bab.carlos.example.net", "acme", "bab", "shop") |
| + regionalPass(t, control, creg, "", nil) |
| + if _, ok := aliasMap(t, creg)["acme."+rdApex]; !ok { |
| + t.Fatalf("control: the single-mode parent derived nothing: %+v", aliasMap(t, creg)) |
| + } |
| + |
| + s := release.NewDirStore(t.TempDir()) |
| + putRegional(t, s, regionalClaim()) |
| + putClaim(t, s, catchall) |
| + reg := aliasRegWith(t) |
| + addInstance(t, reg, "acme.bab.carlos.example.net", "acme", "bab", "shop") |
| + regionalPass(t, s, reg, "", nil) |
| + if got := aliasMap(t, reg); len(got) != 0 { |
| + t.Fatalf("an instance catch-all under a regional parent derived %+v", got) |
| + } |
| +} |
| + |
| +// A Wildcard regional claim's wildcard_domains row (the certificate parent) |
| +// is derived only on a box that holds the bound target. |
| +func TestRegionalWildcardRowOnlyWhereBound(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + putRegional(t, s, regionalCatchall()) |
| + bound := aliasRegWith(t) |
| + regionalInstance(t, bound, rdUK, "uk") |
| + regionalPass(t, s, bound, "uk", nil) |
| + if got := wildcardHosts(t, bound); !reflect.DeepEqual(got, []string{rdApex}) { |
| + t.Fatalf("bound box wildcard rows = %v, want [%s]", got, rdApex) |
| + } |
| + unbound := aliasRegWith(t) |
| + regionalInstance(t, unbound, rdUK, "uk", func(r *registry.Route) { r.Status = "starting" }) |
| + regionalPass(t, s, unbound, "uk", nil) |
| + if got := wildcardHosts(t, unbound); len(got) != 0 { |
| + t.Fatalf("unbound box wildcard rows = %v, want none", got) |
| + } |
| + // The target stops qualifying: the parent goes with it. |
| + if err := bound.SetStatus(rdUK, "starting"); err != nil { |
| + t.Fatal(err) |
| + } |
| + regionalPass(t, s, bound, "uk", nil) |
| + if got := wildcardHosts(t, bound); len(got) != 0 { |
| + t.Fatalf("after the target stopped qualifying wildcard rows = %v", got) |
| + } |
| + wantRegionalRows(t, bound, "uk", "", rdApex, rdStar) |
| +} |
| + |
| +// A regional row write that fails is logged and makes the pass incomplete, |
| +// as every other derived write does; the pass still returns nil. |
| +func TestRegionalRowWriteFailureIsIncomplete(t *testing.T) { |
| + for _, c := range []struct { |
| + name string |
| + inject func(e *aliasEnv) |
| + detach bool |
| + }{ |
| + {name: "upsert", inject: func(e *aliasEnv) { e.failUpsert("regional_domains", "host = '"+rdStar+"'") }}, |
| + {name: "delete", inject: func(e *aliasEnv) { e.failDelete("regional_domains", "host = '"+rdStar+"'") }, detach: true}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + e := newAliasEnv(t) |
| + putRegional(t, e.store, regionalCatchall()) |
| + if c.detach { |
| + if rep := regionalPass(t, e.store, e.reg, "uk", nil); !rep.Complete { |
| + t.Fatal("setup pass incomplete") |
| + } |
| + deleteClaim(t, e.store, rdApex) |
| + } |
| + c.inject(e) |
| + rep := AliasReport{Complete: true, Region: "uk"} |
| + err := ReconcileAliasesReport(context.Background(), e.store, e.reg, aliasNow(), known(), nil, &rep) |
| + if err != nil || rep.Complete { |
| + t.Fatalf("complete=%v err=%v, want incomplete and nil", rep.Complete, err) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/edgesfile/testdata/regional-box-uk.golden.json b/internal/edgesfile/testdata/regional-box-uk.golden.json| new file mode 100644 |
| index 000000000..52440f72b |
| --- /dev/null |
| +++ b/internal/edgesfile/testdata/regional-box-uk.golden.json |
| @@ -0,0 +1,13 @@ |
| +{ |
| + "*.shop.example.com": { |
| + "role": "wildcard", |
| + "platform": false, |
| + "wildcard": true |
| + }, |
| + "shop-uk.example.net": { |
| + "role": "home", |
| + "platform": true, |
| + "account": "abc", |
| + "app": "shop" |
| + } |
| +} |
diff --git a/internal/edgesfile/testdata/regional-box.golden.json b/internal/edgesfile/testdata/regional-box.golden.json| new file mode 100644 |
| index 000000000..7974184cf |
| --- /dev/null |
| +++ b/internal/edgesfile/testdata/regional-box.golden.json |
| @@ -0,0 +1,13 @@ |
| +{ |
| + "*.shop.example.com": { |
| + "role": "wildcard", |
| + "platform": false, |
| + "wildcard": true |
| + }, |
| + "shop-ie.example.net": { |
| + "role": "home", |
| + "platform": true, |
| + "account": "abc", |
| + "app": "shop" |
| + } |
| +} |
diff --git a/internal/host/agent.go b/internal/host/agent.go| index ec1e20c94..e7e773086 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -1169,13 +1169,17 @@ var aliasPassMu sync.Mutex |
| // running for its whole length (passBegin, passEnd), so an asset decision |
| // that overlaps it withholds rather than mixing its writes. The error is the |
| // pass's own, for the caller to log as before. |
| -func aliasPassReporting(ctx context.Context, store release.Store, reg *registry.Registry, cache *domains.ClaimCache, auth *assetAuthority) error { |
| +// |
| +// region is this box's region code (ReconcileConfig.Region, "" for the |
| +// home): a regional claim (#447) derives its regional_domains rows for this |
| +// region's placement. |
| +func aliasPassReporting(ctx context.Context, store release.Store, reg *registry.Registry, cache *domains.ClaimCache, auth *assetAuthority, region string) error { |
| aliasPassMu.Lock() |
| defer aliasPassMu.Unlock() |
| start := auth.passBegin() |
| defer auth.passEnd() |
| deploymentRoutes, routesWhole := edgesfile.DeploymentRoutesComplete(ctx, store, time.Now()) |
| - rep := domains.AliasReport{DeploymentRoutesPartial: deploymentRoutes != nil && !routesWhole} |
| + rep := domains.AliasReport{DeploymentRoutesPartial: deploymentRoutes != nil && !routesWhole, Region: region} |
| err := domains.ReconcileAliasesReport(ctx, store, reg, time.Now, deploymentRoutes, cache, &rep) |
| auth.aliasPass(start, rep) |
| return err |
| @@ -3884,7 +3888,7 @@ func instancesLoop(reg *registry.Registry, writes hostwrite.Config, bs *buildSta |
| plansPass(ctx, store, reg, os.Getenv) |
| runMovesPass(ctx, store) |
| runRunsPass(ctx) |
| - if err := aliasPassReporting(ctx, store, reg, &aliasClaimCache, boxAssetAuthority); err != nil { |
| + if err := aliasPassReporting(ctx, store, reg, &aliasClaimCache, boxAssetAuthority, cfg.Region); err != nil { |
| log.Printf("agent: instances alias pass: %v", err) |
| } |
| if !isFleetBox { |
| @@ -4475,12 +4479,16 @@ func statusTick(ctx context.Context, s release.Store, reg *registry.Registry, p |
| // snapshot (issue #151) — read fresh alongside routes above rather than |
| // folded into the caller's Probes in statusLoop, since reg is already in |
| // scope here and a failed read must not sink the whole snapshot: logged |
| - // and left nil (CollectBox already treats nil the same as "no alias rows |
| - // exist"), same best-effort shape as every other probe in this loop. |
| + // and left nil, same best-effort shape as every other probe in this loop. |
| + // AliasesRead says the read succeeded (#447, ruling 5a): nil Aliases is |
| + // "no alias rows" only with it, and a heartbeat without it is incomplete |
| + // evidence to the console. The caller's value is never trusted. |
| + p.AliasesRead = false |
| if aliases, err := reg.ListAliases(); err != nil { |
| log.Printf("agent: status tick: list aliases: %v", err) |
| } else { |
| p.Aliases = aliases |
| + p.AliasesRead = true |
| } |
| box := status.CollectBox(routes, p, now) |
diff --git a/internal/host/aliasesread_test.go b/internal/host/aliasesread_test.go| new file mode 100644 |
| index 000000000..473715192 |
| --- /dev/null |
| +++ b/internal/host/aliasesread_test.go |
| @@ -0,0 +1,72 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "database/sql" |
| + "encoding/json" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +// TestStatusTickSetsAliasesReadOnlySuccess (#447, ruling 5a): the heartbeat |
| +// statusTick writes carries "aliases_read":true only when its alias read |
| +// succeeded, even with no alias rows at all, and never when the read failed, |
| +// whatever the caller's Probes said. |
| +func TestStatusTickSetsAliasesReadOnlySuccess(t *testing.T) { |
| + path := filepath.Join(t.TempDir(), "registry.db") |
| + reg, err := registry.Open(path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { reg.Close() }) |
| + if err := reg.Upsert(registry.Route{Host: "a.example.com", Kind: "static", Status: "ready"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + store := release.NewDirStore(t.TempDir()) |
| + ctx := context.Background() |
| + key := "status/boxes/" + status.Label("test-machine") + ".json" |
| + tick := func() (string, bool) { |
| + t.Helper() |
| + if err := statusTick(ctx, store, reg, status.Probes{MachineID: "test-machine", AliasesRead: true}, false, ""); err != nil { |
| + t.Fatalf("statusTick: %v", err) |
| + } |
| + raw, _, err := store.Get(ctx, key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var box status.Box |
| + if err := json.Unmarshal(raw, &box); err != nil { |
| + t.Fatal(err) |
| + } |
| + return string(raw), box.Metrics != nil && box.Metrics.AliasesRead |
| + } |
| + |
| + if raw, read := tick(); !read { |
| + t.Fatalf("a healthy registry with no alias rows wrote no aliases_read: %s", raw) |
| + } |
| + |
| + // The alias read fails, every other read still works: the table is |
| + // dropped through a second handle on the same file. |
| + db, err := sql.Open("sqlite", path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer db.Close() |
| + if _, err := db.Exec("PRAGMA busy_timeout=5000"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := db.Exec("DROP TABLE route_aliases"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := reg.ListAliases(); err == nil { |
| + t.Fatal("ListAliases still reads after the table was dropped") |
| + } |
| + if raw, read := tick(); read || strings.Contains(raw, "aliases_read") { |
| + t.Fatalf("a failed alias read wrote aliases_read: %s", raw) |
| + } |
| +} |
diff --git a/internal/host/assetpublish_test.go b/internal/host/assetpublish_test.go| index e597e25e4..3107788e1 100644 |
| --- a/internal/host/assetpublish_test.go |
| +++ b/internal/host/assetpublish_test.go |
| @@ -370,7 +370,7 @@ func TestAssetAuthorityRecordsTheStartTime(t *testing.T) { |
| if err := reconcileSerializedAuth(context.Background(), b.recs, b.reg, b.reconcileConfig(), nil, auth); err != nil { |
| t.Fatal(err) |
| } |
| - if err := aliasPassReporting(context.Background(), b.doms, b.reg, nil, auth); err != nil { |
| + if err := aliasPassReporting(context.Background(), b.doms, b.reg, nil, auth, ""); err != nil { |
| t.Fatal(err) |
| } |
| // Records started at T0 (read 1), aliases at T0+1h (read 2): hostAt is |
| @@ -1162,7 +1162,7 @@ func (b *authorityBox) cycle() { |
| if err := reconcileSerializedAuth(ctx, b.recs, b.reg, b.reconcileConfig(), nil, b.auth); err != nil { |
| b.t.Logf("records pass: %v", err) |
| } |
| - if err := aliasPassReporting(ctx, b.doms, b.reg, nil, b.auth); err != nil { |
| + if err := aliasPassReporting(ctx, b.doms, b.reg, nil, b.auth, ""); err != nil { |
| b.t.Logf("alias pass: %v", err) |
| } |
| if err := edgesFileWriteClaims(ctx, b.base, b.reg, edgesFile{Box: "annie"}, "1.2.3.4", &b.last, false, nil, false, b.policy, nil); err != nil { |
| @@ -1494,7 +1494,7 @@ func TestAssetDecisionOverlappingAnAliasPassWithholds(t *testing.T) { |
| b.clock.advance(25 * time.Minute) |
| b.auth.recordsPass(b.clock.now(), provision.ReconcileReport{Complete: map[string]bool{b.acct + "/shop": true}}) |
| b.once(func() { |
| - if err := aliasPassReporting(ctx, b.doms, b.reg, nil, b.auth); err != nil { |
| + if err := aliasPassReporting(ctx, b.doms, b.reg, nil, b.auth, ""); err != nil { |
| t.Error(err) |
| } |
| }) |
| @@ -1530,7 +1530,7 @@ func TestAssetDecisionOverlappingAnAliasPassWithholds(t *testing.T) { |
| fired := false |
| b.once(func() { |
| fired = true |
| - if err := aliasPassReporting(ctx, b.doms, b.reg, nil, b.auth); err != nil { |
| + if err := aliasPassReporting(ctx, b.doms, b.reg, nil, b.auth, ""); err != nil { |
| t.Error(err) |
| } |
| }) |
diff --git a/internal/host/changeindex.go b/internal/host/changeindex.go| index 2e293bc84..f3c92fa8b 100644 |
| --- a/internal/host/changeindex.go |
| +++ b/internal/host/changeindex.go |
| @@ -330,7 +330,7 @@ func (l *passLegs) run(ctx context.Context, what string, keep func(registry.Rout |
| // the domain claims, not the record families, so they read the |
| // bucket. The pass's report feeds the box's domain confirmed time |
| // (edge asset cache design §4.2). |
| - if err := aliasPassReporting(ctx, l.store, l.reg, &aliasClaimCache, boxAssetAuthority); err != nil { |
| + if err := aliasPassReporting(ctx, l.store, l.reg, &aliasClaimCache, boxAssetAuthority, cfg.Region); err != nil { |
| log.Printf("agent: fast converge alias pass: %v", err) |
| } |
| mark("aliases") |
diff --git a/internal/host/edgesfile_test.go b/internal/host/edgesfile_test.go| index c16dfca27..f65e71fdd 100644 |
| --- a/internal/host/edgesfile_test.go |
| +++ b/internal/host/edgesfile_test.go |
| @@ -7,6 +7,7 @@ import ( |
| "encoding/base64" |
| "encoding/json" |
| "errors" |
| + "flag" |
| "fmt" |
| "go/ast" |
| "go/parser" |
| @@ -22,6 +23,7 @@ import ( |
| "time" |
| "github.com/carlosframework/platform/internal/appconfig" |
| + "github.com/carlosframework/platform/internal/domains" |
| "github.com/carlosframework/platform/internal/edge" |
| "github.com/carlosframework/platform/internal/edgesfile" |
| "github.com/carlosframework/platform/internal/moves" |
| @@ -2333,3 +2335,142 @@ func TestSizesAddNoBoxStoreRequests(t *testing.T) { |
| t.Errorf("a changed total made %v, want %v", got, want) |
| } |
| } |
| + |
| +// updateGoldens rewrites the regional edges-file goldens from the real |
| +// writer: go test ./internal/host/ -run TestEdgesFileNeverPublishesRegionalNames -update |
| +var updateGoldens = flag.Bool("update", false, "rewrite the regional edges-file goldens (internal/edgesfile/testdata) from the real writer") |
| + |
| +// regionalBoxGoldens are the hosts blocks the real writer publishes for each |
| +// box of the W1 scene (#447): box name, region, the bound target this box |
| +// serves, and the golden file that pins its hosts block. internal/edge's W1 |
| +// (Task 5) serves each box's file from these, rebased only to the box's EIP; |
| +// it cannot import this package to run the writer itself. |
| +var regionalBoxGoldens = []struct { |
| + box, region, target, golden string |
| +}{ |
| + {"annie", "", "shop-ie.example.net", "regional-box.golden.json"}, |
| + {"betty", "uk", "shop-uk.example.net", "regional-box-uk.golden.json"}, |
| +} |
| + |
| +// regionalEdgesHosts runs one box of the regional scene through production |
| +// wiring: the regional claim (Wildcard and Catchall, placements home -> |
| +// shop-ie.example.net and uk -> shop-uk.example.net) written by |
| +// domains.SetClaimPlacements, the agent's alias pass (aliasPassReporting) |
| +// with the box's region, then the real edges-file writer. target, when not |
| +// "", is a ready, provisioned, socket-served instance of the claim's app on |
| +// the box in its region. It returns the published hosts block raw and |
| +// parsed. |
| +func regionalEdgesHosts(t *testing.T, box, region, target string) (json.RawMessage, map[string]edgeHost) { |
| + t.Helper() |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + claim := domains.Claim{ |
| + Schema: 2, Host: "shop.example.com", Account: "abc", App: "shop", Route: "shop-ie.example.net", |
| + Wildcard: true, Catchall: true, |
| + CreatedAt: "2026-10-29T00:00:00Z", CreatedBy: "owner@example.com", |
| + Placements: []domains.Placement{ |
| + {Region: "", Host: "shop-ie.example.net"}, |
| + {Region: "uk", Host: "shop-uk.example.net"}, |
| + }, |
| + } |
| + if changed, err := domains.SetClaimPlacements(ctx, s, claim, nil, ""); err != nil || !changed { |
| + t.Fatalf("SetClaimPlacements: changed=%v err=%v", changed, err) |
| + } |
| + reg := edgesTestRegistry(t) |
| + if target != "" { |
| + if err := reg.Upsert(registry.Route{Host: target, Kind: "instance", Socket: "/run/carlos/" + target + ".sock", |
| + Status: "ready", Account: "abc", App: "shop", Region: region}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.SetProvisioned(target, true); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if err := aliasPassReporting(ctx, s, reg, nil, newAssetAuthority(nil), region); err != nil { |
| + t.Fatalf("alias pass: %v", err) |
| + } |
| + var last []byte |
| + if err := edgesFileWrite(ctx, s, reg, edgesFile{Box: box}, "1.2.3.4", &last, false); err != nil { |
| + t.Fatal(err) |
| + } |
| + body, _, err := s.Get(ctx, edgesFileKey(box)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := edgesfile.Parse(body); err != nil { |
| + t.Fatalf("the file does not parse: %v", err) |
| + } |
| + var raw struct { |
| + Hosts json.RawMessage `json:"hosts"` |
| + } |
| + if err := json.Unmarshal(body, &raw); err != nil { |
| + t.Fatal(err) |
| + } |
| + var hosts map[string]edgeHost |
| + if err := json.Unmarshal(raw.Hosts, &hosts); err != nil { |
| + t.Fatal(err) |
| + } |
| + return raw.Hosts, hosts |
| +} |
| + |
| +// TestEdgesFileNeverPublishesRegionalNames (W2, #447 spec §7.1): a box that |
| +// serves a regional claim's bound target publishes the target as a home row |
| +// and the claim's "*.<apex>" as the certificate-only wildcard entry, and |
| +// never the apex under any role nor the star under a dial-capable one. A box |
| +// without a target publishes neither name. Each bound box's hosts block is |
| +// byte for byte the golden W1 serves. |
| +func TestEdgesFileNeverPublishesRegionalNames(t *testing.T) { |
| + const apex, star = "shop.example.com", "*.shop.example.com" |
| + for _, b := range regionalBoxGoldens { |
| + t.Run(b.box, func(t *testing.T) { |
| + raw, hosts := regionalEdgesHosts(t, b.box, b.region, b.target) |
| + if h, ok := hosts[b.target]; !ok || h.Role != "home" || h.Alias { |
| + t.Fatalf("target %s = %+v %v, want a home row", b.target, h, ok) |
| + } |
| + if h, ok := hosts[apex]; ok { |
| + t.Fatalf("the regional apex is published: %+v", h) |
| + } |
| + h, ok := hosts[star] |
| + if !ok || h.Role != "wildcard" || !h.Wildcard || h.Alias || h.TargetHost != "" { |
| + t.Fatalf("%s = %+v %v, want the certificate-only wildcard entry", star, h, ok) |
| + } |
| + if len(hosts) != 2 { |
| + t.Fatalf("hosts = %+v, want the target and the wildcard entry only", hosts) |
| + } |
| + |
| + path := filepath.Join("..", "edgesfile", "testdata", b.golden) |
| + if *updateGoldens { |
| + var pretty bytes.Buffer |
| + if err := json.Indent(&pretty, raw, "", " "); err != nil { |
| + t.Fatal(err) |
| + } |
| + pretty.WriteByte('\n') |
| + if err := os.WriteFile(path, pretty.Bytes(), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + golden, err := os.ReadFile(path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var want, got bytes.Buffer |
| + if err := json.Compact(&want, golden); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := json.Compact(&got, raw); err != nil { |
| + t.Fatal(err) |
| + } |
| + if !bytes.Equal(got.Bytes(), want.Bytes()) { |
| + t.Fatalf("hosts block =\n%s\nwant (golden %s)\n%s", got.Bytes(), b.golden, want.Bytes()) |
| + } |
| + }) |
| + } |
| + t.Run("unbound", func(t *testing.T) { |
| + _, hosts := regionalEdgesHosts(t, "carol", "de", "") |
| + for _, k := range []string{apex, star} { |
| + if h, ok := hosts[k]; ok { |
| + t.Fatalf("a box with no target published %s: %+v", k, h) |
| + } |
| + } |
| + }) |
| +} |
diff --git a/internal/registry/regional_test.go b/internal/registry/regional_test.go| new file mode 100644 |
| index 000000000..fd4b42c38 |
| --- /dev/null |
| +++ b/internal/registry/regional_test.go |
| @@ -0,0 +1,123 @@ |
| +package registry |
| + |
| +import ( |
| + "reflect" |
| + "testing" |
| +) |
| + |
| +// TestRegionalDomainsTable pins the regional_domains table (#447, spec §7.2) |
| +// on a local registry and over the remote transport the root passes use: |
| +// upsert, an ordered list, a Fingerprint that moves on what the edge reads |
| +// (host, target, account, app, region) and not on created_at, and an |
| +// idempotent delete. |
| +func TestRegionalDomainsTable(t *testing.T) { |
| + local := openTestRegistry(t) |
| + t.Cleanup(func() { local.Close() }) |
| + remote, _ := remoteTestRegistry(t) |
| + for _, c := range []struct { |
| + name string |
| + reg *Registry |
| + }{{"local", local}, {"remote", remote}} { |
| + t.Run(c.name, func(t *testing.T) { regionalTableCase(t, c.reg) }) |
| + } |
| +} |
| + |
| +func regionalTableCase(t *testing.T, reg *Registry) { |
| + t.Helper() |
| + fp := func() string { |
| + t.Helper() |
| + s, err := reg.Fingerprint() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return s |
| + } |
| + list := func() []RegionalDomain { |
| + t.Helper() |
| + got, err := reg.ListRegional() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return got |
| + } |
| + empty := fp() |
| + if got := list(); len(got) != 0 { |
| + t.Fatalf("a fresh registry lists %+v", got) |
| + } |
| + |
| + star := RegionalDomain{Host: "*.shop.example.com", Target: "shop-uk.example.net", Account: "abc", App: "shop", Region: "uk", CreatedAt: 100} |
| + apex := RegionalDomain{Host: "shop.example.com", Target: "shop-uk.example.net", Account: "abc", App: "shop", Region: "uk", CreatedAt: 100} |
| + deny := RegionalDomain{Host: "cafe.example.com", Account: "abc", App: "cafe", Region: "uk", CreatedAt: 100} |
| + for _, d := range []RegionalDomain{apex, star, deny} { |
| + if err := reg.UpsertRegional(d); err != nil { |
| + t.Fatalf("UpsertRegional(%s): %v", d.Host, err) |
| + } |
| + } |
| + // Ordered by host: "*" sorts before letters. |
| + if got, want := list(), []RegionalDomain{star, deny, apex}; !reflect.DeepEqual(got, want) { |
| + t.Fatalf("ListRegional =\n%+v\nwant\n%+v", got, want) |
| + } |
| + withRows := fp() |
| + if withRows == empty { |
| + t.Fatal("Fingerprint blind to new regional_domains rows") |
| + } |
| + |
| + // A re-upsert with only a new created_at: same digest, and created_at |
| + // itself is kept (ON CONFLICT updates target, account, app, region only). |
| + again := apex |
| + again.CreatedAt = 999 |
| + if err := reg.UpsertRegional(again); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := fp(); got != withRows { |
| + t.Fatalf("Fingerprint moved on a created_at-only re-upsert: %s -> %s", withRows, got) |
| + } |
| + if got := list()[2]; got.CreatedAt != 100 { |
| + t.Fatalf("re-upsert rewrote created_at: %+v", got) |
| + } |
| + |
| + // Each field the edge reads moves the digest. |
| + for _, mod := range []struct { |
| + field string |
| + set func(*RegionalDomain) |
| + }{ |
| + {"target", func(d *RegionalDomain) { d.Target = "" }}, |
| + {"account", func(d *RegionalDomain) { d.Account = "other" }}, |
| + {"app", func(d *RegionalDomain) { d.App = "cafe" }}, |
| + {"region", func(d *RegionalDomain) { d.Region = "" }}, |
| + } { |
| + before := fp() |
| + d := apex |
| + mod.set(&d) |
| + if err := reg.UpsertRegional(d); err != nil { |
| + t.Fatal(err) |
| + } |
| + if fp() == before { |
| + t.Fatalf("Fingerprint blind to a %s change", mod.field) |
| + } |
| + got := list()[2] |
| + d.CreatedAt = 100 |
| + if got != d { |
| + t.Fatalf("after a %s change the row is %+v, want %+v", mod.field, got, d) |
| + } |
| + if err := reg.UpsertRegional(apex); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if got := fp(); got != withRows { |
| + t.Fatalf("Fingerprint after restoring the row = %s, want %s", got, withRows) |
| + } |
| + |
| + // Delete is idempotent, and removing every row restores the empty digest. |
| + for _, h := range []string{star.Host, deny.Host, apex.Host, apex.Host, "never.example.com"} { |
| + if err := reg.DeleteRegional(h); err != nil { |
| + t.Fatalf("DeleteRegional(%s): %v", h, err) |
| + } |
| + } |
| + if got := list(); len(got) != 0 { |
| + t.Fatalf("after deletes ListRegional = %+v", got) |
| + } |
| + if got := fp(); got != empty { |
| + t.Fatalf("Fingerprint after add+remove = %s, want back to %s", got, empty) |
| + } |
| +} |
diff --git a/internal/registry/registry.go b/internal/registry/registry.go| index a4df697ef..e2b435867 100644 |
| --- a/internal/registry/registry.go |
| +++ b/internal/registry/registry.go |
| @@ -782,6 +782,21 @@ CREATE TABLE IF NOT EXISTS wildcard_domains ( |
| account TEXT NOT NULL DEFAULT '', |
| app TEXT NOT NULL DEFAULT '', |
| created_at INTEGER NOT NULL DEFAULT 0 |
| +);`); err != nil { |
| + return err |
| + } |
| + // regional_domains is a derived table (#447): the alias pass writes one |
| + // row per regional claim key (the apex, and "*.<apex>" with a catch-all) |
| + // on every box, naming the bound target this box may serve it with, or |
| + // "" for none. Wholly pass-owned, additive, same shape as the two above. |
| + if _, err := r.sql.Exec(` |
| +CREATE TABLE IF NOT EXISTS regional_domains ( |
| + host TEXT PRIMARY KEY, |
| + target TEXT NOT NULL DEFAULT '', |
| + account TEXT NOT NULL DEFAULT '', |
| + app TEXT NOT NULL DEFAULT '', |
| + region TEXT NOT NULL DEFAULT '', |
| + created_at INTEGER NOT NULL DEFAULT 0 |
| );`); err != nil { |
| return err |
| } |
| @@ -3471,6 +3486,72 @@ func (r *Registry) DeleteWildcardDomain(host string) error { |
| return err |
| } |
| +// RegionalDomain is one derived row of the regional_domains table (#447, |
| +// spec §7.2): a regional claim's key (its apex, or "*.<apex>" for a |
| +// catch-all) and the target this box may serve it with. Every box writes a |
| +// row for every regional claim, whether or not it holds a target, so the |
| +// edge knows the name is regional: Target "" means deny on this box. Region |
| +// is the deriving box's region ("" for the home), the region the edge's |
| +// Reload re-checks the target against. Wholly pass-owned, like |
| +// route_aliases. |
| +type RegionalDomain struct { |
| + Host, Target, Account, App, Region string // Target "" means deny on this box |
| + CreatedAt int64 |
| +} |
| + |
| +// ListRegional returns every regional_domains row, ordered by host. |
| +func (r *Registry) ListRegional() ([]RegionalDomain, error) { |
| + if r.remote != nil { |
| + out, err := r.remote.call(nil, remoteRequest{Method: "ListRegional"}, nil) |
| + return out.Regional, err |
| + } |
| + |
| + rows, err := r.sql.Query(`SELECT host, target, account, app, region, created_at FROM regional_domains ORDER BY host`) |
| + if err != nil { |
| + return nil, err |
| + } |
| + defer rows.Close() |
| + var out []RegionalDomain |
| + for rows.Next() { |
| + var d RegionalDomain |
| + if err := rows.Scan(&d.Host, &d.Target, &d.Account, &d.App, &d.Region, &d.CreatedAt); err != nil { |
| + return nil, err |
| + } |
| + out = append(out, d) |
| + } |
| + return out, rows.Err() |
| +} |
| + |
| +// UpsertRegional inserts a row, or updates an existing one's target, |
| +// account, app and region. created_at keeps the row's first value: it is |
| +// not hashed by Fingerprint, and a pass that re-derives the same row must |
| +// not look like a change. |
| +func (r *Registry) UpsertRegional(d RegionalDomain) error { |
| + if r.remote != nil { |
| + _, err := r.remote.call(nil, remoteRequest{Method: "UpsertRegional", RD: d}, nil) |
| + return err |
| + } |
| + |
| + _, err := r.sql.Exec(` |
| +INSERT INTO regional_domains (host, target, account, app, region, created_at) |
| +VALUES (?, ?, ?, ?, ?, ?) |
| +ON CONFLICT(host) DO UPDATE SET target=excluded.target, account=excluded.account, app=excluded.app, region=excluded.region`, |
| + d.Host, d.Target, d.Account, d.App, d.Region, d.CreatedAt) |
| + return err |
| +} |
| + |
| +// DeleteRegional removes host's row. Idempotent: a host already gone is a |
| +// success, same contract as DeleteAlias. |
| +func (r *Registry) DeleteRegional(host string) error { |
| + if r.remote != nil { |
| + _, err := r.remote.call(nil, remoteRequest{Method: "DeleteRegional", Host: host}, nil) |
| + return err |
| + } |
| + |
| + _, err := r.sql.Exec(`DELETE FROM regional_domains WHERE host = ?`, host) |
| + return err |
| +} |
| + |
| // RoutePath is one derived row of the route_paths table: a leading URL path |
| // segment on Host that is served by the route at Target instead of by Host's |
| // own route. Wholly pass-owned, like route_aliases and wildcard_domains: |
| @@ -3547,7 +3628,8 @@ func (r *Registry) DeletePath(host, prefix string) error { |
| } |
| // Fingerprint summarizes the routes, fleets, fleet_boxes, route_aliases, |
| -// wildcard_domains and route_paths tables over a fresh connection, for the |
| +// wildcard_domains, route_paths and regional_domains tables over a fresh |
| +// connection, for the |
| // edge's cheap |
| // change poll. It is content-accurate: it hashes the actual VALUES of the |
| // reload-relevant columns, not a length-weighted aggregate, so two |
| @@ -3846,6 +3928,35 @@ FROM route_paths ORDER BY host, prefix`) |
| return "", err |
| } |
| + // regional_domains (#447): each row decides whether the edge serves or |
| + // denies a regional name, so a derivation change must reload the edge. |
| + // host, target, account, app and region hash; created_at does not, so a |
| + // pass that re-derives the same row reloads nothing. The section marker |
| + // is written only when a row exists: a registry with no regional rows |
| + // digests exactly as it did before the table existed (the pinned digests |
| + // in ratelimit_fingerprint_test.go), and the marker still keeps a regional |
| + // row's bytes from being read as a route_paths row's. |
| + rdrows, err := db.Query(`SELECT host, target, account, app, region FROM regional_domains ORDER BY host`) |
| + if err != nil { |
| + return "", err |
| + } |
| + defer rdrows.Close() |
| + marked := false |
| + for rdrows.Next() { |
| + var host, target, account, app, region string |
| + if err := rdrows.Scan(&host, &target, &account, &app, ®ion); err != nil { |
| + return "", err |
| + } |
| + if !marked { |
| + fmt.Fprint(h, "\x1dregional_domains\x1e") |
| + marked = true |
| + } |
| + fmt.Fprintf(h, "%s\x1f%s\x1f%s\x1f%s\x1f%s\x1e", host, target, account, app, region) |
| + } |
| + if err := rdrows.Err(); err != nil { |
| + return "", err |
| + } |
| + |
| return fmt.Sprintf("%d:%x", n, h.Sum(nil)), nil |
| } |
diff --git a/internal/registry/remote_dispatch.go b/internal/registry/remote_dispatch.go| index 3a07b1c55..5f45d3211 100644 |
| --- a/internal/registry/remote_dispatch.go |
| +++ b/internal/registry/remote_dispatch.go |
| @@ -82,6 +82,7 @@ type remoteRequest struct { |
| A RouteAlias |
| Alias string |
| W WildcardDomain |
| + RD RegionalDomain |
| P RoutePath |
| Prefix string |
| Path string |
| @@ -124,6 +125,7 @@ type remoteResponse struct { |
| Route *Route |
| Aliases []RouteAlias |
| Wildcards []WildcardDomain |
| + Regional []RegionalDomain |
| Paths []RoutePath |
| Timers []Timer |
| Number int |
| @@ -339,6 +341,12 @@ func (r *Registry) dispatchRemote(ctx context.Context, q remoteRequest, callback |
| err = r.UpsertWildcardDomain(q.W) |
| case "DeleteWildcardDomain": |
| err = r.DeleteWildcardDomain(q.Host) |
| + case "ListRegional": |
| + out.Regional, err = r.ListRegional() |
| + case "UpsertRegional": |
| + err = r.UpsertRegional(q.RD) |
| + case "DeleteRegional": |
| + err = r.DeleteRegional(q.Host) |
| case "ListPaths": |
| out.Paths, err = r.ListPaths() |
| case "UpsertPath": |
diff --git a/internal/release/regionaltarget.go b/internal/release/regionaltarget.go| new file mode 100644 |
| index 000000000..dab83e861 |
| --- /dev/null |
| +++ b/internal/release/regionaltarget.go |
| @@ -0,0 +1,37 @@ |
| +package release |
| + |
| +import "github.com/carlosframework/platform/internal/registry" |
| + |
| +// RegionalTarget is the one eligibility predicate for a regional domain's |
| +// target (#447, spec §7.2, D10): whether rt may serve a regional claim of |
| +// account and app on a box in region. The alias pass's derivation |
| +// (internal/domains) asks it when it writes a regional_domains row, and the |
| +// edge's Reload asks it again of the routes the same Reload read, so a row |
| +// kept from an earlier pass can never bind a target that has since stopped |
| +// qualifying. |
| +// |
| +// True only for a ready, provisioned instance of exactly that account and |
| +// app, served on a local unix socket (no TCP upstream, no tunnel), that is |
| +// neither a sidecar, a replica nor fleet-placed, and whose own region is the |
| +// box's. The home region is "" on both sides. |
| +func RegionalTarget(rt registry.Route, account, app, region string) bool { |
| + if rt.Status != "ready" { |
| + return false |
| + } |
| + if RouteAccount(rt) != account || rt.App != app { |
| + return false |
| + } |
| + if rt.Kind != "" && rt.Kind != "instance" { |
| + return false |
| + } |
| + if !rt.Provisioned || rt.IsSidecar() || rt.Replica { |
| + return false |
| + } |
| + if _, fleet := registry.FleetPlacement(rt.Region); fleet { |
| + return false |
| + } |
| + if rt.Tunnel != "" || rt.Socket == "" { |
| + return false |
| + } |
| + return rt.Region == region |
| +} |
diff --git a/internal/release/regionaltarget_test.go b/internal/release/regionaltarget_test.go| new file mode 100644 |
| index 000000000..50dc63186 |
| --- /dev/null |
| +++ b/internal/release/regionaltarget_test.go |
| @@ -0,0 +1,81 @@ |
| +package release |
| + |
| +import ( |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// TestRegionalTarget pins the one eligibility predicate (spec §7.2, D10): a |
| +// ready, provisioned, socket-served instance of the claim's account and app |
| +// in the box's own region is a target, and each single change makes it not |
| +// one. |
| +func TestRegionalTarget(t *testing.T) { |
| + base := func() registry.Route { |
| + return registry.Route{ |
| + Host: "shop-uk.example.net", Kind: "instance", Socket: "/run/carlos/shop-uk.sock", |
| + Status: "ready", Provisioned: true, Account: "acct", App: "shop", Region: "uk", |
| + } |
| + } |
| + if !RegionalTarget(base(), "acct", "shop", "uk") { |
| + t.Fatal("a ready provisioned socket instance in its own region is not a target") |
| + } |
| + legacy := base() |
| + legacy.Kind = "" |
| + if !RegionalTarget(legacy, "acct", "shop", "uk") { |
| + t.Fatal(`Kind "" (a legacy instance row) is not a target`) |
| + } |
| + cases := []struct { |
| + name string |
| + mod func(*registry.Route) |
| + account string |
| + app string |
| + region string |
| + }{ |
| + {name: "another account", account: "other"}, |
| + {name: "another app", app: "cafe"}, |
| + {name: "static kind", mod: func(r *registry.Route) { r.Kind = "static" }}, |
| + {name: "service kind", mod: func(r *registry.Route) { r.Kind = "service" }}, |
| + {name: "not provisioned", mod: func(r *registry.Route) { r.Provisioned = false }}, |
| + {name: "sidecar", mod: func(r *registry.Route) { r.Kind = "sidecar" }}, |
| + {name: "replica", mod: func(r *registry.Route) { r.Replica = true }}, |
| + {name: "fleet placed", mod: func(r *registry.Route) { r.Region = "fleet/x" }, region: "fleet/x"}, |
| + {name: "tunnel", mod: func(r *registry.Route) { r.Tunnel = "x" }}, |
| + {name: "addr not socket", mod: func(r *registry.Route) { r.Socket, r.Addr = "", "127.0.0.1:9" }}, |
| + {name: "starting", mod: func(r *registry.Route) { r.Status = "starting" }}, |
| + {name: "home region asked", region: "-"}, |
| + {name: "route in the home region", mod: func(r *registry.Route) { r.Region = "" }}, |
| + } |
| + for _, c := range cases { |
| + t.Run(c.name, func(t *testing.T) { |
| + rt := base() |
| + if c.mod != nil { |
| + c.mod(&rt) |
| + } |
| + account, app, region := "acct", "shop", "uk" |
| + if c.account != "" { |
| + account = c.account |
| + } |
| + if c.app != "" { |
| + app = c.app |
| + } |
| + switch c.region { |
| + case "": |
| + case "-": |
| + region = "" |
| + default: |
| + region = c.region |
| + } |
| + if RegionalTarget(rt, account, app, region) { |
| + t.Fatalf("RegionalTarget(%+v, %q, %q, %q) = true, want false", rt, account, app, region) |
| + } |
| + }) |
| + } |
| + // The home region is a region like any other: a home-region route is a |
| + // target for the home region. |
| + home := base() |
| + home.Region = "" |
| + if !RegionalTarget(home, "acct", "shop", "") { |
| + t.Fatal("a home-region route is not a target for the home region") |
| + } |
| +} |
diff --git a/internal/status/snapshot.go b/internal/status/snapshot.go| index b7c8f1abb..5335a80ff 100644 |
| --- a/internal/status/snapshot.go |
| +++ b/internal/status/snapshot.go |
| @@ -148,6 +148,11 @@ type Probes struct { |
| // here means "no aliases known this tick," identical on the wire to "no |
| // alias rows exist." |
| Aliases []registry.RouteAlias |
| + // AliasesRead is true when this tick's alias read (the reg.ListAliases() |
| + // that fills Aliases above) succeeded (#447, ruling 5a). It is what tells |
| + // "no alias rows" from "the read failed", which Aliases alone cannot: the |
| + // console takes a heartbeat without it as incomplete evidence. |
| + AliasesRead bool |
| // DBBytes sizes one route's SQLite database on local disk: the file at |
| // registry.Route.DBPath plus its -wal. CollectBox calls it for every |
| @@ -639,6 +644,11 @@ type BoxMetrics struct { |
| // present-but-empty map) when this box has no alias rows, same |
| // "absent, not empty" rule as RouteVersions. |
| Aliases map[string]AliasReading `json:"aliases,omitempty"` |
| + // AliasesRead is Probes.AliasesRead carried through: this box read its |
| + // alias rows this tick, so an absent Aliases map means it has none |
| + // (#447, ruling 5a). Omitted when the read failed, which is also how a |
| + // box on a binary that predates the field looks. |
| + AliasesRead bool `json:"aliases_read,omitempty"` |
| // RouteDBBytes is host -> on-disk size of that route's SQLite database |
| // (file plus -wal), for this box's own routes with a DBPath. It is |
| // RouteVersions' twin: hostname-keyed, so it lives in this private block |
| @@ -1115,11 +1125,13 @@ func CollectBox(routes []registry.Route, p Probes, now time.Time) Box { |
| // that predates Metrics entirely. An EMPTY (non-nil) probe or alias table |
| // counts as nothing known for exactly the same reason an empty |
| // routeVersions map does: a box with no multi-upstream route (or no |
| - // alias) has nothing to say, not something empty to say. |
| + // alias) has nothing to say, not something empty to say. The one |
| + // exception is AliasesRead (#447): a successful read of no alias rows IS |
| + // something to say, so it attaches the block on its own. |
| if p.MemTotalBytes != nil || p.MemAvailBytes != nil || p.Load1 != nil || |
| p.DiskFreeBytes != nil || p.Release != "" || p.Tunnel != "" || |
| p.InstanceID != "" || p.Platform != "" || p.SystemChannel != "" || p.System != nil || |
| - len(routeVersions) > 0 || len(routeServing) > 0 || len(aliasReadings) > 0 || len(p.Upstreams) > 0 || |
| + len(routeVersions) > 0 || len(routeServing) > 0 || len(aliasReadings) > 0 || p.AliasesRead || len(p.Upstreams) > 0 || |
| len(routeDBBytes) > 0 || p.Layout != nil || len(p.ConfigRefusals) > 0 || len(p.ReleaseRefusals) > 0 || len(p.ProofWaits) > 0 || p.Rollout != nil || p.ConfigGuard != "" || |
| p.Alerts != nil || p.GeoIP != nil || len(p.BuildStates) > 0 || p.BuildStatesErr != "" || |
| p.UpdateSettings != 0 || len(p.Updates) > 0 || len(p.Egress) > 0 || p.SizeCommittedMiB != nil { |
| @@ -1147,6 +1159,7 @@ func CollectBox(routes []registry.Route, p Probes, now time.Time) Box { |
| RouteVersions: routeVersions, |
| RouteServing: routeServing, |
| Aliases: aliasReadings, |
| + AliasesRead: p.AliasesRead, |
| // Carried through as the prober handed it over: proberSet.State |
| // already returns a fresh copy per call, so there is nothing here |
| // for a later probe tick to mutate under the marshaller. An empty |
diff --git a/internal/status/snapshot_test.go b/internal/status/snapshot_test.go| index bef0e54e3..a6eb78bff 100644 |
| --- a/internal/status/snapshot_test.go |
| +++ b/internal/status/snapshot_test.go |
| @@ -326,3 +326,34 @@ func TestCollectBoxCarriesSizeCommitted(t *testing.T) { |
| t.Fatalf("snapshot with no figure carries the key: %s", got) |
| } |
| } |
| + |
| +// TestCollectBoxCarriesAliasesRead (#447, ruling 5a): a heartbeat says |
| +// whether the box's alias read succeeded this tick, because nil Aliases is |
| +// both "no rows" and "the read failed". AliasesRead alone attaches the |
| +// metrics block, so a box with no alias rows still says it read them; false |
| +// omits the key. |
| +func TestCollectBoxCarriesAliasesRead(t *testing.T) { |
| + at := time.Date(2026, 10, 29, 9, 0, 0, 0, time.UTC) |
| + b := CollectBox(nil, Probes{AliasesRead: true}, at) |
| + if b.Metrics == nil || !b.Metrics.AliasesRead { |
| + t.Fatalf("metrics = %+v, want aliases_read", b.Metrics) |
| + } |
| + out, err := json.Marshal(b) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !strings.Contains(string(out), `"metrics":{"aliases_read":true}`) { |
| + t.Fatalf("json lacks the aliases_read-only metrics block: %s", out) |
| + } |
| + off := CollectBox(nil, Probes{Release: "v1"}, at) |
| + out, err = json.Marshal(off) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if off.Metrics == nil || off.Metrics.AliasesRead || strings.Contains(string(out), "aliases_read") { |
| + t.Fatalf("a failed read published aliases_read: %s", out) |
| + } |
| + if none := CollectBox(nil, Probes{}, at); none.Metrics != nil { |
| + t.Fatalf("an all-unknown Probes attached metrics: %+v", none.Metrics) |
| + } |
| +} |