Skip to content

[FEATURE] Prometheus: add Exemplars support - #799

Open
julianocosta89 wants to merge 5 commits into
perses:mainfrom
julianocosta89:exemplars/3445-datasource
Open

[FEATURE] Prometheus: add Exemplars support#799
julianocosta89 wants to merge 5 commits into
perses:mainfrom
julianocosta89:exemplars/3445-datasource

Conversation

@julianocosta89

@julianocosta89 julianocosta89 commented Sep 7, 2026

Copy link
Copy Markdown

Description

Part of #3445 (perses/perses#3445). Depends on the exemplars contract in perses/spec ().

Summary

Adds exemplars support to the Prometheus datasource and PrometheusTimeSeriesQuery — the data path. Rendering in TimeSeriesChart follows in a follow-up PR stacked on this one.

PrometheusDatasource

  • New optional exemplars: { enable: boolean } section in the datasource spec — off by default, so existing datasources and dashboards are unaffected:
    • prometheus/schemas/datasource/prometheus.cue — CUE schema for the new section
    • prometheus/src/plugins/types.tsPrometheusDatasourceSpec.exemplars?
    • PrometheusDatasourceEditor.tsx — new "Exemplars" section with an "Enable exemplars" Switch (respects readonly mode; the section is removed from the spec when toggled off)
  • New queryExemplars() client method hitting GET /api/v1/query_exemplars?query=...&start=...&end=..., with API types (QueryExemplarsRequestParameters, ExemplarSeries,
    ExemplarData, QueryExemplarsResponse) modeled on the Prometheus docs.
  • The endpoint is allowed through the proxy (GET /api/v1/query_exemplars) and exposed on PrometheusClient via the usual wrapClientMethod.

PrometheusTimeSeriesQuery

  • When the selected datasource has exemplars enabled and the query is in range mode (not instant), a query_exemplars request with the same PromQL + time range is fired in
    parallel
    with the range query.
  • Unit conversion at the datasource boundary: exemplar timestamps (Prometheus seconds) → UnixTimeMs (× 1000), values (Prometheus strings) → numbers.
  • Results attached to TimeSeriesData.exemplars per the spec contract.
  • A failing exemplar request never breaks the panel: it's logged (console.warn) and the series data is returned without exemplars.

Testing

  • Prometheus plugin: 27 tests pass, including mocked query_exemplars client call, exemplar enabled/disabled behavior, exemplar-request failure fallback, and unit conversion.
  • Repo-wide: turbo run type-check / test (30 packages), lint (31), oxfmt clean, make test-schemas-plugins (24 CUE schema tests), make lint-plugins pass.

Follow-up

Stacked on this branch: feat(timeserieschart) PR rendering exemplars as clickable diamond markers (#800).

Screenshots

edit_datasource Screenshot 2026-09-09 at 13 30 08

There are more screenshots available at: #800

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.

…t method

Add an optional `exemplars: { enable: boolean }` section to the
PrometheusDatasource spec, exposed in the datasource editor as a
toggle and validated by the CUE schema.

Add a `queryExemplars` method to the Prometheus client hitting
GET /api/v1/query_exemplars with the same query parameters and
authentication handling as the other API calls. The endpoint is also
added to the default proxy allowedEndpoints list.

Related to perses/perses#3445

Signed-off-by: Juliano Costa <juliano.costa@datadoghq.com>
When the selected datasource has exemplars enabled in its spec and the
query runs in range mode, fire a query_exemplars request alongside the
range query (same PromQL and time range, in parallel) and attach the
converted exemplar data to the returned TimeSeriesData.

Exemplar timestamps are converted from seconds to ms and values are
parsed as numbers. A failing exemplar request never breaks the panel:
the error is logged and the query result is returned without exemplars.

Related to perses/perses#3445

Signed-off-by: Juliano Costa <juliano.costa@datadoghq.com>
@julianocosta89
julianocosta89 force-pushed the exemplars/3445-datasource branch from fc0b4a9 to 543b09a Compare September 8, 2026 12:07
@AntoineThebaud

Copy link
Copy Markdown
Contributor

Please add a screenshot to your PR desc 🙏

@julianocosta89

Copy link
Copy Markdown
Author

@AntoineThebaud screenshots added here and in perses/shared#278

@julianocosta89

Copy link
Copy Markdown
Author

This depends on perses/shared#278

Comment thread prometheus/src/plugins/PrometheusDatasourceEditor.tsx
julianocosta89 and others added 2 commits September 10, 2026 11:46
…ditor

Address maintainer feedback from PR perses#799: the Exemplars heading and
toggle now render before HTTPSettingsEditor as part of the General
Settings section.

Signed-off-by: Juliano Costa <juliano.costa@datadoghq.com>
@julianocosta89

Copy link
Copy Markdown
Author

@AntoineThebaud moved up 🙏🏽

image

@AntoineThebaud AntoineThebaud changed the title Exemplars/3445 datasource [FEATURE] Prometheus: add Exemplars support Sep 10, 2026
@AntoineThebaud

Copy link
Copy Markdown
Contributor

I think this new feature is worth mentionning in the functionnal documentation of the plugin, could you please add something there? https://github.com/perses/plugins/blob/main/docs%2Fprometheus%2FREADME.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants