Skip to content

perf(infra): read hosts, pods and workloads from infra_metrics_hourly - #3275

Merged
Makisuo merged 17 commits into
mainfrom
infra-rollup/reads
Dec 4, 2026
Merged

Makisuo merged 17 commits into
mainfrom
infra-rollup/reads

Conversation

@Makisuo

@Makisuo Makisuo commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Part 2 of 2, on #3274 (the rollup table). That PR stacks on the #3239 fixes (review/pr-3239-fixes).

What

The seven infra list and detail reads now aggregate per-series partials (infra-partials.ts):

  • The reads: hosts list, host detail, pods list, pods summary, pod detail, workloads list, workload detail.
  • The split: whole hours come from infra_metrics_hourly; the partial hours at each end come from raw points, via the rollup-splice boundary.
  • Exact re-aggregation: a mean is sum(Total) / sum(Samples), a peak max(Peak), a last value argMax(Latest, LastSeen).
  • Typed keys: each read names the attribute keys it reads, and reading any other key is a type error. A key the rollup drops cannot quietly read empty.
  • Limits in one pass: pod and workload limits come from the same pass as their row, so the second scan and join from feat(infra): show used / total figures beside the CPU, memory and disk percents #3239 are gone.
  • Fallback: a cluster without migration 0078 reads raw points only. That covers the API (fallbackRows / fallbackFirst, raw twins from infraTiered) and the MCP tools (rollupRead). Both log the fallback and mark the span query.rollup.fallback.

Every read takes the window exactly as sent. An earlier revision rounded a long window's start down to the hour to save one day partition of raw reads. It was dropped so summaries, charts, facets and MCP all cover the same window.

Benchmark

Production warehouse, the same org, 7-day window, timings are medians of 3. Prod has no rollup yet, so the "After" column ran the new SQL with infra_metrics_hourly swapped for an empty table of its shape. That measures everything except the rollup read itself: about 62k rollup rows a day for this org's heaviest metrics.

Query (7d) main #3239 After
Hosts list 133M rows, 19.2s, 128 MB 147M, 21.5s, 512 MB 16.5M, 1.75s, 128 MB
Host detail 73M, 17.9s, 128 MB 52M, 7.8s, 128 MB 10.1M, 0.99s, 64 MB
Pods list 14.6M, 11.9s, 64 MB 34.2M, 15.2s, 1024 MB 0.85M, 0.19s, 64 MB
Pod detail 14.6M, 2.7s, 64 MB 33.8M, 6.8s, 128 MB 0.85M, 0.11s, 64 MB
Workloads list 24.0M, 9.9s, 128 MB 28.0M, 9.0s, 128 MB 1.06M, 0.21s, 64 MB
Workload detail 14.6M, 2.0s, 64 MB 33.8M, 5.1s, 64 MB 0.85M, 0.10s, 32 MB

Memory is the smallest cap the query passes under, found by bisecting max_memory_usage. Raw points sort by series and then time, so each raw edge reads its whole day partition. That is most of the remaining cost.

Raw fallback: most reads match their old cost. The 24h hosts list is about 2× slower (6.8s vs 3.6s), and its 7-day case times out, as the old query nearly did (21s). This only affects self-managed clusters that have not applied 0078.

Verified

  • Parity on chDB: apps/cli/test/infra-metrics-hourly.test.ts seeds hosts, pods, containers and replica gauges across both partial hours. Every routed read returns the same rows on the hourly and raw tiers, over a window that starts mid-hour and over a long window that starts on the hour. A one-off run also matched the pre-change queries row for row on that fixture.
  • Routing: infra.test.ts pins every routed builder: it reads infra_metrics_hourly by default and never on the raw tier. The SQL baseline has raw-tier fixtures.
  • Suites: query-engine 2654, MCP 1676, CLI chDB. Typechecks for query-engine, backend, api, ai and cli; oxlint with .oxlintrc.effect.json.

Known limits

  • Limit check can be fooled: the limit check compares usage ÷ share at the highest sample, the lowest and the totals. A changed limit whose three ratios happen to agree to 1e-9 would pass. That needs a constructed input, not real kubelet data.
  • Both tables: a host writing one metric to both the sum and gauge tables (no known sender does) now reads one mean across both.
  • Preview: the preview deploy can't run. The "Preview Tinybird branch" workflow fails at startup for every PR, so the label is off until that workflow is fixed.

🤖 Generated with Claude Code

IEatCodeDaily and others added 4 commits December 4, 2026 00:13
…k percents

Infra pages showed CPU / memory / disk as bare percents. "Memory 62%" says nothing about whether that is
1 GB or 100 GB, and a pod at 98% of its limit reads the same whether the limit is 64 MB or 4 GB. This puts
the absolute figure beside each percent (tables, stat cards, chart legends and tooltips), from metrics the
collectors already send. A figure is shown only where the data gives one; otherwise the percent stands alone.

Hosts (`listHostsQuery`, `hostDetailSummaryQuery`)
- CPU: busy cores = busy share × `system.cpu.logical.count` ("7.52 / 8 cores").
- Memory: `system.memory.usage{state=used}`; the hostmetrics receiver sends no total and its states do
  not sum to one (`cached` includes `slab_reclaimable`), so total = used bytes ÷ the used share within each
  scrape, averaged over scrapes that carried both ("9.9 GB / 16.0 GB"). Checked against `/proc/meminfo`
  MemTotal byte for byte. All three metrics are read from `metrics_sum` and `metrics_gauge` (the exporter
  routes by data-point type; senders differ), grouped per host and scrape across both.
- Disk: the fullest mount's used and used + free bytes from `system.filesystem.usage`, from the very reading
  its percent comes from (`argMaxIf` on the same mount and freshness rule `diskPct` uses), so used / total
  == diskPct ("41.0 GB / 100 GB"); on a timestamp tie the reading with bytes gives the percent. A used/free
  pair from two scrapes, one state alone, or a newer utilization-only reading gives the percent alone. A
  usage scrape with one state is no fraction at all (it would read 100%), so the mount list and chart skip
  it too. Host detail reads the figures for its one host, not the org.
- Detail charts: CPU states read as cores of the host, memory states as bytes of its total, and each mount
  as bytes of its size (`hostFilesystemTotalsQuery`: used + free per mount, only while it held still) —
  "45% · 7.2 GB" in the legend and tooltip. The totals definition has its own cache revision, since it
  shares the series' id and payload.

Pods (`listPodsQuery`, `podDetailSummaryQuery`): the kubelet sends limit and request shares, not limits, so
each limit or request is usage ÷ share within one sample (one pod by UID, one scrape), and is given only
when every sample agrees and no sample has usage without its share. Then usage over it is exactly the
share beside it, peak or average; a limit resized within the window, samples that disagree, or a pod
without the share show usage alone. The list meters read "0.022 / 2.1 cores",
"1.8 GB / 2.1 GB"; the detail page's four share cards carry the same figures, and its limit and request
charts read as cores or bytes. The summary band reads the same metric set as the list.

Workloads (`listWorkloadsQuery`, `workloadDetailSummaryQuery`): the same per-sample divisor, given only when
every pod of the workload ran under one limit. The list's peak meters and the detail cards and charts then
carry cores and bytes; workloads whose pods run under different limits keep the percent alone.

Nodes: the utilization charts read as cores and bytes of allocatable (the cards already carried them).

Containers (`listContainersQuery`, `containerCountersSummaryQuery`): memory reads usage of the limit from
the docker_stats `container.memory.usage.total` / `.limit` sums, filtered by the list's own filters (an
image filter keeps a reused name's old image out) and left-joined per (name, host); their ratio equals
`container.memory.percent`. A limit that changed within the window gives no figure. Docker's CPU percent is
not a share of a core count, so CPU has no figure.

Supabase: the memory and disk cells, the degraded reason and the overview finding carry bytes of the
project's memory and disk size.

Figures beside a share of a limit or request are share × divisor (`formatShareOfLimit`), so they always read
as the percent beside them; usage stands alone only where there is no limit. A pod name reused across two
clusters folds both into one row, and a usage peak from one beside a share from the other no longer disagrees.

Charts: `InfraMetric` specs take an optional `absolute` (`{ unit, totals }` by series, `*` for all), and
`formatSeriesValue` adds the figure in legends and tooltips; the axis stays in percent.

Compatibility: every new response field is a `Schema.optionalKey` (0 or absent = not sent), so a web build
with them still decodes an older API's response and shows percents only. A missing metric never renders an
invented "0 cores" / "0 B".

Layout (Effect UI pages): `MeterRows` takes an optional `detail` per row in a fixed 112 px lane;
`figureLane: true` keeps the lane for a row with no figure, so a table draws every bar at one length and every
percent in one column. The host, pod and container tables key their lanes on the page column
(`@container/page`) instead of the viewport, since the sidebar narrows it; the lanes live in one place
(`FLEET_LANES`, `InfraCells.ts`). Below 800 px of page the meters read under the name. Narrow single-meter
cells (nodes, workload peaks) put the figure under the meter instead (`CaptionedMeter`), so no column widens.

Tests: query-engine infra/containers suites (per-sample divisors, same-reading disk bytes, container byte
filters, filesystem totals), `formatSeriesValue`, the figure formatters and `podAbsolute`, the Supabase degraded
reasons, the host findings, the regenerated SQL baseline, and the infra pages' parity baselines (regenerated:
every change adds the figure lane and its text; the cost page's parity failures are upstream's own).
Live-checked on a 78-pod / 20-host / 18-container fleet: every figure ÷ its divisor equals the percent beside
it.
…or pod

The memory total and the pod limits were paired per scrape, so the group
grew with hosts or pods times scrapes in the window. They are now plain
per-key aggregates: total = avg used bytes / avg used share, and a limit is
usage / share at the highest sample, the lowest and the total, given only
when the three agree and every usage sample has its share. Same figures on
real data. The filesystem totals query gets its own cache id.
… series

One row per infra series, hour and retention period from metrics_sum and
metrics_gauge, with the resource and point attributes cut to the keys the
infra pages read. The per-core cpu attribute is dropped, so a host's CPU
states fold into one row. Rows carry sum, count, max, min, positive-only
stats, first and last seen, and earliest, latest and peak-time states,
enough for every aggregate the infra list and detail queries take.

RetentionDays is copied from the raw points and partitions the table like
the raw tables do, so an hour of a short-period source expires with its
points. Migration 0078 backfills 90 days before the views exist; Tinybird
replays history on the first deploy (not in SKIP_BACKFILL). Local schema
v70.
The infra list and detail queries aggregate per-series partials: whole
hours from infra_metrics_hourly, the partial hours at the ends from raw
points, so a 7-day window no longer scans every raw point. Each query
names the attribute keys it reads, and reading any other key is a type
error. Pod and workload limits come from the same pass as their row, so
the second scan and its join are gone.

A window of six hours or more takes its start on the hour: raw points
sort by series then time, so a raw edge costs its whole day partition.
A cluster without migration 0078 falls back to raw points (the API,
the MCP tools), and the chDB suite holds every routed read equal to its
raw twin.
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0563acc9-d12a-4be5-8682-020799ee4415

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@maple-review-bot

This comment has been minimized.

@Makisuo Makisuo added the preview:web Deploy a Workers-only PR preview (no ingest/Electric); see docs/pr-previews.md label Dec 4, 2026

@maple-review-bot maple-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 inline note from Maple's review. The score and summary are in the review comment above.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

🍁 Maple PR preview

Warning

Preview cleanup could not be confirmed. The Alchemy teardown outcome was failure.

Final commit de80041 · View workflow run

@maple-review-bot

This comment has been minimized.

The container summary reads it beside the memory and restart counters the
rollup already keeps.
@maple-review-bot

This comment has been minimized.

A window of six hours or more reaches the engine with its start on the
hour, so the rollup reads the first hour whole: the chDB suite now runs
every routed read over such a window against its raw twin. The snap test
pins the six-hour boundary itself. The MCP tools' raw fallback logs and
marks the span as the API's does.
@Makisuo

Makisuo commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Review findings, all fixed in 6bef734:

  • F1: the snapped long-window parity run is added (see the thread).
  • F2: the snap test now pins the boundary. 11:00:01 → 17:00:01 is exactly six hours, and it snaps to 11:00:00.
  • F3: rollupRead now logs the missing-rollup warning, with the org id, and sets query.rollup.fallback on the current span, the same as makeRollupFallback does for the API.

Before merge: on a managed cluster, migration 0078 is applied by the schema apply. Until then both the API and the MCP reads fall back to raw points, and that fallback is now logged on both paths.

Makisuo and others added 2 commits December 4, 2026 21:18
…streak test (#3271)

Assigning undefined back to process.exitCode is a no-op in Bun, so the 78
a chDB refusal sets leaked out whenever this file ran before any other set
the exit code: the CLI suite failed with every test passing.
@Makisuo Makisuo removed the preview:web Deploy a Workers-only PR preview (no ingest/Electric); see docs/pr-previews.md label Dec 4, 2026
Rounding a long window's start to the hour spared one day partition of raw
reads but left the summaries covering up to 59 minutes their charts,
facets and MCP tools did not. Measured on 7 days of a real org, the exact
start costs 1.75s for the hosts list (1.0s snapped, 19s before), so every
read now takes the window as sent. The long-window parity run keeps an
hour-aligned start, the splice's aligned case.
@Makisuo

Makisuo commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

F4: fixed in 5e203f0 by dropping the start snap, not by snapping the charts too. Snapped charts would return points before the x-axis start the page asks for. Without the snap, every read takes the window exactly as sent, so a page's summary, charts, facets and the MCP tools cover one window.

The cost, measured on 7 days of the same org: hosts list 1.75s (1.0s snapped, 19.2s on main), host detail 0.99s (0.25s snapped), pod and workload reads 0.1 to 0.2s. The long-window parity run now starts on the hour, so it still covers the splice's aligned-start case. The PR description has the updated numbers.

@maple-review-bot

This comment has been minimized.

# Conflicts:
#	apps/cli/test/infra-metrics-hourly.test.ts
#	packages/query-engine/src/__sql_baseline__/catalog.sql
#	packages/query-engine/src/ch/queries/infra.test.ts
#	packages/query-engine/src/ch/queries/infra.ts
@Makisuo
Makisuo merged commit f038356 into main Dec 4, 2026
9 checks passed
@Makisuo
Makisuo deleted the infra-rollup/reads branch December 4, 2026 23:42
@maple-review-bot

maple-review-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Maple review

🟡 Confidence 6/10 · needs attention. Held at 6 because a performance warning is open.
1 warning −1 · tests covered · risk medium

The seven infra list and detail reads now splice infra_metrics_hourly whole hours with raw edge points, each with a …Raw twin for clusters without migration 0078. The re-aggregation is faithful and pinned by chDB parity; the raw twin of the hosts list regresses to a timeout at 7 days.

  • Infra hosts, pods and workload reads aggregate per-series partials from infra_metrics_hourly
  • Each read gains a …Raw twin, taken when migration 0078 is missing
  • Means, peaks and last values rebuilt from Total/Samples/Peak/Latest
  • Pod and workload limits come from the same pass as their row

Findings

🟠 Warning · F5 · listHostsQuery raw twin times out at a 7-day window

performance · packages/query-engine/src/ch/queries/infra.ts:397-399

On a cluster without migration 0078 the raw twin groups raw points per series with two keysMap builds (infra-partials.ts:96-123) instead of aggregating them in one pass. Its 7-day window times out where it took 19.2s on main, and 24h doubles to 6.8s, so the hosts page errors on those clusters.

Keep the pre-change single-pass aggregate for `tier: "raw"` in the hosts list, so an un-migrated cluster still returns rows for long windows.
🤖 Prompt to fix this finding with an AI agent
Findings from an automated review of commit 2e845805ebf8732c56db05cd9f8d3c5d1a0220a0. Verify each one against the current code before changing anything, fix only those that still apply, and keep each fix to the lines it names.

---

F5 · Warning · performance · packages/query-engine/src/ch/queries/infra.ts:397-399
`listHostsQuery` raw twin times out at a 7-day window
On a cluster without migration 0078 the raw twin groups raw points per series with two `keysMap` builds (`infra-partials.ts:96-123`) instead of aggregating them in one pass. Its 7-day window times out where it took 19.2s on main, and 24h doubles to 6.8s, so the hosts page errors on those clusters.
Suggested fix: Keep the pre-change single-pass aggregate for `tier: "raw"` in the hosts list, so an un-migrated cluster still returns rows for long windows.

2e84580 · What was checked, coverage and telemetry details are on the Maple / review check. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.

@maple-review-bot maple-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 inline note from Maple's review. The score and summary are in the review comment above.

@@ -339,39 +395,37 @@ export interface ListHostsOutput {
}

export function listHostsQuery(opts: ListHostsOpts = {}) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

listHostsQuery raw twin times out at a 7-day window

F5 · Warning · performance

On a cluster without migration 0078 the raw twin groups raw points per series with two keysMap builds (infra-partials.ts:96-123) instead of aggregating them in one pass. Its 7-day window times out where it took 19.2s on main, and 24h doubles to 6.8s, so the hosts page errors on those clusters.

Keep the pre-change single-pass aggregate for `tier: "raw"` in the hosts list, so an un-migrated cluster still returns rows for long windows.
🤖 Prompt to fix with an AI agent
In `packages/query-engine/src/ch/queries/infra.ts:397-399`: `listHostsQuery` raw twin times out at a 7-day window.

On a cluster without migration 0078 the raw twin groups raw points per series with two `keysMap` builds (`infra-partials.ts:96-123`) instead of aggregating them in one pass. Its 7-day window times out where it took 19.2s on main, and 24h doubles to 6.8s, so the hosts page errors on those clusters.

Suggested fix: Keep the pre-change single-pass aggregate for `tier: "raw"` in the hosts list, so an un-migrated cluster still returns rows for long windows.

Verify the problem exists at that location before changing it, and keep the fix to those lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants