Skip to content

Add PrometheusSeriesResponseListener for series endpoint#144492

Merged
felixbarny merged 13 commits intoelastic:mainfrom
felixbarny:prometheus-series-response-listener
Mar 25, 2026
Merged

Add PrometheusSeriesResponseListener for series endpoint#144492
felixbarny merged 13 commits intoelastic:mainfrom
felixbarny:prometheus-series-response-listener

Conversation

@felixbarny
Copy link
Copy Markdown
Member

@felixbarny felixbarny commented Mar 18, 2026

Implements an ActionListener that converts ESQL query results into a Prometheus-compatible series response, including label name/value extraction and proto serialization.

Also adds ESQL compile-time dependencies to the prometheus plugin.


Stack:

@felixbarny felixbarny self-assigned this Mar 18, 2026
@elasticsearchmachine elasticsearchmachine added Team:StorageEngine external-contributor Pull request authored by a developer outside the Elasticsearch team labels Mar 18, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@felixbarny felixbarny changed the base branch from promql-query-range-parsed-statement to main March 18, 2026 13:52
Extend the prometheus plugin with compile-time dependencies on x-pack-esql,
x-pack-esql-core, and esql:compute so that the series endpoint can build
and execute ESQL logical plans.
Implements an ActionListener that converts ESQL query results into a
Prometheus-compatible series response, including label name/value
extraction and proto serialization.
@felixbarny felixbarny force-pushed the prometheus-series-response-listener branch from 029ea1e to 0325a05 Compare March 18, 2026 13:54
These tests exercise PrometheusSeriesRestAction.parseQueryString which
doesn't exist on this branch. Move them to the rest action PR.
@felixbarny felixbarny enabled auto-merge (squash) March 23, 2026 18:12
metric_name cannot be null and empty dimensions is not legal, so the
test now verifies that the existing assertion in buildLabelMap is tripped
rather than expecting a valid empty label map.
* Prometheus HTTP API error type strings, as defined in the Prometheus source:
* https://github.com/prometheus/prometheus/blob/main/web/api/v1/api.go
*/
private static final String ERROR_TYPE_EXECUTION = "execution";
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.

nit: enum?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've consolidated the error handling with PrometheusQueryRangeResponseListener now and created a shared PrometheusErrorResponse helper.

try {
List<Map<String, String>> seriesList = extractSeries(response);
channel.sendResponse(buildSuccessResponse(seriesList));
} catch (Exception e) {
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.

Can we reuse org/elasticsearch/action/ActionListener.java:250 ?

sendError(e);
}

// -------------------------------------------------------------------------
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.

nit: I can we use this comment pattern around tests but not sure how consistent it is with the rest of the codebase. Just flagging.

Copy link
Copy Markdown
Contributor

@sidosera sidosera left a comment

Choose a reason for hiding this comment

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

Left a few minor comments; otherwise looks good.

One broader question. What’s the intended home for response format conversion rest layer or compute engine. Any particular reason we chose current approach?

- Convert error type string constants to a private enum
- Rename buildSuccessResponse -> replaySuccess (void, non-static, sends response directly)
- Rename sendError -> replayError
- Remove separator comment style
- Add imports for XContentParser and XContentParserConfiguration (replacing FQNs)
Both PrometheusQueryRangeResponseListener and PrometheusSeriesResponseListener
shared duplicate error type mapping and error JSON construction logic.
Extract to a single PrometheusErrorResponse class with:
- send(channel, e, logger): builds and sends the error response with fallback
- build(status, message): constructs the error JSON builder
- mapErrorType(status): maps HTTP status to Prometheus error type string

The series listener now uses ExceptionsHelper.status(e) for status resolution
(consistent with the range listener) instead of manual instanceof checks.
@felixbarny felixbarny merged commit 106cc04 into elastic:main Mar 25, 2026
36 checks passed
@felixbarny felixbarny deleted the prometheus-series-response-listener branch March 25, 2026 09:20
eranweiss-elastic pushed a commit to eranweiss-elastic/elasticsearch that referenced this pull request Mar 25, 2026
)

Implements an ActionListener that converts ESQL query results into a
Prometheus-compatible series response, including label name/value
extraction and JSON serialization.
seanzatzdev pushed a commit to seanzatzdev/elasticsearch that referenced this pull request Mar 27, 2026
)

Implements an ActionListener that converts ESQL query results into a
Prometheus-compatible series response, including label name/value
extraction and JSON serialization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor Pull request authored by a developer outside the Elasticsearch team >non-issue :StorageEngine/TSDB You know, for Metrics Team:StorageEngine v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants