Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe("command surface", () => {
"warehouse disable",
"warehouse enable",
"warehouse inspect",
"warehouse inspect capacity",
"warehouse inspect query-stats",
"warehouse status",
"warehouse tables",
Expand All @@ -83,7 +84,7 @@ describe("command surface", () => {
);

it.effect(
"mounts workload inspection under Warehouse and preserves standalone inspect commands",
"mounts metrics inspection under Warehouse and preserves standalone inspect commands",
() =>
Effect.gen(function* () {
const { commands } = yield* Effect.promise(() => surface);
Expand All @@ -95,16 +96,18 @@ describe("command surface", () => {
expect(enabled[path]).toEqual(commands[path]);
}
expect(enabled).not.toHaveProperty("inspect warehouse");
const stats = enabled["warehouse inspect query-stats"];
expect(stats).toMatchObject({
stage: { status: "experimental", feature: "warehouse" },
target: { group: "hosted", consent: "none" },
api: { operationId: "v2-get-warehouse-query-stats" },
});
expect(Object.keys(stats?.flags ?? {})).toEqual(
expect.arrayContaining(["since", "from", "to", "attributes", "interval", "remote"]),
);
expect(stats?.flags).not.toHaveProperty("wait");
for (const command of ["capacity", "query-stats"]) {
const entry = enabled[`warehouse inspect ${command}`];
expect(entry).toMatchObject({
stage: { status: "experimental", feature: "warehouse" },
target: { group: "hosted", consent: "none" },
api: { operationId: `v2-get-warehouse-${command}` },
});
expect(Object.keys(entry?.flags ?? {})).toEqual(
expect.arrayContaining(["since", "from", "to", "attributes", "interval", "remote"]),
);
expect(entry?.flags).not.toHaveProperty("wait");
}
}),
);

Expand Down
1 change: 1 addition & 0 deletions apps/cli/src/commands/api/api-command-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const generatedOperations: ReadonlyArray<OpenApiOperationId> = [
"v2-get-warehouse-table-layout",
"v2-update-warehouse-table-layout",
"v2-get-warehouse-query-stats",
"v2-get-warehouse-capacity",
];

export const nouns = {
Expand Down
67 changes: 37 additions & 30 deletions apps/cli/src/commands/api/api-commands.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,38 +107,45 @@ const runWarehouse = (
return { result, requests, bodies };
}).pipe(Effect.scoped);

it.live("warehouse inspect query-stats reaches the public route through the compiled CLI", () =>
Effect.gen(function* () {
const response = json(200, {
data: [
{
type: "warehouse_metric",
id: "query_rate",
attributes: {
project_ref: REF,
metric: "query_rate",
unit: "per_second",
aggregation: "rate",
definition: "Query invocations per second.",
requested: { metric: "query_rate", start: 1795000000, end: 1795001800 },
effective: { start: 1795000000, end: 1795001800, step: 60, rate_window_seconds: 300 },
scrape_interval_seconds: 60,
last_sample_at: null,
availability: "unavailable",
series: [],
it.live.each([
{ command: "query-stats", metric: "query_rate", unit: "per_second", aggregation: "rate" },
{ command: "capacity", metric: "query_in_flight", unit: "queries", aggregation: "sum" },
] as const)(
"warehouse inspect $command reaches the public route through the compiled CLI",
({ command, metric, unit, aggregation }) =>
Effect.gen(function* () {
const response = json(200, {
data: [
{
type: "warehouse_metric",
id: metric,
attributes: {
project_ref: REF,
metric,
unit,
aggregation,
definition: "Executor query invocations.",
requested: { metric, start: 1795000000, end: 1795001800 },
effective: { start: 1795000000, end: 1795001800, step: 60, rate_window_seconds: 300 },
scrape_interval_seconds: 60,
last_sample_at: null,
availability: "unavailable",
series: [],
},
},
},
],
} satisfies OperationOutput<"v2GetWarehouseQueryStats">);
const { result, requests } = yield* runWarehouse(
["inspect", "query-stats", "--since", "30m"],
() => response,
);
],
} satisfies
| OperationOutput<"v2GetWarehouseQueryStats">
| OperationOutput<"v2GetWarehouseCapacity">);
const { result, requests } = yield* runWarehouse(
["inspect", command, "--since", "30m"],
() => response,
);

requireCliSuccess(result, "warehouse inspect query-stats");
expect(result.stdout, result.stderr).toBe(response.body);
expect(requests).toEqual([`GET /v2/projects/${REF}/warehouse/query-stats`]);
}).pipe(Effect.provide(BunServices.layer)),
requireCliSuccess(result, `warehouse inspect ${command}`);
expect(result.stdout, result.stderr).toBe(response.body);
expect(requests).toEqual([`GET /v2/projects/${REF}/warehouse/${command}`]);
}).pipe(Effect.provide(BunServices.layer)),
);

it.live("warehouse status reports a 409 as a conflict failure document on stderr", () =>
Expand Down
105 changes: 105 additions & 0 deletions apps/cli/src/commands/api/api-commands.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,106 @@ describe("generated warehouse commands", () => {
});
});
});
describe("warehouse inspect capacity", () => {
const argv = ["warehouse", "inspect", "capacity"];
const attributes = {
project_ref: VALID_REF,
metric: "activation_duration_p95",
unit: "seconds",
aggregation: "p95",
definition: "Activation duration by kind and result.",
requested: { metric: "activation_duration_p95", start: 1795000000, end: 1795001800 },
effective: { start: 1795000000, end: 1795001800, step: 60, rate_window_seconds: 300 },
scrape_interval_seconds: 60,
last_sample_at: 1795001740,
availability: "partial",
series: [
{
labels: { kind: "cold", result: "success" },
points: [
{ timestamp: 1795001740, value: 0.2 },
{ timestamp: 1795001800, value: null },
],
coverage: { returned_points: 1, expected_points: 2 },
},
{
labels: { kind: "warm", result: "success" },
points: [{ timestamp: 1795001800, value: 0.01 }],
coverage: { returned_points: 1, expected_points: 2 },
},
],
} satisfies OperationOutput<"v2GetWarehouseCapacity">["data"][number]["attributes"];
const response = {
data: [
{
type: "warehouse_metric",
id: "activation_duration_p95",
attributes: { ...attributes, future_observation: { reason: null } },
},
],
};

it.effect("leaves default selection to the API and preserves all JSON bytes when piped", () => {
const rawResponse = `\n${encodeJson(response).replace('"value":0.2', '"value":0.20')}\n`;
const { sent, out, run } = setup([...argv, "--since", "30m", "--interval", "5m"], {
route: ok(rawResponse),
});
return Effect.gen(function* () {
yield* run;
expect(sent).toHaveLength(1);
expect(sent[0]).toMatchObject({
method: "GET",
path: `/v2/projects/${VALID_REF}/warehouse/capacity`,
body: undefined,
});
expect(Object.fromEntries(new URLSearchParams(sent[0]?.search))).toEqual({
since: "30m",
interval: "5m",
});
expect(out.stdoutText).toBe(rawResponse);
});
});

it.effect(
"renders both capacity series, their dimensions, unit, availability, and null sample",
() => {
const { out, run } = setup(argv, { route: ok(response), stdoutIsTty: true });
return Effect.gen(function* () {
yield* run;
expect(out.stdoutText).toMatch(/Kind\s+cold/);
expect(out.stdoutText).toMatch(/Kind\s+warm/);
expect(out.stdoutText.match(/Result\s+success/g)).toHaveLength(2);
expect(out.stdoutText).toMatch(/\bUNIT\b[\s\S]*\bseconds\b/);
expect(out.stdoutText).toMatch(/\bAVAILABILITY\b[\s\S]*\bpartial\b/);
expect(out.stdoutText).toMatch(/1795001800\s*[|│]?\s*-/);
expect(out.stdoutText).toMatch(/1795001800\s*[|│]?\s*0\.01/);
});
},
);

it.effect(
"forwards fixed timestamps and metric selection and keeps all dimensions in YAML",
() => {
const from = "2026-11-18T09:30:00+01:00";
const to = "2026-11-18T10:00:00+01:00";
const selection = "activation_duration_p95,worker_admission_occupied";
const { sent, out, run } = setup(
[...argv, "--from", from, "--to", to, "--attributes", selection, "-o", "yaml"],
{ route: ok(response), stdoutIsTty: true },
);
return Effect.gen(function* () {
yield* run;
expect(sent).toHaveLength(1);
expect(Object.fromEntries(new URLSearchParams(sent[0]?.search))).toEqual({
from,
to,
attributes: selection,
});
expect(parseYaml(out.stdoutText)).toEqual(response);
});
},
);
});
Comment thread
bnjjj marked this conversation as resolved.
Resolved
describe("warehouse tables get", () => {
const tablePath = `/v2/projects/${VALID_REF}/warehouse/tables/16385`;
const body = {
Expand Down Expand Up @@ -2067,6 +2167,11 @@ describe("generated warehouse commands", () => {
args: ["warehouse", "inspect", "query-stats"],
features: ["warehouse"],
},
{
name: "Warehouse capacity inspection",
args: ["warehouse", "inspect", "capacity"],
features: ["warehouse"],
},
{ name: "database inspection", args: ["inspect", "db", "table-stats"], features: [] },
{ name: "inspection report", args: ["inspect", "report"], features: [] },
{
Expand Down
28 changes: 28 additions & 0 deletions apps/cli/src/commands/api/generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ Enables replication for the currently eligible tables in a schema, or the named
- Failure message from `/data/attributes/status_error`.
- Failure hint names `supabase warehouse status --remote=<ref>`.

## `supabase warehouse inspect capacity`

Inspect Warehouse capacity diagnostics

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.

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`.

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.

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.

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.

- Access: read-only, no consent.
- Feature: `warehouse`.
- Request: `GET /v2/projects/{ref}/warehouse/capacity` (`v2-get-warehouse-capacity`), success 200 json.

### Flags

| Flag | Type | Required | Repeatable | Binds to |
| --------------------------- | --------------------------------------------- | -------- | ---------- | ------------------ |
| `--attributes <attributes>` | string | no | no | query `attributes` |
| `--from <from>` | string | no | no | query `from` |
| `--interval <interval>` | string (`10m`, `1d`, `1h`, `1m`, `30m`, `5m`) | no | no | query `interval` |
| `--since <since>` | string | no | no | query `since` |
| `--to <to>` | string | no | no | query `to` |

## `supabase warehouse inspect query-stats`

Inspect Warehouse workload query statistics
Expand Down
Loading