Skip to content

[FEATURE] Prometheus: per-query exemplars toggle (perses#3445) - #877

Merged
AntoineThebaud merged 9 commits into
perses:mainfrom
julianocosta89:exemplars/3445-query-toggle
Nov 9, 2026
Merged

AntoineThebaud merged 9 commits into
perses:mainfrom
julianocosta89:exemplars/3445-query-toggle

Conversation

@julianocosta89

Copy link
Copy Markdown
Contributor

Description

Adds the missing piece of the exemplars MVP from perses/perses#3445: an optional enableExemplars toggle on the PrometheusTimeSeriesQuery spec, rendered as an Auto / On / Off button group in the query editor (same pattern as the existing instant toggle).

Semantics:

  • Auto (field unset): follow the exemplars.enable setting of the selected datasource — the behavior introduced with the MVP.
  • On: fetch exemplars for this query, even when the rest of the panel would not show them otherwise (still gated by the datasource toggle).
  • Off: skip the exemplars request for this query, even when the datasource has exemplars enabled.

A per-query On cannot override a datasource-level off: the effective flag is datasource.exemplars.enable === true && (spec.enableExemplars ?? true) && !isInstant — exemplars stay a datasource opt-in feature, and they are only fetched for range queries (the exemplars API is range-based).

Editor UX:

  • The button group sits next to the Range/Instant/Auto query-type group.
  • It is disabled when exemplars are disabled on the selected datasource (helper text: "Exemplars (disabled on the datasource)") or when the query is instant ("not available for instant queries"), with the state-aware message color so a misconfiguration is visible at a glance.

Also included:

  • enableExemplars?: bool in the plugin CUE schema.
  • EnableExemplars(bool) option on the Go SDK query builder (mirroring Instant).

Screenshots

Query editor with the Exemplars Auto/On/Off toggle:

query editor with the exemplars toggle

Full panel editor context:

panel editor with the query editor

Testing

  • Unit tests for getTimeSeriesData: enableExemplars: false suppresses the exemplar request even when the datasource enables them; enableExemplars: true does not bypass a datasource-level off; instant queries never fetch exemplars (pre-existing behavior, kept intact).
  • tsc --noEmit, oxlint and oxfmt are clean.

@julianocosta89
julianocosta89 requested review from Gladorme and removed request for a team October 16, 2026 13:40

@AntoineThebaud AntoineThebaud left a comment

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.

Thanks @julianocosta89 for following-up on this 🙏 could you just shrink the legend control to make room for these new controls, to avoid using more vertical space for this query form, something like this mockup:

Image

@Gladorme

Copy link
Copy Markdown
Member

Strange to have the same style of inputs. But not the same display (exemplar having a label but not query type) 😕

@AntoineThebaud

Copy link
Copy Markdown
Contributor

Strange to have the same style of inputs. But not the same display (exemplar having a label but not query type) 😕

Well query type controls are quite self explanatory I think, at a glance you understand what "range" and "instant" are related to, so the label isn't mandatory for user comprehension, and adding a "Query type" label in front would consume too much space in the current state imho. But if we want to have similar look & feel across the 2 controls maybe we could go with dropdown+label for each? Like we have for the Query Type dropdown that comes first in the form (oh y btw "Query type" is already taken then 😅 )

@julianocosta89
julianocosta89 force-pushed the exemplars/3445-query-toggle branch from 2db3ea5 to 549ab43 Compare October 27, 2026 10:08
@julianocosta89

Copy link
Copy Markdown
Contributor Author

@AntoineThebaud here are the new screenshots:

image image image

Add an optional enableExemplars field to the PrometheusTimeSeriesQuery
spec, rendered as an Auto/On/Off button group in the query editor (same
pattern as the instant toggle):

- Auto (unset): follow the exemplars.enable setting of the datasource
- On/Off: override the datasource setting for this query
- the control is disabled when exemplars are disabled on the selected
  datasource or when the query is instant (the exemplars API is
  range-based)
- a per-query On cannot override a datasource-level Off

Also adds the field to the CUE schema and a EnableExemplars() option to
the Go SDK query builder.

Signed-off-by: Juliano Costa <julianocosta89@outlook.com>
@julianocosta89
julianocosta89 force-pushed the exemplars/3445-query-toggle branch from 549ab43 to a204a7b Compare October 27, 2026 11:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The exemplars controls remain enabled with misleading helper text for Auto queries on instant-mode panels, and the On/Off/Auto group lacks an accessible name and exposed selected state.

2 open issues
What changed in this PR

Adds per-query exemplar control to Prometheus time-series queries while preserving datasource opt-in and range-query restrictions.

Changes:

  • Adds an Auto/On/Off editor control with datasource and instant-query availability messaging.
  • Applies the per-query flag when fetching exemplars and tests opt-out and datasource gating.
  • Exposes the optional setting in the TypeScript model, CUE schema, and Go SDK.
File Description
prometheus/​src/​plugins/​prometheus-time-series-query/​time-series-query-model.ts Defines the optional enableExemplars field.
prometheus/​src/​plugins/​prometheus-time-series-query/​query-editor-model.ts Adds immediate-update state handling for the toggle.
prometheus/​src/​plugins/​prometheus-time-series-query/​PrometheusTimeSeriesQueryEditor.tsx Adds exemplar controls and availability messages.
prometheus/​src/​plugins/​prometheus-time-series-query/​plugin.test.ts Tests per-query opt-out and datasource gating.
prometheus/​src/​plugins/​prometheus-time-series-query/​get-time-series-data.ts Includes the query setting in exemplar request gating.
prometheus/​sdk/​go/​query/​query.go Adds the optional serialized Go field.
prometheus/​sdk/​go/​query/​options.go Adds the EnableExemplars builder option.
prometheus/​schemas/​prometheus-time-series-query/​query.cue Allows the optional boolean in query configuration.

Review effort: Balanced

…3445)

- Name the On/Off/Auto group via aria-labelledby and expose each
  button's state with aria-pressed.
- In Auto query mode, note that exemplars are skipped when the panel
  runs instant queries. The editor cannot see the panel's query mode,
  so it cannot disable the control in that case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvsQXh9qWa3NMgi9mUQTY3
Signed-off-by: Juliano Costa <julianocosta89@outlook.com>
Exemplars being disabled on the datasource is a configuration state,
not an error, so the label no longer switches to the error colour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvsQXh9qWa3NMgi9mUQTY3
Signed-off-by: Juliano Costa <julianocosta89@outlook.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The exemplar documentation still incorrectly promises a datasource override and fetching for every range query, and must clarify per-query Auto/On/Off behavior and datasource and range-query requirements.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Low severity Correct EnableExemplars datasource override documentation

prometheus/​sdk/​go/​query/​options.go:71

EnableExemplars(true) cannot enable fetching when the datasource disables exemplars, so this documentation incorrectly promises an override. Document that datasource opt-in remains required, omission follows the datasource setting, and false skips fetching. The same correction is needed in prometheus/src/plugins/prometheus-time-series-query/time-series-query-model.ts:28–30.

Low severity Update exemplar docs for the per-query Auto/On/Off option

prometheus/​src/​plugins/​prometheus-time-series-query/​get-time-series-data.ts:129

This changes the documented behavior: docs/prometheus/README.md:137 still says an enabled datasource fetches exemplars with every range query, which is no longer true when enableExemplars is false. Please update the exemplar guide and query model documentation to describe the per-query Auto/On/Off option and clarify that On still requires an enabled datasource and a range query.

2 resolved since last review

Review effort: Balanced

enableExemplars can only narrow the datasource setting: true still
requires exemplars enabled on the datasource and a range query.
Document the Auto/On/Off modes in the README and fix the Go and TS
comments that described it as an override.

Signed-off-by: Juliano Costa <julianocosta89@outlook.com>
@julianocosta89

Copy link
Copy Markdown
Contributor Author

@Gladorme and @AntoineThebaud anything missing here?

The latest screenshots are here: #877 (comment)

@AntoineThebaud

AntoineThebaud commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

@Gladorme and @AntoineThebaud anything missing here?

The latest screenshots are here: #877 (comment)

Sorry for the delay on this topic @julianocosta89, I will have time tomorrow to review this one & #876 as well

@julianocosta89

Copy link
Copy Markdown
Contributor Author

@AntoineThebaud Any chance you are attending KubeCon?!

@AntoineThebaud

Copy link
Copy Markdown
Contributor

@julianocosta89 not the current NA edition but I should be there at the next EU one in 2027

@AntoineThebaud AntoineThebaud left a comment

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.

LGTM

@AntoineThebaud
AntoineThebaud added this pull request to the merge queue Nov 9, 2026
Merged via the queue into perses:main with commit 524dbac Nov 9, 2026
18 checks passed
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.

4 participants