feat: PoC Prometheus/Mimir streaming Search API over HTTP - #252
Draft
itsmylife wants to merge 26 commits into
Draft
feat: PoC Prometheus/Mimir streaming Search API over HTTP#252itsmylife wants to merge 26 commits into
itsmylife wants to merge 26 commits into
Conversation
|
Wanted to link to prometheus/proposals#74 so this work is discoverable from there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
This is an exploration / proof of concept, not a merge candidate. It demonstrates end-to-end Prometheus/Mimir Search API streaming over plain HTTP. The implementation still needs to be split into small, reviewable changes and refined before production use.
Parameter handling across autocomplete and discovery consumers is also provisional. Follow-up work must ensure each call site supplies the correct Search API parameters and semantics instead of adapting values intended for the legacy labels/series endpoints.
What & why
Adds opt-in support for the Prometheus/Mimir NDJSON streaming Search API:
/api/v1/search/metric_names/api/v1/search/label_names/api/v1/search/label_valuesThe Search API provides fuzzy, scored, server-side suggestions and streams results progressively as they are computed.
This PoC integrates it into:
ResourceApiClientinterfaceThe feature is gated by the per-data-source Search API setting. When enabled, upstream Search API errors are surfaced instead of silently falling back to legacy discovery. Default behavior is unchanged while the setting is disabled.
Architecture
This implementation uses a chunked HTTP resource request:
The backend forwards upstream bytes without buffering the complete response. The frontend parses arbitrary chunk boundaries, emits completed batches immediately, and accumulates the final result.
How this differs from the earlier PoC
The earlier streaming PoC (#248) used a persistent Grafana Live WebSocket with a custom request/response protocol, per-session channels, mailboxes, request IDs, and per-slot cancellation.
This implementation explores a simpler, socket-free design:
getBackendSrv().chunked()streams bytes directly to the frontend.CallResourcestreaming forwards NDJSON without buffering.AbortControllerand request contexts propagate cancellation upstream.The trade-off is one HTTP request per search instead of multiplexing searches over a persistent connection. This PR is intended to evaluate whether that simpler operational model is preferable before committing to a production architecture.
Transport behavior
The implementation:
getBackendSrv().chunked()APIX-Grafana-Org-Id401through Grafana's login-ping flowKnown PoC gaps
The main remaining work is correct, context-specific parameter construction.
Several integrations currently reuse or adapt values intended for legacy labels/series endpoints. Before this becomes production-ready, each consumer must be audited for the correct use of:
search[]versusmatch[]batch_sizeinclude_metadataThere are also some
getBackendSrv().fetch()behaviors thatchunked()cannot reproduce through the public plugin API, including device ID injection, fetch queueing, Query Inspector events, JWT URL-login headers, and automatic error toasts. These are considered low-impact for this discovery PoC but need an explicit product decision.Dev environment / how to test
The development stack includes Prometheus
v3.13.1with--enable-feature=search-api, a data source with Search API enabled, and a classic data source for comparison.Build the backend:
Build the frontend:
Start the stack:
Use the
prometheus-search-apidata source in Explore and the query builder. Exercise the metric combobox, Metrics Explorer, and Monaco metric/label completions.Confirm results arrive progressively over a chunked HTTP resource request without a Grafana Live WebSocket.
Compare with the
prometheusdata source and confirm the classic discovery behavior remains unchanged when the toggle is off.What to focus a review on