Skip to content
Closed
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
39 changes: 36 additions & 3 deletions apps/ai/src/mcp/__evals__/infra-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ const podStats = (p: Pod) => {
const memoryLimitPct = p.unbounded ? 0 : avgOf(p.memory)
const memoryLimitPctPeak = p.unbounded ? 0 : peakOf(p.memory)
return {
memoryUsage: avgOf(workingSet(p)),
cpuUsage,
cpuUsagePeak,
cpuLimitPct: ofLimit(cpuUsage),
Expand Down Expand Up @@ -280,6 +281,14 @@ const podListRow = (sql: string, p: Pod) => {
...stats,
cpuRequestPct: stats.cpuLimitPct * 2,
memoryRequestPct: stats.memoryLimitPct * 1.5,
// The working-set curve's peak, limited or not, over the limit that curve uses.
memoryBytesPeak: peakOf(workingSet(p)),
memoryLimitBytes: p.unbounded ? 0 : memoryLimitOf(p),
cpuLimitCores: p.cpuLimitCores,
memoryUsage: avgOf(workingSet(p)),
// The request shares above are 2× and 1.5× the limit shares: requests of ½ and ⅔ the limit.
cpuRequestCores: p.cpuLimitCores / 2,
memoryRequestBytes: p.unbounded ? 0 : (memoryLimitOf(p) * 2) / 3,
}
}

Expand Down Expand Up @@ -550,10 +559,11 @@ const MEMORY_LIMIT_BYTES = new Map([
["postgres", 4 * 2 ** 30],
["api-gateway", 2 ** 30],
])
const memoryLimitOf = (p: Pod) => MEMORY_LIMIT_BYTES.get(p.owner[1]) ?? 2 ** 30
const workingSet =
(p: Pod): Curve =>
(t) =>
p.unbounded ? 150 * 2 ** 20 : p.memory(t) * (MEMORY_LIMIT_BYTES.get(p.owner[1]) ?? 2 ** 30)
p.unbounded ? 150 * 2 ** 20 : p.memory(t) * memoryLimitOf(p)

/** Container restarts: the OOM-killed checkout pod restarted once in the window. */
const RESTARTS = new Map<string, number>([[INFRA_WORLD.oomPod, 1]])
Expand Down Expand Up @@ -585,10 +595,20 @@ const workloadRows = (sql: string) => {
avgCpuLimitPct: mean((s) => s.cpuLimitPct),
avgMemoryLimitPct: mean((s) => s.memoryLimitPct),
avgCpuUsage: mean((s) => s.cpuUsage),
avgMemoryUsage: mean((s) => s.memoryUsage),
peakCpuLimitPct: Math.max(...Arr.map(stats, (s) => s.cpuLimitPctPeak)),
peakMemoryLimitPct: Math.max(...Arr.map(stats, (s) => s.memoryLimitPctPeak)),
saturation: Math.max(...Arr.map(stats, (s) => Math.max(s.cpuLimitPctPeak, s.memoryLimitPctPeak))),
cpuUsage: Arr.reduce(stats, 0, (sum, s) => sum + s.cpuUsage),
// One limit across the pods, else none (`steadyDivisor`).
cpuLimitCores:
new Set(Arr.map(pods, (p) => p.cpuLimitCores)).size === 1 ? (pods[0]?.cpuLimitCores ?? 0) : 0,
memoryLimitBytes:
new Set(Arr.map(pods, (p) => (p.unbounded ? 0 : memoryLimitOf(p)))).size === 1 &&
pods[0] !== undefined &&
!pods[0].unbounded
? memoryLimitOf(pods[0])
: 0,
desiredReplicas: pods.length,
readyReplicas: pods.length,
replicaSamples: 1,
Expand All @@ -600,6 +620,9 @@ const workloadRows = (sql: string) => {
})
}

/** Every container runs under a 2 GiB limit; list and detail derive their bytes from it. */
const CONTAINER_MEMORY_LIMIT_BYTES = 2 * 1024 ** 3

const containerRow = (sql: string, c: (typeof CONTAINERS)[number]) => ({
containerName: c.containerName,
hostName: c.hostName,
Expand All @@ -619,6 +642,9 @@ const containerRow = (sql: string, c: (typeof CONTAINERS)[number]) => ({
cpuLimitCores: c.cpuLimitCores,
uptimeSeconds: 5_400,
saturation: Math.max(peakOf(c.cpu), peakOf(c.memory)),
// The limit the detail counters report; the bytes are its share.
memoryBytesPeak: peakOf(c.memory) * CONTAINER_MEMORY_LIMIT_BYTES,
memoryLimitBytes: CONTAINER_MEMORY_LIMIT_BYTES,
})

export const infraFixtureRules = (): FixtureRule[] => [
Expand Down Expand Up @@ -755,8 +781,8 @@ export const infraFixtureRules = (): FixtureRule[] => [
Arr.map(
Arr.filter(CONTAINERS, (c) => matches(sql, "container.name", c.containerName)),
(c) => ({
memoryBytesAvg: 1_200_000_000,
memoryLimitBytes: 2_147_483_648,
memoryBytesAvg: avgOf(c.memory) * CONTAINER_MEMORY_LIMIT_BYTES,
memoryLimitBytes: CONTAINER_MEMORY_LIMIT_BYTES,
restartsDelta: c.restarts,
pidsAvg: 48,
}),
Expand Down Expand Up @@ -805,6 +831,13 @@ export const infraFixtureRules = (): FixtureRule[] => [
memoryPct: avgOf(h.memory),
diskPct: Math.max(...Arr.map(h.filesystems, (fs) => fs.used)),
load15: avgOf(h.load15),
// Every world host has 8 cores and 16 GiB.
cpuCores: 8,
memoryUsedBytes: avgOf(h.memory) * 16 * GIB,
memoryTotalBytes: 16 * GIB,
// and a 100 GiB root disk.
diskUsedBytes: Math.max(...Arr.map(h.filesystems, (fs) => fs.used)) * 100 * GIB,
diskTotalBytes: 100 * GIB,
cloudProvider: "aws",
cloudRegion: "eu-central-1",
sourceId: "src_infra_world",
Expand Down
33 changes: 31 additions & 2 deletions apps/api/src/routes/internal/query-engine.http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ import { AWS_INFRA_KIND_IDS, AWS_INFRA_KINDS } from "@maple/domain/aws-infra"
import { GCP_INFRA_SERVICE_IDS, gcpInfraMetrics } from "@maple/domain/gcp-infra"
import { SESSION_LIVE_WINDOW_SECONDS } from "@maple/domain/query-engine"
import { isAiContentFormat } from "@maple/domain/ai-traffic"
import { DateTime, Duration, Effect, Option, Order, Schema, Array as Arr } from "effect"
import { DateTime, Duration, Effect, Option, Order, Schema, Array as Arr, Record as Rec } from "effect"
import { QueryEngineService } from "@maple/backend/services/warehouse/QueryEngineService"
import {
isMissingAwsMetricsHourly,
Expand Down Expand Up @@ -1868,7 +1868,15 @@ export const HttpQueryEngineLive = HttpApiBuilder.group(MapleInternalApi, "query
})
}

const rows = yield* runQuery(Queries.hostInfraGaugeTimeseries, tenant, payload)
const [rows, totals] = yield* Effect.all(
[
runQuery(Queries.hostInfraGaugeTimeseries, tenant, payload),
spec.family === "filesystem"
? runQuery(Queries.hostInfraFilesystemTotals, tenant, payload)
: Effect.succeed([]),
],
{ concurrency: 2 },
)
return new HostInfraTimeseriesResponse({
data: Arr.map(rows, (row) => ({
bucket: DateTime.formatIso(row.bucket),
Expand All @@ -1877,6 +1885,17 @@ export const HttpQueryEngineLive = HttpApiBuilder.group(MapleInternalApi, "query
})),
groupByAttributeKey: spec.groupByAttributeKey,
unit: spec.unit,
...(spec.family === "filesystem"
? {
totals: Rec.fromEntries(
Arr.flatMap(totals, (row) =>
row.totalBytes > 0
? [[row.mountpoint, row.totalBytes] as const]
: [],
),
),
}
: undefined),
})
}),
)
Expand Down Expand Up @@ -1915,6 +1934,9 @@ export const HttpQueryEngineLive = HttpApiBuilder.group(MapleInternalApi, "query
cpuLimitPctPeak: row.cpuLimitPctPeak,
memoryLimitPctPeak: row.memoryLimitPctPeak,
saturation: row.saturation,
memoryBytesPeak: row.memoryBytesPeak,
memoryLimitBytes: row.memoryLimitBytes,
cpuLimitCores: row.cpuLimitCores,
})),
// The denominator has to match the predicate the list ran, or a scoped
// view reads "Top 17 of 541". The scope counts are already computed
Expand Down Expand Up @@ -1997,6 +2019,8 @@ export const HttpQueryEngineLive = HttpApiBuilder.group(MapleInternalApi, "query
cpuLimitCores: row.cpuLimitCores,
uptimeSeconds: row.uptimeSeconds,
saturation: row.saturation,
memoryBytesPeak: row.memoryBytesPeak,
memoryLimitBytes: row.memoryLimitBytes,
})),
// The denominator has to match the predicate the list ran (see listPods).
totalCount: countOrRowCount(
Expand Down Expand Up @@ -2170,6 +2194,8 @@ export const HttpQueryEngineLive = HttpApiBuilder.group(MapleInternalApi, "query
peakCpuLimitPct: row.peakCpuLimitPct,
peakMemoryLimitPct: row.peakMemoryLimitPct,
cpuUsage: row.cpuUsage,
cpuLimitCores: row.cpuLimitCores,
memoryLimitBytes: row.memoryLimitBytes,
})),
})
}),
Expand All @@ -2191,6 +2217,9 @@ export const HttpQueryEngineLive = HttpApiBuilder.group(MapleInternalApi, "query
avgCpuLimitPct: row.avgCpuLimitPct,
avgMemoryLimitPct: row.avgMemoryLimitPct,
avgCpuUsage: row.avgCpuUsage,
avgMemoryUsage: row.avgMemoryUsage,
cpuLimitCores: row.cpuLimitCores,
memoryLimitBytes: row.memoryLimitBytes,
}
: null,
})
Expand Down
18 changes: 17 additions & 1 deletion apps/web/src/lab/bench/infra-bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MetricChart, TitledHeader } from "@maple/views/kit/charts/InfraMetricCh
import { LINKED_CURSOR_STYLE, MountLinkedCursor } from "@maple/views/kit/charts/LinkedCursor"
import { Panel } from "@maple/views/kit/Panel"
import { styleText } from "@maple/views/kit/style-text"
import { ANY_SERIES, type ChartAbsolute } from "@maple/views/lib/infra-chart-units"
import { Array as Arr } from "effect"
import { AsyncResult } from "effect/reactivity"
import { HostSeriesSummary, K8sChart, type SeriesRead } from "../../native/kit/InfraCharts"
Expand Down Expand Up @@ -40,6 +41,9 @@ const seriesOf = (rows: ReturnType<typeof makeRows>, unit: string): SeriesRead =
AsyncResult.success({ rows, unit })
const POD_CPU = seriesOf(makeRows(["api", "worker", "ingest"], 1, 2.2), "cores")
const POD_LIMIT = seriesOf(makeRows(["value"], 1, 3.3), "percent")
/** An 8-core host and a 2-core pod limit, so the share charts read cores beside their percents. */
const HOST_CORES: ChartAbsolute = { unit: "cores", totals: { [ANY_SERIES]: 8 } }
const POD_LIMIT_CORES: ChartAbsolute = { unit: "cores", totals: { [ANY_SERIES]: 2 } }

type H = Html.H<BenchMessage>

Expand All @@ -57,6 +61,7 @@ const hostChart = (h: H, state: BenchState, metric: "cpu" | "load15", label: str
rows: metric === "cpu" ? HOST_CPU_ROWS : HOST_LOAD_ROWS,
unit: metric === "cpu" ? "percent" : "load",
seriesLabel: label,
absolute: metric === "cpu" ? HOST_CORES : undefined,
stacked: isStacked,
showThreshold: isStacked,
linkedChartId: chartId,
Expand All @@ -75,12 +80,14 @@ const podChart = (
label: string,
title: string,
isStacked: boolean,
absolute?: ChartAbsolute,
) =>
K8sChart(h, {
...state.chart(chartId),
series,
chartId,
seriesLabel: label,
absolute,
title,
stacked: isStacked,
showThreshold: !isStacked,
Expand All @@ -103,6 +110,15 @@ export const lab = defineChartBench("Infra charts", {
hostChart(h, state, "cpu", "CPU", "CPU"),
hostChart(h, state, "load15", "Load (15m)", "Load"),
podChart(h, state, "pod-cpu_usage", POD_CPU, "CPU usage", "CPU by container", true),
podChart(h, state, "pod-cpu_limit", POD_LIMIT, "CPU / limit", "CPU vs limit", false),
podChart(
h,
state,
"pod-cpu_limit",
POD_LIMIT,
"CPU / limit",
"CPU vs limit",
false,
POD_LIMIT_CORES,
),
),
})
22 changes: 20 additions & 2 deletions apps/web/src/lab/infra-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { String as Str } from "effect"
*/
type HostRow = ListHostsResponse["data"][number]

const GIB = 1024 ** 3

export interface InfraLabFixture {
readonly end: string
readonly hosts: ReadonlyArray<HostRow>
Expand Down Expand Up @@ -146,6 +148,12 @@ export function buildInfraLabFixture(nowMs: number): InfraLabFixture {
memoryPct: number,
diskPct: number,
seenMs = 4_000,
/** Cores, total memory and root disk the host reported; all 0 for a host that sent none. */
capacity: Readonly<{ cores: number; memoryBytes: number; diskBytes: number }> = {
cores: 8,
memoryBytes: 16 * GIB,
diskBytes: 100 * GIB,
},
): HostRow => ({
hostName,
osType: "linux",
Expand All @@ -156,15 +164,25 @@ export function buildInfraLabFixture(nowMs: number): InfraLabFixture {
memoryPct,
diskPct,
load15: cpuPct * 8,
cpuCores: capacity.cores,
memoryUsedBytes: Math.round(memoryPct * capacity.memoryBytes),
memoryTotalBytes: capacity.memoryBytes,
diskUsedBytes: Math.round(diskPct * capacity.diskBytes),
diskTotalBytes: capacity.diskBytes,
})
const hosts: ReadonlyArray<HostRow> = [
host("worker-eu-07", 0.94, 0.62, 0.41),
host("api-eu-02", 0.81, 0.74, 0.33),
host("ingest-eu-01", 0.66, 0.58, 0.29),
host("db-proxy-eu-01", 0.47, 0.58, 0.19),
host("db-proxy-eu-01", 0.47, 0.58, 0.19, 4_000, {
cores: 4,
memoryBytes: 8 * GIB,
diskBytes: 50 * GIB,
}),
{ ...host("edge-eu-03", 0.22, 0.31, 0.12), cloudProvider: "gcp" },
{ ...host("win-agent-01", 0.19, 0.28, 0.12), osType: "windows", cloudProvider: "azure" },
host("scheduler-eu-01", 0.11, 0.24, 0.31),
// An older agent: percentages only, so the row shows no figures.
host("scheduler-eu-01", 0.11, 0.24, 0.31, 4_000, { cores: 0, memoryBytes: 0, diskBytes: 0 }),
{
...host("build-runner-03", 0.05, 0.12, 0.44, 2 * 60 * 60 * 1000),
osType: "darwin",
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/lab/worst-case-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ const host = (hostName: string, cpuPct: number, memoryPct: number, diskPct: numb
memoryPct,
diskPct,
load15: cpuPct * 8,
// 8 cores, 16 GiB, a 2 TiB disk: the widest figures the lane has to hold ("11.36 / 8 cores",
// "15.8 GB / 16.0 GB", "2.0 TB / 2.0 TB").
cpuCores: 8,
memoryUsedBytes: Math.round(memoryPct * 16 * 1024 ** 3),
memoryTotalBytes: 16 * 1024 ** 3,
diskUsedBytes: Math.round(diskPct * 2 * 1024 ** 4),
diskTotalBytes: 2 * 1024 ** 4,
})

export function hosts(mode: WorstCaseMode): ReadonlyArray<HostRow> {
Expand Down
42 changes: 33 additions & 9 deletions apps/web/src/native/kit/InfraCells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,38 @@ export const OffsetPager = <M>(h: Html.H<M>, options: OffsetPagerOptions<M>) =>
})
}

/** An `AvgPeak` in a list's right-aligned column, shown from `lg`. */
export const AvgPeakColumn = <M>(h: Html.H<M>, options: AvgPeakOptions) =>
h.div.class("hidden w-32 text-right lg:block").children(AvgPeak(h, options))
/**
* A fleet list's lanes key on the page column, which the sidebar narrows: each shows once the row holds
* it (padding 32 + name 256 + 16 per gap + the lanes before it + last seen 96) plus 56 of slack for the
* page gutter and a classic scrollbar. Without the meter lane the meters read under the name; a phone
* shows the status badge, not the age (needs 400).
*/
export const FLEET_LANES = {
meters: "hidden w-82 @min-[800px]/page:block",
metersHead: "hidden @min-[800px]/page:flex",
metersUnderName: "mt-2 @min-[800px]/page:hidden",
first: "hidden w-32 text-right @min-[944px]/page:block",
firstHead: "hidden @min-[944px]/page:flex",
second: "hidden w-32 text-right @min-[1088px]/page:block",
secondHead: "hidden @min-[1088px]/page:flex",
lastSeen: "hidden w-24 text-right @min-[456px]/page:block",
lastSeenHead: "hidden @min-[456px]/page:flex",
} as const

/** An `AvgPeak` in a list's right-aligned column: the first or second lane after the meters. */
export const AvgPeakColumn = <M>(h: Html.H<M>, options: AvgPeakOptions, lane: "first" | "second") =>
h.div.class(FLEET_LANES[lane]).children(AvgPeak(h, options))

/** A fleet row's loading cells: the meta line under the name, and the two peak meters from `md`. */
export const RowMetaSkeleton = <M>(h: Html.H<M>) => Skeleton(h, { className: "mt-1.5 h-3 w-40" })
/** A fleet row's loading cells: the meta line under the name (with the meters on a narrow page). */
export const RowMetaSkeleton = <M>(h: Html.H<M>) => [
Skeleton(h, { className: "mt-1.5 h-3 w-40" }),
Skeleton(h, { className: "mt-2 h-6 w-48 @min-[800px]/page:hidden" }),
]

export const PeakMetersSkeleton = <M>(h: Html.H<M>) =>
h.div
.class("hidden w-44 space-y-1.5 md:block")
.children(Skeleton(h, { className: "h-2.5 w-44" }), Skeleton(h, { className: "h-2.5 w-44" }))
/** The rest of a fleet row's loading cells: the meter lane, the two avg/peak lanes, last seen. */
export const LaneSkeletons = <M>(h: Html.H<M>) => [
Skeleton(h, { className: "hidden h-6 w-82 @min-[800px]/page:block" }),
Skeleton(h, { className: "hidden h-3 w-32 @min-[944px]/page:block" }),
Skeleton(h, { className: "hidden h-3 w-32 @min-[1088px]/page:block" }),
Skeleton(h, { className: "hidden h-3 w-24 @min-[456px]/page:block" }),
]
Loading