Skip to content

feat(promql): a Prometheus-compatible query API - #2666

Open
Makisuo wants to merge 46 commits into
promql/4-mcpfrom
promql/5-prometheus-api
Open

Makisuo wants to merge 46 commits into
promql/4-mcpfrom
promql/5-prometheus-api

Merge branch 'promql/4-mcp' into promql/5-prometheus-api

f4cc0ea
Select commit
Loading
Failed to load commit list.
Maple Review Bot / Maple / review completed Nov 16, 2026 in 2m 33s

Confidence 6/10 · 1 issue to address

🟡 Confidence 6/10 · needs attention. Open findings from earlier passes survive at this head, chiefly that a warehouse failure answers 503 while the span stays Ok; wire formatting and org scoping are well pinned.
1 warning −1 · 9 notes · tests partial −1 · risk high −1 · 3/4 new units observable −1

Adds a Prometheus-compatible query and discovery API under /v2/metrics/prometheus/api/v1, with Go-format values, Prometheus error envelopes, metrics:read scoping and org-scoped discovery reads. Mergeable once the open unavailable path's span status is settled; the McpOAuthProtocolError from http-graph.ts is untouched by this diff, which only adds a route layer there.

  • prometheus.http.ts serves query, query_range, series, labels, label values, metadata, buildinfo and exemplars
  • PromqlQueryService gains series, labelNames, labelValues and metadata over catalog and rollups
  • promqlIdentityValuesQuery/promqlMetadataQuery/promqlAttributeValuesQuery add org-scoped discovery reads
  • query and match[] are redacted from the traced request URL

Still open from earlier reviews

Production impact

Open errors in the changed files (1)
Issue Service Occurrences File
@maple/backend/errors/McpOAuthProtocolError maple-api 4 apps/api/src/runtime/http-graph.ts

After this merges, Maple checks whether they stop.

Telemetry this change adds and removes (13)
  • ➕ span name PrometheusApi.query · apps/api/src/routes/v2/prometheus.http.ts:118
  • ➕ span name PrometheusApi.queryRange · apps/api/src/routes/v2/prometheus.http.ts:138
  • ➕ span name PrometheusApi.series · apps/api/src/routes/v2/prometheus.http.ts:167
  • ➕ span name PrometheusApi.labels · apps/api/src/routes/v2/prometheus.http.ts:173
  • ➕ span name PrometheusApi.labelValues · apps/api/src/routes/v2/prometheus.http.ts:180
  • ➕ span name PrometheusApi.metadata · apps/api/src/routes/v2/prometheus.http.ts:187
  • ➕ span name PromqlQueryService.series · packages/backend/src/services/promql/PromqlQueryService.ts:355
  • ➕ span name PromqlQueryService.attributeKeys · packages/backend/src/services/promql/PromqlQueryService.ts:391
  • ➕ span name PromqlQueryService.labelNames · packages/backend/src/services/promql/PromqlQueryService.ts:420
  • ➕ span name PromqlQueryService.attributeValues · packages/backend/src/services/promql/PromqlQueryService.ts:436
  • ➕ span name PromqlQueryService.identityValues · packages/backend/src/services/promql/PromqlQueryService.ts:467
  • ➕ span name PromqlQueryService.labelValues · packages/backend/src/services/promql/PromqlQueryService.ts:489
  • ➕ span name PromqlQueryService.metadata · packages/backend/src/services/promql/PromqlQueryService.ts:525
What was checked
  • Every new query filters OrgId via orgIdParam (promql.ts:367, 752, 775, 798), and the service test refuses non-single-tenant reads
  • parseTime/parseStep reject out-of-range epochs and rolled-over calendar fields before formatWarehouseDateTime (prometheus-wire.ts:48)
  • Discovery label-marking and identity values reuse labelValueExpr, so /series and /label/job/values cannot disagree
Observability coverage: 3 of 4 changes observable
Change Kind Observable Evidence
Prometheus query routes (/query, /query_range, GET and form POST) HTTP server route yes Effect.fn("PrometheusApi.query")/queryRange (prometheus.http.ts:118, 138); server span from the existing API tracing, with query/match[] redacted (api-observability.ts:66-71)
Prometheus discovery routes (/series, /labels, /label/:name/values, /metadata, /status/buildinfo, /query_exemplars) HTTP server route yes Effect.fn spans at prometheus.http.ts:167-193 with maple.promql.* attributes
Discovery warehouse reads (series, label names, label values, metadata) database query yes warehouse.compiledQuery contexts promqlLabelNames/promqlLabelValues/promqlJobs/promqlInstances/promqlMetadata (PromqlQueryService.ts:400-482)
Prometheus error path (warehouse failure → 503) error path no toErrorResponse logs and returns the 503 as a success value (prometheus.http.ts:66-70), so the span stays Ok — open finding F21

f4cc0ea · Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.