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
16 changes: 16 additions & 0 deletions packages/api/src/mcp/tools/dashboards/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,22 @@ const mcpTableTileSchema = mcpTileLayoutSchema.extend({
'When ordering by an alias that contains spaces or special characters, ' +
`wrap the alias in quotes: e.g. '"P95 Latency" DESC'.`,
),
limitAfter: z
.string()
.max(10000)
.optional()
.describe(
'ClickHouse LIMIT AFTER start expression. Mutually exclusive with OFFSET. ' +
'Example: "service_id >= 3". Requires ORDER BY.',
),
limitUntil: z
.string()
.max(10000)
.optional()
.describe(
'ClickHouse LIMIT UNTIL end expression. Used with LIMIT AFTER. ' +
'Example: "service_id >= 8".',
),
asRatio: z.boolean().optional().describe(asRatioDescription),
groupByColumnsOnLeft: z
.boolean()
Expand Down
10 changes: 10 additions & 0 deletions packages/api/src/mcp/tools/savedSearches/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ export const mcpSaveSavedSearchSchema = z.object({
.string()
.optional()
.describe('Sort expression. Example: "Timestamp DESC"'),
limitAfter: z
.string()
.optional()
.describe(
'ClickHouse LIMIT AFTER start expression. Mutually exclusive with OFFSET pagination.',
),
limitUntil: z
.string()
.optional()
.describe('ClickHouse LIMIT UNTIL end expression. Used with LIMIT AFTER.'),
sourceId: objectIdSchema.describe(
'Source ID — call clickstack_list_sources to find available sources.',
),
Expand Down
6 changes: 6 additions & 0 deletions packages/api/src/models/savedSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type ExternalSavedSearch = {
where?: string;
whereLanguage?: string;
orderBy?: string;
limitAfter?: string;
limitUntil?: string;
sourceId?: string;
tags?: string[];
filters?: unknown[];
Expand Down Expand Up @@ -52,6 +54,8 @@ const savedSearchSchema = new Schema<
where: String,
whereLanguage: String,
orderBy: String,
limitAfter: String,
limitUntil: String,
source: {
type: mongoose.Schema.Types.ObjectId,
required: true,
Expand Down Expand Up @@ -88,6 +92,8 @@ savedSearchSchema.methods.toExternalJSON = function (): ExternalSavedSearch {
where: this.where,
whereLanguage: this.whereLanguage,
orderBy: this.orderBy,
limitAfter: this.limitAfter,
limitUntil: this.limitUntil,
sourceId: this.source ? String(this.source) : undefined,
tags: this.tags,
filters: this.filters,
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/routers/external-api/v2/savedSearches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ const savedSearchRequestSchema = z.object({
.default(''),
whereLanguage: z.enum(['lucene', 'sql']).optional().default('lucene'),
orderBy: z.string().max(1024).optional().default(''),
limitAfter: z.string().max(4096).optional().default(''),
limitUntil: z.string().max(4096).optional().default(''),
tags: tagsSchema.default([]),
filters: z
.array(savedSearchFilterSchema)
Expand Down
23 changes: 23 additions & 0 deletions packages/api/src/routers/external-api/v2/utils/dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ export const convertToExternalTileChartConfig = (
? config.select.map(convertToExternalSelectItem)
: [DEFAULT_SELECT_ITEM],
orderBy: stringValueOrDefault(config.orderBy, undefined),
limitAfter: config.limit?.after || undefined,
limitUntil: config.limit?.until || undefined,
...externalFormulaFields,
...externalShowOperandSeriesField,
};
Expand All @@ -597,6 +599,8 @@ export const convertToExternalTileChartConfig = (
select: stringValueOrDefault(config.select, ''),
where: config.where,
whereLanguage: config.whereLanguage ?? 'lucene',
limitAfter: config.limit?.after || undefined,
limitUntil: config.limit?.until || undefined,
};
case DisplayType.Markdown:
return {
Expand Down Expand Up @@ -917,6 +921,23 @@ const convertExternalPromqlConfigToInternal = (
}
};

function limitAfterUntilFields(externalConfig: {
limitAfter?: string;
limitUntil?: string;
}): { limit?: { after?: string; until?: string } } {
const after = externalConfig.limitAfter?.trim();
const until = externalConfig.limitUntil?.trim();
if (!after && !until) {
return {};
}
return {
limit: {
...(after ? { after } : {}),
...(until ? { until } : {}),
},
};
}

export function convertToInternalTileConfig(
externalTile: ConfigTile,
): DashboardDocument['tiles'][number] {
Expand Down Expand Up @@ -1049,6 +1070,7 @@ export function convertToInternalTileConfig(
source: externalConfig.sourceId,
where: '',
seriesReturnType: externalConfig.asRatio ? 'ratio' : undefined,
...limitAfterUntilFields(externalConfig),
name,
description,
} satisfies BuilderSavedChartConfig;
Expand Down Expand Up @@ -1190,6 +1212,7 @@ export function convertToInternalTileConfig(
name,
description,
whereLanguage: externalConfig.whereLanguage ?? 'lucene',
...limitAfterUntilFields(externalConfig),
} satisfies BuilderSavedChartConfig;
break;
case 'event_patterns':
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/utils/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ const externalDashboardTableChartConfigSchema = z.object({
groupBy: z.string().max(10000).optional(),
having: z.string().max(10000).optional(),
orderBy: z.string().max(10000).optional(),
limitAfter: z.string().max(10000).optional(),
limitUntil: z.string().max(10000).optional(),
asRatio: z.boolean().optional(),
numberFormat: NumberFormatSchema.optional(),
groupByColumnsOnLeft: z.boolean().optional(),
Expand Down Expand Up @@ -571,6 +573,8 @@ const externalDashboardSearchChartConfigSchema = z.object({
select: z.string().max(10000),
where: z.string().max(10000).optional().default(''),
whereLanguage: whereLanguageSchema,
limitAfter: z.string().max(10000).optional(),
limitUntil: z.string().max(10000).optional(),
});

// Extended schema for the /api/v2/search endpoint — adds orderBy which is not
Expand Down
Loading
Loading