Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"trailingComma": "none",
"printWidth": 160,
"arrowParens": "always",
"objectWrap": "collapse",
"objectWrap": "preserve",
"plugins": ["prettier-plugin-tailwindcss"],
"tailwindStylesheet": "src/app/globals.css",
"tailwindFunctions": ["cn", "cva"],
Expand Down
4 changes: 4 additions & 0 deletions GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ _Avoid_: global Add-on configuration, runtime version cache
The Cluster Add-on that installs the Agent Sandbox controller and its extension CRDs, including SandboxTemplate and SandboxWarmPool. It does not create user workload resources.
_Avoid_: Agent, Agent runtime

**Node Monitoring History**:
A record of CPU, memory, and occupied node filesystem usage over time for each cluster node. Cluster totals include all nodes measured at a given time.
_Avoid_: App monitoring history, volume usage

**App**:
A deployable workload managed by QuickStack.

Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const eslintConfig = [
"unused-imports": unusedImports,
},
rules: {
"curly": ["error", "all"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE "NodeMonitoringSample" (
"id" TEXT NOT NULL PRIMARY KEY,
"sampledAt" DATETIME NOT NULL,
"nodeName" TEXT NOT NULL,
"cpuCores" REAL,
"ramBytes" REAL,
"diskBytes" REAL
);
CREATE INDEX "NodeMonitoringSample_sampledAt_idx" ON "NodeMonitoringSample"("sampledAt");
CREATE INDEX "NodeMonitoringSample_nodeName_sampledAt_idx" ON "NodeMonitoringSample"("nodeName", "sampledAt");
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Monitoring history is beta data: discard existing App and Node samples.
DROP TABLE "AppMonitoringSample";
DROP TABLE "NodeMonitoringSample";

CREATE TABLE "MonitoringSample" (
"id" TEXT NOT NULL PRIMARY KEY,
"sampledAt" DATETIME NOT NULL,
"measuredAt" DATETIME,
"appId" TEXT,
"nodeName" TEXT,
"cpuCores" REAL,
"ramBytes" REAL,
"nodeFilesystemUsedBytes" REAL,
CONSTRAINT "MonitoringSample_appId_fkey" FOREIGN KEY ("appId") REFERENCES "App" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "MonitoringSample_owner_check" CHECK (("appId" IS NOT NULL AND "nodeName" IS NULL) OR ("appId" IS NULL AND "nodeName" IS NOT NULL)),
CONSTRAINT "MonitoringSample_storage_check" CHECK ("appId" IS NULL OR "nodeFilesystemUsedBytes" IS NULL)
);
CREATE INDEX "MonitoringSample_appId_sampledAt_idx" ON "MonitoringSample"("appId", "sampledAt");
CREATE INDEX "MonitoringSample_nodeName_sampledAt_idx" ON "MonitoringSample"("nodeName", "sampledAt");
CREATE INDEX "MonitoringSample_sampledAt_idx" ON "MonitoringSample"("sampledAt");
24 changes: 14 additions & 10 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ model App {
appPorts AppPort[]
appNodePorts AppNodePort[]
appVolumes AppVolume[]
monitoringSamples AppMonitoringSample[]
monitoringSamples MonitoringSample[]
appFileMounts AppFileMount[]
appBasicAuths AppBasicAuth[]
appGitSshKey AppGitSshKey?
Expand Down Expand Up @@ -649,17 +649,21 @@ model AppBasicAuth {
updatedAt DateTime @updatedAt
}

// One row per known App and Volume at each collection time. Null values are gaps.
model AppMonitoringSample {
id String @id @default(uuid())
sampledAt DateTime
appId String
app App @relation(fields: [appId], references: [id], onDelete: Cascade)
cpuCores Float?
ramBytes Float?
measuredAt DateTime?
// One row per App or Node at each collection time. Null metric values are gaps.
// The migration enforces exactly one owner and reserves filesystem usage for Nodes.
model MonitoringSample {
id String @id @default(uuid())
sampledAt DateTime
measuredAt DateTime?
appId String?
app App? @relation(fields: [appId], references: [id], onDelete: Cascade)
nodeName String?
cpuCores Float?
ramBytes Float?
nodeFilesystemUsedBytes Float?

@@index([appId, sampledAt])
@@index([nodeName, sampledAt])
@@index([sampledAt])
}

Expand Down
176 changes: 94 additions & 82 deletions src/__tests__/integration/server/mcp/mcp-eval.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,93 +7,105 @@ import { z } from 'zod';
import { createQuickStackMcpHandler } from '@/server/mcp/mcp-handler';

function runHarness(url: string, apiKey: string): Promise<{ code: number | null; stdout: string; stderr: string }> {
return new Promise((resolve, reject) => {
const child = spawn(process.execPath, ['scripts/mcp-eval.mjs', '--url', url, '--api-key', apiKey], {
cwd: process.cwd(),
env: process.env,
});
let stdout = '';
let stderr = '';
child.stdout.on('data', (chunk) => { stdout += chunk.toString(); });
child.stderr.on('data', (chunk) => { stderr += chunk.toString(); });
child.on('error', reject);
child.on('close', (code) => resolve({ code, stdout, stderr }));
return new Promise((resolve, reject) => {
const child = spawn(process.execPath, ['scripts/mcp-eval.mjs', '--url', url, '--api-key', apiKey], {
cwd: process.cwd(),
env: process.env
});
let stdout = '';
let stderr = '';
child.stdout.on('data', (chunk) => {
stdout += chunk.toString();
});
child.stderr.on('data', (chunk) => {
stderr += chunk.toString();
});
child.on('error', reject);
child.on('close', (code) => resolve({ code, stdout, stderr }));
});
}

describe('MCP evaluation harness', () => {
it('runs the scripted tasks against the real MCP handler', async () => {
const fixture = new Elysia({ prefix: '/api/v1' })
.get('/projects', ({ query }) => {
const projects = [{ id: 'p1', name: 'Demo' }, { id: 'p2', name: 'Second' }];
if (query.limit === undefined) return projects;
const limit = Number(query.limit);
return {
items: projects.slice(0, limit),
total: projects.length,
limit,
nextCursor: limit < projects.length ? String(limit) : null,
};
}, {
query: z.object({ limit: z.coerce.number().optional() }),
response: { 200: z.union([z.array(z.object({ id: z.string(), name: z.string() })), z.object({
items: z.array(z.object({ id: z.string(), name: z.string() })),
total: z.number(),
limit: z.number(),
nextCursor: z.string().nullable(),
})]) },
detail: { operationId: 'listProjects', summary: 'List projects', tags: ['Projects'] },
})
.post('/apps/:appId/deploy', ({ params }) => ({ deploymentId: `deploy-${params.appId}` }), {
params: z.object({ appId: z.string() }),
query: z.object({ forceRebuild: z.coerce.boolean().optional() }),
response: { 200: z.object({ deploymentId: z.string() }) },
detail: { operationId: 'deployApp', summary: 'Deploy app', description: 'Deploy an app.', tags: ['Apps'] },
});
it('runs the scripted tasks against the real MCP handler', async () => {
const fixture = new Elysia({ prefix: '/api/v1' })
.get(
'/projects',
({ query }) => {
const projects = [
{ id: 'p1', name: 'Demo' },
{ id: 'p2', name: 'Second' }
];
if (query.limit === undefined) {
return projects;
}
const limit = Number(query.limit);
return {
items: projects.slice(0, limit),
total: projects.length,
limit,
nextCursor: limit < projects.length ? String(limit) : null
};
},
{
query: z.object({ limit: z.coerce.number().optional() }),
response: {
200: z.union([
z.array(z.object({ id: z.string(), name: z.string() })),
z.object({
items: z.array(z.object({ id: z.string(), name: z.string() })),
total: z.number(),
limit: z.number(),
nextCursor: z.string().nullable()
})
])
},
detail: { operationId: 'listProjects', summary: 'List projects', tags: ['Projects'] }
}
)
.post('/apps/:appId/deploy', ({ params }) => ({ deploymentId: `deploy-${params.appId}` }), {
params: z.object({ appId: z.string() }),
query: z.object({ forceRebuild: z.coerce.boolean().optional() }),
response: { 200: z.object({ deploymentId: z.string() }) },
detail: { operationId: 'deployApp', summary: 'Deploy app', description: 'Deploy an app.', tags: ['Apps'] }
});

const handler = createQuickStackMcpHandler({
app: fixture,
resolveAuthInfo: async () => ({ token: 'eval-token', clientId: 'eval', scopes: [] }),
});
const server = createServer(async (request, response) => {
const chunks: Buffer[] = [];
for await (const chunk of request) {
chunks.push(Buffer.from(chunk));
}
const method = request.method ?? 'GET';
const body = method === 'GET' || method === 'HEAD'
? undefined
: new Uint8Array(Buffer.concat(chunks));
const fetchResponse = await handler.fetch(new Request(
`http://127.0.0.1${request.url ?? '/api/mcp'}`,
{
method,
headers: request.headers as Record<string, string>,
body,
}
));
response.statusCode = fetchResponse.status;
fetchResponse.headers.forEach((value, key) => response.setHeader(key, value));
response.end(Buffer.from(await fetchResponse.arrayBuffer()));
});
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve));
const handler = createQuickStackMcpHandler({
app: fixture,
resolveAuthInfo: async () => ({ token: 'eval-token', clientId: 'eval', scopes: [] })
});
const server = createServer(async (request, response) => {
const chunks: Buffer[] = [];
for await (const chunk of request) {
chunks.push(Buffer.from(chunk));
}
const method = request.method ?? 'GET';
const body = method === 'GET' || method === 'HEAD' ? undefined : new Uint8Array(Buffer.concat(chunks));
const fetchResponse = await handler.fetch(
new Request(`http://127.0.0.1${request.url ?? '/api/mcp'}`, {
method,
headers: request.headers as Record<string, string>,
body
})
);
response.statusCode = fetchResponse.status;
fetchResponse.headers.forEach((value, key) => response.setHeader(key, value));
response.end(Buffer.from(await fetchResponse.arrayBuffer()));
});
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve));

try {
const address = server.address();
if (!address || typeof address === 'string') {
throw new Error('Test server did not expose a port.');
}
const { code, stdout, stderr } = await runHarness(
`http://127.0.0.1:${address.port}/api/mcp`,
'eval-token'
);
try {
const address = server.address();
if (!address || typeof address === 'string') {
throw new Error('Test server did not expose a port.');
}
const { code, stdout, stderr } = await runHarness(`http://127.0.0.1:${address.port}/api/mcp`, 'eval-token');

expect(stderr).toBe('');
expect(stdout).toContain('Success: 3/3 tasks');
expect(code).toBe(0);
} finally {
await handler.close();
await new Promise<void>((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
}
}, 60_000);
expect(stderr).toBe('');
expect(stdout).toContain('Success: 3/3 tasks');
expect(code).toBe(0);
} finally {
await handler.close();
await new Promise<void>((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())));
}
}, 60_000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
vi.mock('@/server/adapter/kubernetes-api.adapter', () => ({ default: {} }));

import { createPrismaTestContext } from '@/__tests__/prisma-test.utils';
import adapter from '@/server/adapter/app-history.adapter';
import nodeHistory from '@/server/services/standalone-services/node-monitoring-history.service';
import history from '@/server/services/standalone-services/app-monitoring-history.service';
import metrics from '@/server/services/standalone-services/app-history.service';
import filesystem from '@/server/services/standalone-services/app-volume-filesystem.service';
Expand All @@ -15,7 +15,7 @@ describe('App monitoring history persistence', () => {
await db.project.create({ data: { id: 'project', name: 'Project' } });
await db.app.create({ data: { id: 'app', name: 'App', projectId: 'project' } });
const cutoff = new Date(Date.now() - 3600_000);
await adapter.save(
await history.save(
[
{ appId: 'app', sampledAt: new Date(cutoff.getTime() - 1), cpuCores: 1, ramBytes: 2 },
{ appId: 'app', sampledAt: cutoff, cpuCores: 3, ramBytes: 4 }
Expand All @@ -34,11 +34,11 @@ describe('App monitoring history persistence', () => {
await db.project.create({ data: { id: 'project', name: 'Project' } });
await db.app.create({ data: { id: 'app', name: 'App', projectId: 'project' } });
const now = Date.now();
await adapter.save([{ appId: 'app', sampledAt: new Date(now - 2 * 3600_000), cpuCores: 1, ramBytes: 2 }], [], [], new Date(now - 24 * 3600_000));
await adapter.setRetentionHours(1);
await history.save([{ appId: 'app', sampledAt: new Date(now - 2 * 3600_000), cpuCores: 1, ramBytes: 2 }], [], [], new Date(now - 24 * 3600_000));
await history.setRetentionHours(1);
expect((await history.getHistory(['app'])).points).toEqual([]);
await adapter.save([], [], [], new Date(now - (await adapter.getRetentionHours()) * 3600_000));
expect(await db.appMonitoringSample.count()).toBe(0);
await history.save([], [], [], new Date(now - (await history.getRetentionHours()) * 3600_000));
expect(await db.monitoringSample.count()).toBe(0);
});

it('stores shared Volume usage once and exposes it only through accessible mounts', async () => {
Expand All @@ -53,7 +53,7 @@ describe('App monitoring history persistence', () => {
await db.appVolume.create({ data: { id: 'base', appId: 'one', containerMountPath: '/data', size: 1 } });
await db.appVolume.create({ data: { id: 'shared', appId: 'two', containerMountPath: '/share', size: 1, sharedVolumeId: 'base' } });
const sampledAt = new Date();
await adapter.save(
await history.save(
[],
[{ id: 'sample', volumeId: 'base', sampledAt, status: 'available', usedBytes: 42, measuredAt: sampledAt }],
[
Expand Down Expand Up @@ -104,6 +104,24 @@ describe('App monitoring history persistence', () => {
}
});

it('keeps App and Node histories separate in the shared table', async () => {
const db = ctx.getDataAccess().client;
await db.project.create({ data: { id: 'project', name: 'Project' } });
await db.app.create({ data: { id: 'app', name: 'App', projectId: 'project' } });
const sampledAt = new Date();
const cutoff = new Date(sampledAt.getTime() - 3600_000);
await history.save([{ appId: 'app', sampledAt, cpuCores: 1, ramBytes: 2 }], [], [], cutoff);
await nodeHistory.save([{ nodeName: 'node', sampledAt, measuredAt: sampledAt, cpuCores: 3, ramBytes: 4, nodeFilesystemUsedBytes: 5 }], cutoff);
expect((await history.getRawHistory(['app'], cutoff))[0]).toHaveLength(1);
expect(await db.monitoringSample.findMany({ where: { nodeName: { not: null }, sampledAt: { gte: cutoff } } })).toMatchObject([
{ nodeName: 'node', measuredAt: sampledAt, nodeFilesystemUsedBytes: 5 }
]);
await db.app.delete({ where: { id: 'app' } });
expect(await db.monitoringSample.findMany({ where: { nodeName: { not: null }, sampledAt: { gte: cutoff } } })).toHaveLength(1);
await nodeHistory.save([], new Date(sampledAt.getTime() + 1));
expect(await db.monitoringSample.findMany({ where: { nodeName: { not: null }, sampledAt: { gte: cutoff } } })).toHaveLength(0);
});

it('reads a day of five-minute history for 100 Apps', async () => {
const db = ctx.getDataAccess().client;
await db.project.create({ data: { id: 'project', name: 'Project' } });
Expand All @@ -113,7 +131,7 @@ describe('App monitoring history persistence', () => {
const samples = Array.from({ length: 288 }, (_, index) =>
appIds.map((appId) => ({ appId, sampledAt: new Date(now - index * 5 * 60_000), cpuCores: 0.25, ramBytes: 1024 }))
).flat();
await adapter.save(samples, [], [], new Date(now - 24 * 3600_000));
await history.save(samples, [], [], new Date(now - 24 * 3600_000));
const result = await history.getHistory(appIds);
expect(result.points).toHaveLength(288);
expect(result.points[0]).toMatchObject({ cpuCores: 25, ramBytes: 102400 });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @vitest-environment node
import Database from 'better-sqlite3';
import { readFileSync } from 'node:fs';

it('replaces beta samples while preserving volumes and enforcing ownership and cascade rules', () => {
const db = new Database(':memory:');
db.pragma('foreign_keys = ON');
try {
db.exec(`
CREATE TABLE App (id TEXT PRIMARY KEY);
CREATE TABLE AppMonitoringSample (id TEXT PRIMARY KEY);
CREATE TABLE NodeMonitoringSample (id TEXT PRIMARY KEY);
CREATE TABLE AppVolumeMonitoringSample (id TEXT PRIMARY KEY);
INSERT INTO App VALUES ('app');
INSERT INTO AppMonitoringSample VALUES ('old-app');
INSERT INTO NodeMonitoringSample VALUES ('old-node');
INSERT INTO AppVolumeMonitoringSample VALUES ('volume');
`);
db.exec(readFileSync('prisma/migrations/20261116130000_unify_monitoring_samples/migration.sql', 'utf8'));
expect(db.prepare('SELECT count(*) AS n FROM MonitoringSample').get()).toEqual({ n: 0 });
expect(db.prepare('SELECT count(*) AS n FROM AppVolumeMonitoringSample').get()).toEqual({ n: 1 });
const insert = db.prepare('INSERT INTO MonitoringSample (id, sampledAt, appId, nodeName, nodeFilesystemUsedBytes) VALUES (?, ?, ?, ?, ?)');
insert.run('app-sample', 1, 'app', null, null);
insert.run('node-sample', 1, null, 'node', 5);
expect(() => insert.run('none', 1, null, null, null)).toThrow();
expect(() => insert.run('both', 1, 'app', 'node', null)).toThrow();
expect(() => insert.run('storage-on-app', 1, 'app', null, 5)).toThrow();
expect(() => insert.run('missing-app', 1, 'missing', null, null)).toThrow();
db.prepare('DELETE FROM App WHERE id = ?').run('app');
expect(db.prepare('SELECT id FROM MonitoringSample').all()).toEqual([{ id: 'node-sample' }]);
} finally {
db.close();
}
});
Loading
Loading