MCP: PromQL, dashboard-tile, pattern and `describe_source` tools return no cost statistics
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- backend, observability
调研方向
Start with formatQueryResult in packages/api/src/mcp/tools/query/helpers.ts, then runPromqlTile and summarizeRows in queryTiles.ts, and the pattern and catalog tools. Run the attached repro test with make dev-int FILE=reproToolStatistics. Done when every query tool's response includes a statistics key, and clickstack_query_tiles tiles report elapsedMs, rowsRead and bytesRead.
由索引模型根据 Issue 内容生成。
描述
Summary
clickstack_table, clickstack_timeseries and clickstack_sql return ClickHouse's statistics (elapsed, rows_read, bytes_read) with every result, and agents use it to tell a cheap query from an expensive one. The tools agents use most during an investigation return nothing:
clickstack_promqlclickstack_query_tileon a PromQL tile (a builder tile does returnstatistics)clickstack_query_tiles, which returns onlystatus/hasData/rowCountper tileclickstack_event_patternsandclickstack_emerging_signalsclickstack_describe_source
The builder tools have statistics only because ClickHouse's JSON output carries it and formatQueryResult (packages/api/src/mcp/tools/query/helpers.ts) passes the response through. The other tools build their own output (runPromqlTile, summarizeRows in queryTiles.ts, the pattern and catalog tools), and the numbers get dropped.
Environment
HyperDX main at c220e164 (2026-11-13), ClickHouse 26.10.3.7 (CI compose). Production-size numbers below are from a ClickHouse 26.10.3 server with about 110M log rows per hour and a TimeSeries table with about 217M series.
Steps to reproduce
reproToolStatistics.int.test.ts (below; copy to packages/api/src/mcp/__tests__/dashboards/) seeds a few log rows and a small TimeSeries table, then calls each tool and looks for a statistics key anywhere in the response:
clickstack_table ok statistics: {"elapsed":0.040143028,"rows_read":50,"bytes_read":483}
clickstack_timeseries ok statistics: {"elapsed":0.007009402,"rows_read":50,"bytes_read":400}
clickstack_sql ok statistics: {"elapsed":0.001872216,"rows_read":1,"bytes_read":16}
clickstack_query_tile (builder tile) ok statistics: {"elapsed":0.00614494,"rows_read":50,"bytes_read":400}
clickstack_query_tile (promql tile) ok statistics: none
clickstack_promql ok statistics: none
clickstack_query_tiles ok statistics: none
clickstack_event_patterns ok statistics: none
clickstack_emerging_signals ok statistics: none
clickstack_describe_source (log source) ok statistics: none
clickstack_describe_source (promql source) ok statistics: none
Impact
These are the tools whose cost varies most. In 15 minutes of agent investigations on the production-size server, system.query_log showed:
| Tool | Queries | Read in total | Slowest | Largest read |
|---|---|---|---|---|
clickstack_query_tiles |
271 | 217 GiB | 25.8 s | 10.2 GiB |
clickstack_promql |
60 | 73 GiB | 25.8 s | 20 GiB (the read cap) |
clickstack_describe_source |
60 | 62 GiB | 5.9 s | 5.0 GiB |
clickstack_query_tile |
10 | 16.5 GiB | 8.0 s | 5.8 GiB |
clickstack_event_patterns |
14 | 4.7 GiB | 2.0 s | 1.1 GiB |
clickstack_emerging_signals |
20 | 4.5 GiB | 2.9 s | 1.0 GiB |
The agents saw none of this. A PromQL tile that read 10 GiB looked the same as one that read 4 MB, so they couldn't learn which queries or tiles to avoid, or compare a PromQL query with the builder equivalent. The same numbers per tile would also show which dashboard tiles are the expensive ones.
Proposed fix
- Return
statisticsfrom every query tool, in the same shape asclickstack_table: summed over the ClickHouse queries the call ran, plus aqueriescount. - In
clickstack_query_tiles, addelapsedMs,rowsReadandbytesReadto each tile summary. - For PromQL through ClickHouse's
prometheus_api_v1handler, the response doesn't carry the numbers: on 26.10.3 itsX-ClickHouse-Summaryheader reportsread_rows: 0. HyperDX already setsX-ClickHouse-Query-Id(hdx-mcp-…), so the numbers could come fromsystem.query_logfor that id, or ClickHouse could report the inner query's progress in the summary header. Until then, returnelapsed(wall time) on its own.
Related
- #3540: MCP query attribution in
log_comment
reproToolStatistics.int.test.ts
// Repro: which MCP query tools return ClickHouse cost statistics (elapsed, rows_read, bytes_read).
// Copy to packages/api/src/mcp/__tests__/dashboards/ and run:
// make dev-int FILE=reproToolStatistics
import { DisplayType, SourceKind } from '@hyperdx/common-utils/dist/types';
import {
bulkInsertLogs,
DEFAULT_DATABASE,
DEFAULT_LOGS_TABLE,
dropTimeSeriesTable,
seedTimeSeriesTagsTable,
} from '@/fixtures';
import { callTool, getFirstText } from '@/mcp/__tests__/mcpTestUtils';
import Dashboard from '@/models/dashboard';
import { Source } from '@/models/source';
import { setupDashboardTests } from './setup';
const mockFetch = jest.mocked(global.fetch);
const realFetch: typeof fetch = globalThis.realFetch;
const TABLE = 'repro_tool_statistics';
/** Every value under a key named `statistics`, anywhere in the response. */
const findStatistics = (node: unknown): unknown[] =>
node == null || typeof node !== 'object'
? []
: Object.entries(node).flatMap(([k, v]) =>
k === 'statistics' ? [v] : findStatistics(v),
);
describe('repro: cost statistics per MCP tool', () => {
const ctx = setupDashboardTests();
const now = Date.now();
const start = new Date(now - 30 * 60_000).toISOString();
const end = new Date(now + 60_000).toISOString();
beforeAll(async () => {
const nowSec = Math.floor(now / 1000);
await seedTimeSeriesTagsTable({
table: TABLE,
series: ['a', 'b'].map(pod => ({
metricName: 'repro_up',
tags: { job: 'api', pod },
startSec: nowSec - 1200,
endSec: nowSec - 60,
})),
withSamples: true,
});
});
afterAll(() => dropTimeSeriesTable({ table: TABLE }));
it('prints which tools return statistics', async () => {
await ctx.reconnect({ promqlEnabled: true });
mockFetch.mockImplementation(realFetch);
await bulkInsertLogs(
Array.from({ length: 50 }, (_, i) => ({
Body: `request ${i % 5} failed after ${i} ms`,
ServiceName: 'api',
SeverityText: i % 2 ? 'ERROR' : 'INFO',
Timestamp: new Date(now - (i % 20) * 60_000),
})),
);
const logSource = await Source.create({
kind: SourceKind.Log,
team: ctx.team._id,
from: { databaseName: DEFAULT_DATABASE, tableName: DEFAULT_LOGS_TABLE },
timestampValueExpression: 'Timestamp',
connection: ctx.connection._id,
name: 'Logs',
bodyExpression: 'Body',
severityTextExpression: 'SeverityText',
});
const promSource = await Source.create({
kind: SourceKind.Promql,
team: ctx.team._id,
connection: ctx.connection._id,
name: 'Metrics',
from: { databaseName: DEFAULT_DATABASE, tableName: TABLE },
timestampValueExpression: 'timestamp',
});
const tile = (id: string, config: Record<string, unknown>) => ({ id, x: 0, y: 0, w: 6, h: 3, config });
const dashboard = await new Dashboard({
name: 'Repro',
tiles: [
tile('promql', {
configType: 'promql',
name: 'Up by pod',
displayType: DisplayType.Line,
source: promSource._id.toString(),
granularity: '1 minute',
promqlExpression: [{ expression: 'sum by (pod) (repro_up)' }],
}),
tile('builder', {
name: 'Log lines',
displayType: DisplayType.Line,
source: logSource._id.toString(),
select: [{ aggFn: 'count', valueExpression: '' }],
where: '',
granularity: '1 minute',
}),
],
filters: [],
team: ctx.team._id,
}).save();
const logId = logSource._id.toString();
const promId = promSource._id.toString();
const dashboardId = dashboard._id.toString();
const calls: [string, Record<string, unknown>][] = [
['clickstack_table', { sourceId: logId, select: [{ aggFn: 'count' }], groupBy: 'SeverityText', startTime: start, endTime: end }],
['clickstack_timeseries', { sourceId: logId, select: [{ aggFn: 'count' }], startTime: start, endTime: end }],
['clickstack_sql', { connectionId: ctx.connection._id.toString(), sql: `SELECT count() FROM ${DEFAULT_DATABASE}.${DEFAULT_LOGS_TABLE}`, startTime: start, endTime: end }],
['clickstack_query_tile', { dashboardId, tileId: 'builder', startTime: start, endTime: end }],
['clickstack_query_tile', { dashboardId, tileId: 'promql', startTime: start, endTime: end }],
['clickstack_promql', { sourceId: promId, expression: 'sum by (pod) (repro_up)', startTime: start, endTime: end }],
['clickstack_query_tiles', { dashboardId, startTime: start, endTime: end }],
['clickstack_event_patterns', { sourceId: logId, startTime: start, endTime: end }],
['clickstack_emerging_signals', {
sourceId: logId,
baselineStartTime: new Date(now - 30 * 60_000).toISOString(),
baselineEndTime: new Date(now - 10 * 60_000).toISOString(),
currentStartTime: new Date(now - 10 * 60_000).toISOString(),
currentEndTime: end,
}],
['clickstack_describe_source', { sourceId: logId }],
['clickstack_describe_source', { sourceId: promId }],
];
const lines: string[] = [];
const has: Record<string, boolean> = {};
for (const [tool, args] of calls) {
const result = await callTool(ctx.client!, tool, args);
const text = getFirstText(result);
let stats: unknown[] = [];
try {
stats = findStatistics(JSON.parse(text));
} catch {
// not JSON
}
const label = `${tool}${args.tileId ? ` (${args.tileId} tile)` : ''}${tool === 'clickstack_describe_source' ? (args.sourceId === promId ? ' (promql source)' : ' (log source)') : ''}`;
has[label] = stats.length > 0;
lines.push(
`${label.padEnd(48)} ${result.isError ? 'ERROR ' : 'ok '} statistics: ${stats.length ? JSON.stringify(stats[0]) : 'none'}`,
);
}
console.log(`REPRO\n${lines.join('\n')}`);
expect(has['clickstack_table']).toBe(true);
expect(has['clickstack_query_tile (builder tile)']).toBe(true);
for (const label of [
'clickstack_promql',
'clickstack_query_tile (promql tile)',
'clickstack_query_tiles',
'clickstack_event_patterns',
'clickstack_emerging_signals',
'clickstack_describe_source (log source)',
'clickstack_describe_source (promql source)',
]) {
expect([label, has[label]]).toEqual([label, false]);
}
});
});
- 主要语言
- TypeScript
- 星标
- 10.1k
- 派生
- 527
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 186
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ClickHouse/ClickStack 的其他 Issue
-
external
难度 2/5 1-3 小时 新手友好度 72/100
ClickHouse/ClickStack#3761 ·
维护者通常 1 天内回复
-
Metric chart with aggFn increase and a multi-column group-by fails: toString() gets several arguments可能已有人在做 @CG-5228 于 26 天前认领。 未关闭external
难度 2/5 1-3 小时 新手友好度 76/100
ClickHouse/ClickStack#3477 · 1 条评论 ·
维护者通常 1 天内回复
-
Slack notifications for inline alerts fail when the chart-explorer link passes Slack's 3000-character block limit可能已有人在做 @Tyagiquamar 于 27 天前认领。 未关闭alerting bug external
难度 2/5 1-3 小时 新手友好度 76/100
ClickHouse/ClickStack#3452 ·
维护者通常 1 天内回复
-
check-alerts worker: 13 error spans (mongodb.create, NamespaceExists) every minute because mongoose autoCreate is still on可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug external Needs Feedback
难度 2/5 1-3 小时 新手友好度 72/100
ClickHouse/ClickStack#3308 · 1 条评论 ·
维护者通常 1 天内回复
-
count_distinct aggFn on metric tiles ignores valueExpression, always counts distinct metric Values可能已有人在做 @Harshul1484 于 54 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
ClickHouse/ClickStack#2311 ·
维护者通常 1 天内回复
查看 ClickHouse/ClickStack 的全部 Issue
相似的 Issue
-
Add: GTrekker未关闭check:passed streams:add
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
area: ui Bug Payload OSS
难度 1/5 1 小时以内 新手友好度 88/100
payloadcms/payload#19839 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
fix(auth): add the email OTP verification step to Pollar login可能已有人在做 @akansnoro 今天认领。 未关闭Stellar Wave
难度 2/5 1-3 小时 新手友好度 74/100
safetrustcr/dApp-SafeTrust#584 · 10 条评论 ·
维护者通常 1 天内回复
-
The manager preset saves launch definitions without the required file and digest pair可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复