/** * PromQL → Datadog query language translator. * * Targets the closed set of query shapes the MCP's tools actually * issue, not arbitrary PromQL. The shapes are enumerated in * `src/lib/promql.ts`: * * - `topk(N, sum by (a,b,c) (increase(M{filters}[range])))` * - `sum by (a,b,c) (increase(M{filters}[range]))` * - `sum by (label) (rate(M{filters}[range]))` * - `sum(increase(M{filters}[range]))` * - `sort_desc(sum by (a) (increase(M{filters}[range])))` * - `count(increase(M{filters}[range]) > 0)` * - `count(count by (svc) (increase(M[range]) > 0))` * - `group by (a,b,c) (M{filters})` * * Mapping to Datadog's query syntax: * * `sum:M{filters} by {labels}` ← `sum by (labels) (M{filters})` * `sum:M{filters}.as_count() by {labels}` ← `sum by (labels) (increase(M{filters}[range]))` * `sum:M{filters}.as_rate() by {labels}` ← `sum by (labels) (rate(M{filters}[range]))` * `top(, N, 'sum', 'desc')` ← `topk(N, )` * `count_not_null()` ← `count()` (when wrapping a counted set) * * Datadog's range vector handling is implicit: pass the query without * `[range]` and DD applies its own rollup window based on the request's * `from`/`to`. The PromQL `[15m]` is informational; DD's response * granularity is governed by the query window, not the inline range. * * Vendored PromQL parser: `vendor/promql-parser` (MIT, generated from * a PEG.js grammar). Imported via createRequire because the parser is * CommonJS and the rest of the MCP is ESM. */ export declare class PromQLTranslationError extends Error { readonly promql: string; constructor(message: string, promql: string); } /** * Translate a PromQL query string to a Datadog query string the * `/api/v1/query` endpoint accepts. Throws `PromQLTranslationError` * when the input shape is outside the supported subset. * * Pre-processes specific shapes that the vendored PEG.js grammar * doesn't parse cleanly: * - `topk(N, INNER)` — grammar fails on multi-arg function calls; * we extract N and INNER, translate INNER recursively, wrap with * Datadog's top(...). * - `bottomk(N, INNER)` — symmetric. * - `sort_desc(INNER)` / `sort(INNER)` — strip the cosmetic wrapper * and translate INNER; Datadog auto-orders. * - `count(INNER > 0)` — collapse the boolean filter; translate * INNER, wrap in count_not_null. */ export declare function promqlToDatadog(promql: string): string;