feat: info() data-label autocomplete via /api/v1/info_labels (PoC) - #244
Draft
itsmylife wants to merge 3 commits into
Draft
feat: info() data-label autocomplete via /api/v1/info_labels (PoC)#244itsmylife wants to merge 3 commits into
itsmylife wants to merge 3 commits into
Conversation
# Conflicts: # provisioning/datasources/datasources.yml
Contributor
|
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update or ping for review. Thank you for your contributions! |
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.
What this is
This adds autocompletion for the PromQL
info(<base>, { … })function, for its data-label selector. It uses the new experimental Prometheus endpoint/api/v1/info_labels.So when you type inside the second argument of
info(), you get suggestions for the data-label names and values that come from the info metrics in scope (for exampletarget_info). The suggestions are scoped by the first argument ofinfo().The whole thing is opt-in per datasource with a new
jsonData.infoLabelsAutocompletetoggle, so it never fires against a normal Prometheus.Warning
This is a PoC. I pushed it as one single commit only to show that it works end to end.
Please don't review or merge it like this, I will split it into small PRs (see "Follow-up").
How to run and test it
The endpoint is experimental and does not exist in normal Prometheus yet, so you need Arve's branch to get a server that serves
/api/v1/info_labels.git clone https://github.com/aknuds1/prometheus cd prometheus git checkout arve/info-autocomplete go run ./documentation/examples/info-autocomplete-demoThis starts Prometheus on 127.0.0.1:9090 with the needed feature flags already on (search-api and promql-experimental-functions), and it also appends its own demo series (
target_info,build_info,http_requests_total,db_queries_total).This branch already has a provisioned datasource pointing at that demo (
provisioning/datasources/datasources.yml, nameprometheus-info-labels-demo). Grafana runs in Docker, so it reaches the host demo via http://host.docker.internal:9090. On Linux use the docker bridge gateway or run with --network host. The datasource hasjsonData.infoLabelsAutocomplete: trueso the feature is enabled.In Explore, open the code editor with that datasource and try code completion at
^:There are also unit tests (yarn test). They mock the request layer, so for the unit tests you do not need a live server.
Why frontend only, and no streaming API here
The
/api/v1/info_labelsendpoint returns NDJSON, so technically it is a stream. But in this PR the frontend just fetches the full response body as text and parses it line by line. It does not consume it as a live stream, and there is no backend streaming plumbing (Grafana Live,StreamHandler, etc).I did this on purpose:
limit(andvalues_limit), so the payload is small. Buffering the whole body and parsing it once is simple and fast enough, and it keeps this PR frontend only with zero backend changes.Follow-up
I will split this PoC into around 9 or 10 small PRs. Almost all of them are behavior neutral (dead code or a no-op config), so the final PR that actually enables the feature stays very small. The real behavior change is only about 4 lines in monaco-completion-provider.ts.