Skip to content

Commit e35de1e

Browse files
authored
feat(cli): add warehouse inspect capacity (#7714)
Add the experimental `supabase warehouse inspect capacity` command, stacked on #7640. ```sh supabase warehouse inspect capacity --remote <project-ref> --since 30m ``` Generate the command from the public capacity API contract, with `--from`/`--to`, `--attributes`, and `--interval`. Keep metric selection defaults and range validation server-owned. Reuse the shared text, JSON, and YAML output contract, preserving units, dimensions, null values, and availability. JSON/YAML retain the complete response. No new generated-command runtime or generator logic is needed. Closes PIPE-1463.
1 parent f8159c3 commit e35de1e

12 files changed

Lines changed: 1442 additions & 41 deletions

File tree

‎apps/cli/src/cli/command-surface/command-surface.integration.test.ts‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe("command surface", () => {
5858
"warehouse disable",
5959
"warehouse enable",
6060
"warehouse inspect",
61+
"warehouse inspect capacity",
6162
"warehouse inspect query-stats",
6263
"warehouse status",
6364
"warehouse tables",
@@ -83,7 +84,7 @@ describe("command surface", () => {
8384
);
8485

8586
it.effect(
86-
"mounts workload inspection under Warehouse and preserves standalone inspect commands",
87+
"mounts metrics inspection under Warehouse and preserves standalone inspect commands",
8788
() =>
8889
Effect.gen(function* () {
8990
const { commands } = yield* Effect.promise(() => surface);
@@ -95,16 +96,18 @@ describe("command surface", () => {
9596
expect(enabled[path]).toEqual(commands[path]);
9697
}
9798
expect(enabled).not.toHaveProperty("inspect warehouse");
98-
const stats = enabled["warehouse inspect query-stats"];
99-
expect(stats).toMatchObject({
100-
stage: { status: "experimental", feature: "warehouse" },
101-
target: { group: "hosted", consent: "none" },
102-
api: { operationId: "v2-get-warehouse-query-stats" },
103-
});
104-
expect(Object.keys(stats?.flags ?? {})).toEqual(
105-
expect.arrayContaining(["since", "from", "to", "attributes", "interval", "remote"]),
106-
);
107-
expect(stats?.flags).not.toHaveProperty("wait");
99+
for (const command of ["capacity", "query-stats"]) {
100+
const entry = enabled[`warehouse inspect ${command}`];
101+
expect(entry).toMatchObject({
102+
stage: { status: "experimental", feature: "warehouse" },
103+
target: { group: "hosted", consent: "none" },
104+
api: { operationId: `v2-get-warehouse-${command}` },
105+
});
106+
expect(Object.keys(entry?.flags ?? {})).toEqual(
107+
expect.arrayContaining(["since", "from", "to", "attributes", "interval", "remote"]),
108+
);
109+
expect(entry?.flags).not.toHaveProperty("wait");
110+
}
108111
}),
109112
);
110113

‎apps/cli/src/commands/api/api-command-policy.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const generatedOperations: ReadonlyArray<OpenApiOperationId> = [
2525
"v2-get-warehouse-table-layout",
2626
"v2-update-warehouse-table-layout",
2727
"v2-get-warehouse-query-stats",
28+
"v2-get-warehouse-capacity",
2829
];
2930

3031
export const nouns = {

‎apps/cli/src/commands/api/api-commands.e2e.test.ts‎

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -107,38 +107,45 @@ const runWarehouse = (
107107
return { result, requests, bodies };
108108
}).pipe(Effect.scoped);
109109

110-
it.live("warehouse inspect query-stats reaches the public route through the compiled CLI", () =>
111-
Effect.gen(function* () {
112-
const response = json(200, {
113-
data: [
114-
{
115-
type: "warehouse_metric",
116-
id: "query_rate",
117-
attributes: {
118-
project_ref: REF,
119-
metric: "query_rate",
120-
unit: "per_second",
121-
aggregation: "rate",
122-
definition: "Query invocations per second.",
123-
requested: { metric: "query_rate", start: 1795000000, end: 1795001800 },
124-
effective: { start: 1795000000, end: 1795001800, step: 60, rate_window_seconds: 300 },
125-
scrape_interval_seconds: 60,
126-
last_sample_at: null,
127-
availability: "unavailable",
128-
series: [],
110+
it.live.each([
111+
{ command: "query-stats", metric: "query_rate", unit: "per_second", aggregation: "rate" },
112+
{ command: "capacity", metric: "query_in_flight", unit: "queries", aggregation: "sum" },
113+
] as const)(
114+
"warehouse inspect $command reaches the public route through the compiled CLI",
115+
({ command, metric, unit, aggregation }) =>
116+
Effect.gen(function* () {
117+
const response = json(200, {
118+
data: [
119+
{
120+
type: "warehouse_metric",
121+
id: metric,
122+
attributes: {
123+
project_ref: REF,
124+
metric,
125+
unit,
126+
aggregation,
127+
definition: "Executor query invocations.",
128+
requested: { metric, start: 1795000000, end: 1795001800 },
129+
effective: { start: 1795000000, end: 1795001800, step: 60, rate_window_seconds: 300 },
130+
scrape_interval_seconds: 60,
131+
last_sample_at: null,
132+
availability: "unavailable",
133+
series: [],
134+
},
129135
},
130-
},
131-
],
132-
} satisfies OperationOutput<"v2GetWarehouseQueryStats">);
133-
const { result, requests } = yield* runWarehouse(
134-
["inspect", "query-stats", "--since", "30m"],
135-
() => response,
136-
);
136+
],
137+
} satisfies
138+
| OperationOutput<"v2GetWarehouseQueryStats">
139+
| OperationOutput<"v2GetWarehouseCapacity">);
140+
const { result, requests } = yield* runWarehouse(
141+
["inspect", command, "--since", "30m"],
142+
() => response,
143+
);
137144

138-
requireCliSuccess(result, "warehouse inspect query-stats");
139-
expect(result.stdout, result.stderr).toBe(response.body);
140-
expect(requests).toEqual([`GET /v2/projects/${REF}/warehouse/query-stats`]);
141-
}).pipe(Effect.provide(BunServices.layer)),
145+
requireCliSuccess(result, `warehouse inspect ${command}`);
146+
expect(result.stdout, result.stderr).toBe(response.body);
147+
expect(requests).toEqual([`GET /v2/projects/${REF}/warehouse/${command}`]);
148+
}).pipe(Effect.provide(BunServices.layer)),
142149
);
143150

144151
it.live("warehouse status reports a 409 as a conflict failure document on stderr", () =>

‎apps/cli/src/commands/api/api-commands.integration.test.ts‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,106 @@ describe("generated warehouse commands", () => {
645645
});
646646
});
647647
});
648+
describe("warehouse inspect capacity", () => {
649+
const argv = ["warehouse", "inspect", "capacity"];
650+
const attributes = {
651+
project_ref: VALID_REF,
652+
metric: "activation_duration_p95",
653+
unit: "seconds",
654+
aggregation: "p95",
655+
definition: "Activation duration by kind and result.",
656+
requested: { metric: "activation_duration_p95", start: 1795000000, end: 1795001800 },
657+
effective: { start: 1795000000, end: 1795001800, step: 60, rate_window_seconds: 300 },
658+
scrape_interval_seconds: 60,
659+
last_sample_at: 1795001740,
660+
availability: "partial",
661+
series: [
662+
{
663+
labels: { kind: "cold", result: "success" },
664+
points: [
665+
{ timestamp: 1795001740, value: 0.2 },
666+
{ timestamp: 1795001800, value: null },
667+
],
668+
coverage: { returned_points: 1, expected_points: 2 },
669+
},
670+
{
671+
labels: { kind: "warm", result: "success" },
672+
points: [{ timestamp: 1795001800, value: 0.01 }],
673+
coverage: { returned_points: 1, expected_points: 2 },
674+
},
675+
],
676+
} satisfies OperationOutput<"v2GetWarehouseCapacity">["data"][number]["attributes"];
677+
const response = {
678+
data: [
679+
{
680+
type: "warehouse_metric",
681+
id: "activation_duration_p95",
682+
attributes: { ...attributes, future_observation: { reason: null } },
683+
},
684+
],
685+
};
686+
687+
it.effect("leaves default selection to the API and preserves all JSON bytes when piped", () => {
688+
const rawResponse = `\n${encodeJson(response).replace('"value":0.2', '"value":0.20')}\n`;
689+
const { sent, out, run } = setup([...argv, "--since", "30m", "--interval", "5m"], {
690+
route: ok(rawResponse),
691+
});
692+
return Effect.gen(function* () {
693+
yield* run;
694+
expect(sent).toHaveLength(1);
695+
expect(sent[0]).toMatchObject({
696+
method: "GET",
697+
path: `/v2/projects/${VALID_REF}/warehouse/capacity`,
698+
body: undefined,
699+
});
700+
expect(Object.fromEntries(new URLSearchParams(sent[0]?.search))).toEqual({
701+
since: "30m",
702+
interval: "5m",
703+
});
704+
expect(out.stdoutText).toBe(rawResponse);
705+
});
706+
});
707+
708+
it.effect(
709+
"renders both capacity series, their dimensions, unit, availability, and null sample",
710+
() => {
711+
const { out, run } = setup(argv, { route: ok(response), stdoutIsTty: true });
712+
return Effect.gen(function* () {
713+
yield* run;
714+
expect(out.stdoutText).toMatch(/Kind\s+cold/);
715+
expect(out.stdoutText).toMatch(/Kind\s+warm/);
716+
expect(out.stdoutText.match(/Result\s+success/g)).toHaveLength(2);
717+
expect(out.stdoutText).toMatch(/\bUNIT\b[\s\S]*\bseconds\b/);
718+
expect(out.stdoutText).toMatch(/\bAVAILABILITY\b[\s\S]*\bpartial\b/);
719+
expect(out.stdoutText).toMatch(/1795001800\s*[|│]?\s*-/);
720+
expect(out.stdoutText).toMatch(/1795001800\s*[|│]?\s*0\.01/);
721+
});
722+
},
723+
);
724+
725+
it.effect(
726+
"forwards fixed timestamps and metric selection and keeps all dimensions in YAML",
727+
() => {
728+
const from = "2026-11-18T09:30:00+01:00";
729+
const to = "2026-11-18T10:00:00+01:00";
730+
const selection = "activation_duration_p95,worker_admission_occupied";
731+
const { sent, out, run } = setup(
732+
[...argv, "--from", from, "--to", to, "--attributes", selection, "-o", "yaml"],
733+
{ route: ok(response), stdoutIsTty: true },
734+
);
735+
return Effect.gen(function* () {
736+
yield* run;
737+
expect(sent).toHaveLength(1);
738+
expect(Object.fromEntries(new URLSearchParams(sent[0]?.search))).toEqual({
739+
from,
740+
to,
741+
attributes: selection,
742+
});
743+
expect(parseYaml(out.stdoutText)).toEqual(response);
744+
});
745+
},
746+
);
747+
});
648748
describe("warehouse tables get", () => {
649749
const tablePath = `/v2/projects/${VALID_REF}/warehouse/tables/16385`;
650750
const body = {
@@ -2067,6 +2167,11 @@ describe("generated warehouse commands", () => {
20672167
args: ["warehouse", "inspect", "query-stats"],
20682168
features: ["warehouse"],
20692169
},
2170+
{
2171+
name: "Warehouse capacity inspection",
2172+
args: ["warehouse", "inspect", "capacity"],
2173+
features: ["warehouse"],
2174+
},
20702175
{ name: "database inspection", args: ["inspect", "db", "table-stats"], features: [] },
20712176
{ name: "inspection report", args: ["inspect", "report"], features: [] },
20722177
{

‎apps/cli/src/commands/api/generated.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,34 @@ Enables replication for the currently eligible tables in a schema, or the named
6767
- Failure message from `/data/attributes/status_error`.
6868
- Failure hint names `supabase warehouse status --remote=<ref>`.
6969

70+
## `supabase warehouse inspect capacity`
71+
72+
Inspect Warehouse capacity diagnostics
73+
74+
Returns capacity, admission, assignment-wait, and activation measurements over a bounded time range, using the project’s stored Warehouse placement. Use `--since` or specify both `--from` and `--to`; the default is the last 30 minutes.
75+
76+
Each measurement includes its definition, unit, aggregation, requested and effective ranges, `rate_window_seconds`, source-sample freshness, availability, coverage, and full series with dimension labels such as `reason`, `kind`, and `result`.
77+
78+
Executor invocations in flight are distinct from worker admission grants. Occupied admission includes active plus pending grants. The configured admission limit does not imply an open gate or spare capacity. Missing, stale, and insufficient observations remain unavailable or `null`; they do not establish healthy or idle capacity.
79+
80+
Point timestamps are evaluation times; `last_sample_at` is the original source-sample time. Rates and latency quantiles describe the effective rate window at each point, not the entire requested range.
81+
82+
Each request returns up to eight measurements, and a failure of one measurement does not discard the other results. No raw queries or backend selectors are accepted.
83+
84+
- Access: read-only, no consent.
85+
- Feature: `warehouse`.
86+
- Request: `GET /v2/projects/{ref}/warehouse/capacity` (`v2-get-warehouse-capacity`), success 200 json.
87+
88+
### Flags
89+
90+
| Flag | Type | Required | Repeatable | Binds to |
91+
| --------------------------- | --------------------------------------------- | -------- | ---------- | ------------------ |
92+
| `--attributes <attributes>` | string | no | no | query `attributes` |
93+
| `--from <from>` | string | no | no | query `from` |
94+
| `--interval <interval>` | string (`10m`, `1d`, `1h`, `1m`, `30m`, `5m`) | no | no | query `interval` |
95+
| `--since <since>` | string | no | no | query `since` |
96+
| `--to <to>` | string | no | no | query `to` |
97+
7098
## `supabase warehouse inspect query-stats`
7199

72100
Inspect Warehouse workload query statistics

0 commit comments

Comments
 (0)