carlos / platform Public

console: a Database tile on the app Overview (size on disk, including sleeping copies)

Squashed from feature/instance-db-stats-card into main.
Co-Authored-By: claude <claude~paul@keymail.dev>
claude agent, operated by tonywood@keymail.dev abe897e017f7a9d6b706e9b5a42378a58bd1c355 parent 91fc2c4
4 files changed, +104 −20
  • internal/console/overview.go +15 −1
  • internal/console/overview_test.go +74 −18
  • internal/console/server.go +6 −1
  • internal/console/templates/app_overview.html +9 −0

CI passed — run details

landed from feature/instance-db-stats-card

diff --git a/internal/console/overview.go b/internal/console/overview.go
index 104e4cb2c..03db7eba9 100644
--- a/internal/console/overview.go
+++ b/internal/console/overview.go
@@ -72,6 +72,14 @@ type OverviewStats struct {
CPUSum *float64
MemSum *int64
+ // DBSizeSum is this app's total on-disk SQLite footprint (each route's
+ // file plus its -wal, status.BoxMetrics.RouteDBBytes via dbJoin), summed
+ // across every one of the account's own routes with a sized database —
+ // not gated on the metrics sweep reporting, since a hibernating
+ // instance's database is still on disk and still worth showing. Nil
+ // when no route could be sized.
+ DBSizeSum *int64
+
// Domains, and how many need someone's attention: a custom domain not
// pointing here yet, or a cert that is not ready.
DomainTotal int
@@ -93,7 +101,7 @@ type OverviewStats struct {
// instance count and the domains count must skip rows stamped with another
// account — a same-named app elsewhere must not inflate this dashboard or
// wave its failed cert on it.
-func assembleOverview(view *AppView, acct string, metrics []InstanceMetrics, versions []VersionView) OverviewStats {
+func assembleOverview(view *AppView, acct string, metrics []InstanceMetrics, versions []VersionView, dbJoin boxJoin) OverviewStats {
st := OverviewStats{MetricsUnavailable: metrics == nil}
st.Deployment = observedDeployment(view.Routes, acct)
reporting := make(map[string]bool, len(metrics))
@@ -119,6 +127,12 @@ func assembleOverview(view *AppView, acct string, metrics []InstanceMetrics, ver
if rt.Account != acct || rt.Platform {
continue
}
+ if n := dbJoin.dbSize(rt.Host); n != nil {
+ if st.DBSizeSum == nil {
+ st.DBSizeSum = new(int64)
+ }
+ *st.DBSizeSum += *n
+ }
if rt.Kind == "sidecar" {
st.SidecarTotal++
continue
diff --git a/internal/console/overview_test.go b/internal/console/overview_test.go
index 380b3ad0b..fece75e74 100644
--- a/internal/console/overview_test.go
+++ b/internal/console/overview_test.go
@@ -12,12 +12,14 @@ package console
// says so.
import (
+ "context"
"net/http"
"strings"
"testing"
"time"
"github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/status"
)
// f64 and i64 are the pointer literals InstanceMetrics carries — nil is a
@@ -30,7 +32,7 @@ func TestOverviewLiveVersionFromOwnedRoutes(t *testing.T) {
{Name: "beta", Version: "v9"},
{Name: "stable", Version: "v7", Err: "obsolete unreadable pointer"},
}, Routes: []RouteView{{Host: "kass.example", Account: "bab", Channel: "edge", Version: "v9"}}}
- st := assembleOverview(view, "bab", nil, nil)
+ st := assembleOverview(view, "bab", nil, nil, boxJoin{})
if !st.Deployment.HasReportedVersion() {
t.Fatal("an app with a reported route version is not reported deployed")
}
@@ -39,7 +41,7 @@ func TestOverviewLiveVersionFromOwnedRoutes(t *testing.T) {
}
// A pointer with no owned route is a target, not a deployment.
- st = assembleOverview(&AppView{App: "kass", Channels: []ChannelView{{Name: "stable", Version: "v9"}}}, "bab", nil, nil)
+ st = assembleOverview(&AppView{App: "kass", Channels: []ChannelView{{Name: "stable", Version: "v9"}}}, "bab", nil, nil, boxJoin{})
if st.Deployment.HasReportedVersion() || st.Deployment.UniformVersion() != "" {
t.Fatalf("a never-promoted app reads as live: %+v", st)
}
@@ -52,7 +54,7 @@ func TestOverviewUnknownRouteVersionIsUnknownNotOffline(t *testing.T) {
view := &AppView{App: "kass", Channels: []ChannelView{
{Name: "stable", Err: "signature does not verify"},
}, Routes: []RouteView{{Host: "kass.example", Account: "bab", Channel: "stable"}}}
- st := assembleOverview(view, "bab", nil, nil)
+ st := assembleOverview(view, "bab", nil, nil, boxJoin{})
if st.Deployment.HasReportedVersion() {
t.Fatal("an unreadable pointer was reported as a known live version")
}
@@ -88,7 +90,7 @@ func TestOverviewSumsOnlyReportingInstances(t *testing.T) {
{Host: "d", CPUFrac: f64(99), MemBytes: i64(99), Hibernate: true},
{Host: "e"},
}
- st := assembleOverview(view, "bab", metrics, nil)
+ st := assembleOverview(view, "bab", metrics, nil, boxJoin{})
if st.InstanceTotal != 5 {
t.Fatalf("InstanceTotal = %d, want 5 (the routes, not the sweep, and never another account's)", st.InstanceTotal)
}
@@ -111,7 +113,7 @@ func TestOverviewSumsOnlyReportingInstances(t *testing.T) {
// Nobody reported: nil, not zero. A zero here would render as "0%" and
// claim an idle app where there is simply no reading.
quietView := &AppView{App: "kass", Routes: []RouteView{{Host: "a", Account: "bab", Kind: "instance"}, {Host: "b", Account: "bab", Kind: "instance"}}}
- quiet := assembleOverview(quietView, "bab", []InstanceMetrics{{Host: "a"}, {Host: "b"}}, nil)
+ quiet := assembleOverview(quietView, "bab", []InstanceMetrics{{Host: "a"}, {Host: "b"}}, nil, boxJoin{})
if quiet.CPUSum != nil || quiet.MemSum != nil {
t.Fatalf("sums = %v %v with nothing reporting, want nil so the tiles show the em-dash",
quiet.CPUSum, quiet.MemSum)
@@ -122,7 +124,7 @@ func TestOverviewSumsOnlyReportingInstances(t *testing.T) {
// The sweep FAILED (nil metrics): the count must survive — "readings
// unavailable" is not "no hosts yet".
- failed := assembleOverview(quietView, "bab", nil, nil)
+ failed := assembleOverview(quietView, "bab", nil, nil, boxJoin{})
if failed.InstanceTotal != 2 {
t.Fatalf("InstanceTotal = %d after a failed sweep, want the routes' 2", failed.InstanceTotal)
}
@@ -143,7 +145,7 @@ func TestOverviewSeparatesNoReadings(t *testing.T) {
{Host: "d.x", Kind: "instance", Account: "acct1", Hibernate: true}, // asleep
}, Domains: []DomainView{{}, {}, {}, {}}}
metrics := []InstanceMetrics{{Host: "a.x", Box: "box1"}}
- st := assembleOverview(view, "acct1", metrics, nil)
+ st := assembleOverview(view, "acct1", metrics, nil, boxJoin{})
if st.InstanceExpected != 4 || st.InstanceReporting != 1 || st.InstanceAsleep != 1 ||
st.InstanceNoReadings != 1 || st.InstanceCounted != 3 {
t.Fatalf("counts: %+v", st)
@@ -188,7 +190,7 @@ func TestOverviewDomainAttentionCountsGuidanceAndFailedTLS(t *testing.T) {
{Domain: "e.example.com", TLS: "ready", Guidance: "Point an A record for e.example.com at ..."},
{Domain: "f.example.com", TLS: "failed: dns-01 timeout"},
}}
- st := assembleOverview(view, "bab", nil, nil)
+ st := assembleOverview(view, "bab", nil, nil, boxJoin{})
if st.DomainTotal != 5 {
t.Fatalf("DomainTotal = %d, want 5 — the other account's domain is not this tenant's", st.DomainTotal)
}
@@ -220,7 +222,7 @@ func TestOverviewReleasesCapped(t *testing.T) {
for i := range full {
full[i] = VersionView{Version: "v" + string(rune('a'+i))}
}
- st := assembleOverview(&AppView{App: "kass"}, "bab", nil, full)
+ st := assembleOverview(&AppView{App: "kass"}, "bab", nil, full, boxJoin{})
if st.ReleaseCount != versionsCap || !st.ReleasesCapped {
t.Fatalf("count/capped = %d/%v, want %d/true", st.ReleaseCount, st.ReleasesCapped, versionsCap)
}
@@ -228,11 +230,11 @@ func TestOverviewReleasesCapped(t *testing.T) {
t.Fatalf("LatestVersion = %q, want the head of the newest-first list (%q)", st.LatestVersion, full[0].Version)
}
- short := assembleOverview(&AppView{App: "kass"}, "bab", nil, full[:versionsCap-1])
+ short := assembleOverview(&AppView{App: "kass"}, "bab", nil, full[:versionsCap-1], boxJoin{})
if short.ReleasesCapped {
t.Fatalf("a list one short of the cap was reported capped (%d)", short.ReleaseCount)
}
- none := assembleOverview(&AppView{App: "kass"}, "bab", nil, nil)
+ none := assembleOverview(&AppView{App: "kass"}, "bab", nil, nil, boxJoin{})
if none.ReleaseCount != 0 || none.ReleasesCapped || none.LatestVersion != "" {
t.Fatalf("empty release list = %+v, want zeros and no version", none)
}
@@ -572,7 +574,7 @@ func TestOverviewAndAppListAgreeWhenFailedRouteHasNoVersion(t *testing.T) {
Host: "kass.example", Account: "bab", Kind: "instance", Status: "failed", Provisioned: true,
}}}
row := summarize(view, "bab")
- overview := assembleOverview(&view, "bab", []InstanceMetrics{}, nil)
+ overview := assembleOverview(&view, "bab", []InstanceMetrics{}, nil, boxJoin{})
if row.Verdict != "attention" || overview.Verdict != "attention" {
t.Fatalf("list=%q overview=%q, want attention on both pages", row.Verdict, overview.Verdict)
}
@@ -587,7 +589,7 @@ func TestOverviewIgnoresPlatformAliasWithoutInventingStaticVersion(t *testing.T)
},
Channels: []ChannelView{{Name: "edge", Version: "site-v3"}},
}
- st := assembleOverview(&view, "bab", []InstanceMetrics{}, nil)
+ st := assembleOverview(&view, "bab", []InstanceMetrics{}, nil, boxJoin{})
if st.Verdict != "ok" || st.Deployment.RouteCount != 1 || st.Deployment.ReportableCount != 0 || st.Deployment.HasReportedVersion() {
t.Fatalf("overview = %+v, want a healthy static deployment with no invented observation", st)
}
@@ -596,7 +598,7 @@ func TestOverviewIgnoresPlatformAliasWithoutInventingStaticVersion(t *testing.T)
func TestServiceOnlyAppIsPresentAndHealthyOnBothPages(t *testing.T) {
view := AppView{App: "proxy", Routes: []RouteView{{Host: "proxy.example", Account: "bab", Kind: "service", Status: "ready"}}}
row := summarize(view, "bab")
- overview := assembleOverview(&view, "bab", []InstanceMetrics{}, nil)
+ overview := assembleOverview(&view, "bab", []InstanceMetrics{}, nil, boxJoin{})
if row.Verdict != "ok" || overview.Verdict != "ok" || !overview.Deployment.HasRoutes() || overview.Deployment.ReportableCount != 0 {
t.Fatalf("list=%+v overview=%+v, want a present healthy service with no version report", row, overview)
}
@@ -608,7 +610,7 @@ func TestStaticPlusSilentInstanceIsUnknownOnBothPages(t *testing.T) {
{Host: "app.example", Account: "bab", Kind: "instance"},
}}
row := summarize(view, "bab")
- overview := assembleOverview(&view, "bab", []InstanceMetrics{}, nil)
+ overview := assembleOverview(&view, "bab", []InstanceMetrics{}, nil, boxJoin{})
if row.Verdict != "unknown" || overview.Verdict != "unknown" {
t.Fatalf("list=%q overview=%q, want unknown on both pages", row.Verdict, overview.Verdict)
}
@@ -622,7 +624,7 @@ func TestPlatformOnlyFailureDoesNotCreateCrossPageAttention(t *testing.T) {
Host: "alias.bab.oncarlos.com", Account: "bab", Platform: true, Status: "failed",
}}, Domains: []DomainView{{Guidance: "ignored platform guidance"}}}
row := summarize(view, "bab")
- overview := assembleOverview(&view, "bab", []InstanceMetrics{}, nil)
+ overview := assembleOverview(&view, "bab", []InstanceMetrics{}, nil, boxJoin{})
if row.Verdict != "notdeployed" || overview.Verdict != "notdeployed" {
t.Fatalf("list=%q overview=%q, want notdeployed on both pages", row.Verdict, overview.Verdict)
}
@@ -634,7 +636,7 @@ func TestOverviewExpectedCountsInstanceKindOnly(t *testing.T) {
{Host: "b", Account: "bab", Kind: "static"},
{Host: "c", Account: "other", Kind: "instance"},
}}
- st := assembleOverview(view, "bab", []InstanceMetrics{}, nil)
+ st := assembleOverview(view, "bab", []InstanceMetrics{}, nil, boxJoin{})
if st.InstanceExpected != 1 {
t.Errorf("InstanceExpected = %d, want 1 (instance-kind, this account only)", st.InstanceExpected)
}
@@ -656,7 +658,7 @@ func TestOverviewCountsSidecarsSeparately(t *testing.T) {
// Another account's sidecar must not count here either.
{Host: "bot.eleven.other.sidecar.internal", Account: "other", Kind: "sidecar"},
}}
- st := assembleOverview(view, "bab", []InstanceMetrics{}, nil)
+ st := assembleOverview(view, "bab", []InstanceMetrics{}, nil, boxJoin{})
if st.InstanceTotal != 1 {
t.Errorf("InstanceTotal = %d, want 1 — sidecars must not inflate it", st.InstanceTotal)
}
@@ -665,6 +667,36 @@ func TestOverviewCountsSidecarsSeparately(t *testing.T) {
}
}
+// TestOverviewDBSizeSumsEveryRouteRegardlessOfReporting: a hibernating
+// instance's database is still sitting on disk even though the metrics
+// sweep hears nothing from it, so the Database tile's size must come from
+// the account's ROUTES (via dbJoin, the same status.BoxMetrics.RouteDBBytes
+// join the instances/routes APIs already use), not be gated on the sweep
+// the way CPU/Mem are. It must also stay tenant-scoped like every other
+// number assembleOverview produces.
+func TestOverviewDBSizeSumsEveryRouteRegardlessOfReporting(t *testing.T) {
+ view := &AppView{App: "ips", Routes: []RouteView{
+ {Host: "a", Account: "bab", Kind: "instance"},
+ {Host: "b", Account: "bab", Kind: "instance", Hibernate: true},
+ {Host: "c", Account: "bab", Kind: "instance"}, // no sized database
+ {Host: "theirs", Account: "other", Kind: "instance"},
+ }}
+ join := boxJoin{dbBytes: map[string]int64{
+ "a": 1 << 20,
+ "b": 2 << 20, // asleep, unreported by the sweep, still on disk
+ "theirs": 99 << 20,
+ }}
+ st := assembleOverview(view, "bab", nil, nil, join)
+ if st.DBSizeSum == nil || *st.DBSizeSum != 3<<20 {
+ t.Fatalf("DBSizeSum = %v, want 3MiB (a+b only — hibernating counts, another account never does)", st.DBSizeSum)
+ }
+
+ none := assembleOverview(&AppView{App: "kass", Routes: []RouteView{{Host: "x", Account: "bab", Kind: "instance"}}}, "bab", nil, nil, boxJoin{})
+ if none.DBSizeSum != nil {
+ t.Fatalf("DBSizeSum = %v with no route sized, want nil so the tile shows the em-dash", none.DBSizeSum)
+ }
+}
+
// TestAppPageShowsPartialMismatchNotFullAlarm guards the boundary
// AllMismatched exists to draw: when only SOME of an app's routes disagree
// with the viewed account, the page must name the disagreeing route(s), not
@@ -702,3 +734,27 @@ func TestAppPageShowsPartialMismatchNotFullAlarm(t *testing.T) {
t.Errorf("the partial-mismatch banner does not link to diagnostics:\n%s", body)
}
}
+
+// TestAppOverviewDatabaseTileRenders: the tile shows the sized database from
+// a fresh box's status, and says so plainly when nothing has been sized.
+func TestAppOverviewDatabaseTileRenders(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.addRoute(t, registry.Route{Host: "owned.example.com", Kind: "instance",
+ Status: "ready", App: "kass", Backing: registry.BackingUnit})
+ c := signInPaul(t, fx)
+
+ _, _, body := get(t, c, fx.u("/apps/kass"))
+ if !strings.Contains(body, "<h2>Database</h2>") || !strings.Contains(body, "no size reported yet") {
+ t.Fatalf("unsized app: want the Database tile saying no size yet in:\n%s", body)
+ }
+
+ box := status.CollectBox(nil, status.Probes{MachineID: "box1"}, time.Now())
+ box.Metrics = &status.BoxMetrics{RouteDBBytes: map[string]int64{"owned.example.com": 3 << 20}}
+ if err := status.WriteBox(context.Background(), fx.rel, box); err != nil {
+ t.Fatal(err)
+ }
+ _, _, body = get(t, c, fx.u("/apps/kass"))
+ if !strings.Contains(body, "3.0 MB") || !strings.Contains(body, "on disk, including copies that are asleep") {
+ t.Fatalf("sized app: want 3.0 MB on the Database tile in:\n%s", body)
+ }
+}
diff --git a/internal/console/server.go b/internal/console/server.go
index db0eea533..80838075e 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -2815,7 +2815,12 @@ func (s *Server) handleApp(w http.ResponseWriter, r *http.Request) {
}
p.Versions = versions
metrics := s.appResourceMetrics(r.Context(), p.Detail, acct)
- p.Overview = assembleOverview(p.Detail, acct.Sqid, metrics, versions)
+ // The Database tile's sizes are best-effort: a slow status read costs the
+ // tile its number (the em-dash), never the page.
+ joinCtx, cancelJoin := context.WithTimeout(r.Context(), instanceStoreTimeout)
+ dbJoin := loadBoxJoin(joinCtx, s.cfg.Releases, time.Now())
+ cancelJoin()
+ p.Overview = assembleOverview(p.Detail, acct.Sqid, metrics, versions, dbJoin)
// The diagram is drawn from the SAME tenant-filtered rows the Running tab
// renders, so the two can never disagree about which addresses exist or
// how they are doing — see flow.go's package comment for why it is not
diff --git a/internal/console/templates/app_overview.html b/internal/console/templates/app_overview.html
index 1ed17eaab..f029121bb 100644
--- a/internal/console/templates/app_overview.html
+++ b/internal/console/templates/app_overview.html
@@ -37,6 +37,15 @@
<p class="tile-value">{{pct .CPUSum}} · {{bytesOrDash .MemSum}}</p>
<p class="tile-detail">{{if .CPUSum}}CPU · memory, from the copies responding{{else if .MetricsUnavailable}}no data right now{{else}}no recent data{{end}}</p>
</a>
+ {{/* Sizes come from the routes, not the metrics sweep: a sleeping copy's
+ database is still on disk. Hidden for apps that run nothing. */}}
+ {{if or .DBSizeSum .InstanceExpected}}
+ <a class="tile" href="{{$.Nav}}/apps/{{$.AppName}}/instances">
+ <h2>Database</h2>
+ <p class="tile-value">{{bytesOrDash .DBSizeSum}}</p>
+ <p class="tile-detail">{{if .DBSizeSum}}on disk, including copies that are asleep{{else}}no size reported yet{{end}}</p>
+ </a>
+ {{end}}
<a class="tile" href="{{$.Nav}}/apps/{{$.AppName}}/settings/domains">
<h2>Web addresses</h2>
<p class="tile-value">{{.DomainTotal}}</p>