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
7 changes: 7 additions & 0 deletions .changeset/external-api-promql-tiles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperdx/api': minor
---

feat: Support PromQL dashboard tiles in the external API

`/api/v2/dashboards` now returns PromQL tiles and accepts them on create and update, as `configType: "promql"` with a `sourceId` and a list of `expressions`. Previously PromQL tiles were left out of responses, so saving a dashboard back through the API deleted them. MCP dashboard tools still hide PromQL tiles until they support editing them.
4 changes: 3 additions & 1 deletion packages/api/src/mcp/tools/dashboards/getDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export function registerGetDashboard({
if (!dashboard) {
return mcpUserError('Dashboard not found');
}
const externalDashboard = convertToExternalDashboard(dashboard);
const externalDashboard = convertToExternalDashboard(dashboard, {
hidePromqlTiles: true,
});
return {
content: [
{
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/mcp/tools/dashboards/getDashboardTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export function registerGetDashboardTile({
return mcpUserError('Dashboard not found');
}

const externalDashboard = convertToExternalDashboard(dashboard);
const externalDashboard = convertToExternalDashboard(dashboard, {
hidePromqlTiles: true,
});
const tile = externalDashboard.tiles.find(t => t.id === tileId);
if (!tile) {
return mcpUserError(
Expand Down
8 changes: 6 additions & 2 deletions packages/api/src/mcp/tools/dashboards/patchDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ export function registerPatchDashboard({
if (existingIdx === -1) {
// Build a human-readable list of available tile IDs.
// Convert only for the error message (read-only, no write-back).
const externalDashboard =
convertToExternalDashboard(existingDashboard);
const externalDashboard = convertToExternalDashboard(
existingDashboard,
{
hidePromqlTiles: true,
},
);
return mcpUserError(
`Tile not found: ${tileId}. Available tile IDs: ${externalDashboard.tiles.map(t => `${t.id} (${t.name})`).join(', ')}`,
);
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/mcp/tools/dashboards/queryTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export function registerQueryTile({
return mcpUserError('Dashboard not found');
}

const externalDashboard = convertToExternalDashboard(dashboard);
const externalDashboard = convertToExternalDashboard(dashboard, {
hidePromqlTiles: true,
});
const tile = externalDashboard.tiles.find(t => t.id === tileId);
if (!tile) {
return mcpUserError(
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/mcp/tools/dashboards/queryTiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ export function registerQueryTiles({
return mcpUserError('Dashboard not found');
}

const externalDashboard = convertToExternalDashboard(dashboard);
const externalDashboard = convertToExternalDashboard(dashboard, {
hidePromqlTiles: true,
});
const allTiles = externalDashboard.tiles;

const resolved = resolveDashboardVariables(
Expand Down
8 changes: 6 additions & 2 deletions packages/api/src/mcp/tools/dashboards/saveDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ async function createDashboard({

recordDashboardOnboardingIfHasTiles(userId, newDashboard.tiles);

const externalDashboard = convertToExternalDashboard(newDashboard);
const externalDashboard = convertToExternalDashboard(newDashboard, {
hidePromqlTiles: true,
});
return {
content: [
{
Expand Down Expand Up @@ -373,7 +375,9 @@ async function updateDashboard({

recordDashboardOnboardingIfHasTiles(userId, updatedDashboard.tiles);

const externalDashboard = convertToExternalDashboard(updatedDashboard);
const externalDashboard = convertToExternalDashboard(updatedDashboard, {
hidePromqlTiles: true,
});
return {
content: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5602,6 +5602,71 @@ describe('External API v2 Dashboards - new format', () => {
expect(await Alert.findById(alert._id)).toBeNull();
});

it('should delete alert when tile is updated from builder to PromQL config', async () => {
const tileId = new ObjectId().toString();
const dashboard = await createTestDashboard({
tiles: [
{
id: tileId,
x: 0,
y: 0,
w: 6,
h: 3,
config: {
name: 'Builder Tile',
displayType: 'line',
source: traceSource._id.toString(),
select: [
{ aggFn: 'count', aggCondition: '', valueExpression: '' },
],
where: '',
},
},
],
});
const webhook = await Webhook.create({
name: 'Test Webhook',
service: WebhookService.Slack,
url: 'https://hooks.slack.com/test',
team: team._id,
});
const alert = await Alert.create({
team: team._id,
dashboard: dashboard._id,
tileId,
source: AlertSource.TILE,
threshold: 100,
interval: '1h',
thresholdType: AlertThresholdType.ABOVE,
channel: { type: 'webhook', webhookId: webhook._id.toString() },
});

await authRequest('put', `${BASE_URL}/${dashboard._id}`)
.send({
name: 'Updated Dashboard',
tags: [],
tiles: [
{
id: tileId,
name: 'PromQL Tile',
x: 0,
y: 0,
w: 6,
h: 3,
config: {
configType: 'promql',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 minor — No integration test covers the REST create, read and save-back path for PromQL tiles or their validation

The only new integration test with a PromQL tile checks alert cleanup. Nothing exercises the main path in the PR description: a PromQL tile surviving GET → PUT, POST with a PromQL heatmap no longer being rejected by the heatmap gate, or a missing or wrong PromQL sourceId being rejected. The unit tests call the converters directly and skip validateDashboardTiles. Fix: add integration tests for a PromQL heatmap POST (expect 200), a GET → PUT round-trip that keeps the tile, and a POST whose sourceId points to a non-PromQL source (expect 400 once the source-kind check is added).

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

displayType: 'line',
sourceId: promqlSource._id.toString(),
expressions: [{ expression: 'up' }],
},
},
],
})
.expect(200);

expect(await Alert.findById(alert._id)).toBeNull();
});

it('should delete alert when a tile with an alert is removed from the dashboard', async () => {
const keepTileId = new ObjectId().toString();
const removeTileId = new ObjectId().toString();
Expand Down Expand Up @@ -7255,10 +7320,12 @@ describe('External API v2 Dashboards - new format', () => {
// check it would persist as a builder tile AND skip the builder-only
// rules — here a formula referencing a nonexistent series.
const res = await postTile({
configType: 'promql',
configType: 'foo',
formulas: [{ expression: 'C * 2' }],
}).expect(400);
expect(res.body.message).toContain('configType must be "sql" or omitted');
expect(res.body.message).toContain(
'configType must be "sql", "promql" or omitted',
);
});

it('round-trips formulas on a log/trace event source', async () => {
Expand Down
Loading
Loading