-
Notifications
You must be signed in to change notification settings - Fork 10.8k
web/api: add search API endpoint #18573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e8e25eb
99ef765
d82cf5f
e713c64
9170a8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -521,6 +521,114 @@ curl http://localhost:9090/api/v1/label/U__http_2e_status_code/values | |||||||
| } | ||||||||
| ``` | ||||||||
|
|
||||||||
| ### Searching metric names, label names, and label values | ||||||||
|
|
||||||||
| These endpoints are experimental and must be enabled with | ||||||||
| `--enable-feature=search-api`. | ||||||||
|
|
||||||||
| The following endpoints provide streamed discovery results for metric names, | ||||||||
| label names, and label values: | ||||||||
|
|
||||||||
| ``` | ||||||||
| GET /api/v1/search/metric_names | ||||||||
| POST /api/v1/search/metric_names | ||||||||
| GET /api/v1/search/label_names | ||||||||
| POST /api/v1/search/label_names | ||||||||
| GET /api/v1/search/label_values | ||||||||
| POST /api/v1/search/label_values | ||||||||
| ``` | ||||||||
|
|
||||||||
| These endpoints return newline-delimited JSON with content type | ||||||||
| `application/x-ndjson`. The stream contract is: | ||||||||
|
|
||||||||
| - Zero or more **batch lines**, each with a `results` array and an optional | ||||||||
| `warnings` array. | ||||||||
| - The stream then ends with **either** a **trailer line** (`status`, `has_more`, | ||||||||
| optional `warnings`) **or** an **error line** (`status`, `errorType`, `error`) | ||||||||
| if iteration failed mid-stream after the first batch was sent. | ||||||||
|
|
||||||||
| ```json | ||||||||
| {"results":[{"name":"http_requests_total","type":"counter","help":"Total HTTP requests."}]} | ||||||||
| {"status":"success","has_more":false} | ||||||||
| ``` | ||||||||
|
|
||||||||
| If an error occurs **before** streaming starts, the API returns the usual | ||||||||
| Prometheus JSON error object with a 4xx/5xx status code. If an error occurs | ||||||||
| **after** streaming starts, the stream ends with an NDJSON error line in place | ||||||||
| of the trailer. | ||||||||
|
|
||||||||
| Clients must tolerate an abrupt EOF without a trailer (for example, on | ||||||||
| transport failure or server shutdown) and must ignore unknown fields in the | ||||||||
| trailer for forward compatibility. | ||||||||
|
|
||||||||
| The `has_more` field in the trailer is informational only: this version of | ||||||||
| the API does not provide a pagination cursor. To retrieve more results, raise | ||||||||
| `limit` (subject to the operator-configured `--web.search.max-limit`) or narrow | ||||||||
| the request via `match[]`. A future version of the API may add a cursor. | ||||||||
|
|
||||||||
| Common URL query parameters: | ||||||||
|
|
||||||||
| - `match[]=<series_selector>`: Repeated series selector used to scope the | ||||||||
| search. Optional. | ||||||||
| - `search[]=<string>`: Repeated search string matched against names or values. | ||||||||
| Multiple values use OR semantics. Optional. | ||||||||
| - `fuzz_threshold=<number>`: Fuzzy threshold from 0 to 100. Optional. A value | ||||||||
| of 0 is the lowest fuzzy threshold. | ||||||||
| - `fuzz_alg=<subsequence | jarowinkler>`: Matching algorithm. Optional. Default | ||||||||
| is `subsequence`. | ||||||||
| - `case_sensitive=<bool>`: Toggle case-sensitive matching. Optional. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| - `sort_by=<string>`: Sort mode. Supported values depend on the endpoint. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| - `sort_dir=<asc | dsc>`: Sort direction. Optional. Only valid with | ||||||||
| `sort_by=alpha`. | ||||||||
| - `include_score=<bool>`: Include the relevance score in each result. Optional. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| - `start=<rfc3339 | unix_timestamp>`: Start timestamp. Optional. | ||||||||
| - `end=<rfc3339 | unix_timestamp>`: End timestamp. Optional. | ||||||||
| - `limit=<number>`: Maximum number of returned results. Optional. Default is | ||||||||
| 100. | ||||||||
| - `batch_size=<number>`: Preferred number of results per NDJSON batch. | ||||||||
| Optional. Default is 100. | ||||||||
|
|
||||||||
| The `start` and `end` parameters narrow results to the selected time window. | ||||||||
| Results may include values from series active slightly outside that window, | ||||||||
| because Prometheus stores data in fixed-size blocks (typically 2 hours each). | ||||||||
|
|
||||||||
| Additional parameters for `/api/v1/search/metric_names`: | ||||||||
|
|
||||||||
| - `include_metadata=<bool>`: Include metric metadata in each result. | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| - `sort_by=<alpha | score>` | ||||||||
|
|
||||||||
| Additional parameters for `/api/v1/search/label_names`: | ||||||||
|
|
||||||||
| - `sort_by=<alpha | score>` | ||||||||
|
|
||||||||
| Additional parameters for `/api/v1/search/label_values`: | ||||||||
|
|
||||||||
| - `label=<label_name>`: Label name whose values should be searched. Required. | ||||||||
| - `sort_by=<alpha | score>` | ||||||||
|
|
||||||||
| This example searches metric names for autocomplete: | ||||||||
|
|
||||||||
| ```bash | ||||||||
| curl -g 'http://localhost:9090/api/v1/search/metric_names?search[]=http_req&sort_by=score&include_metadata=true&limit=5' | ||||||||
|
roidelapluie marked this conversation as resolved.
|
||||||||
| ``` | ||||||||
|
|
||||||||
| ```json | ||||||||
| {"results":[{"name":"http_requests_total","type":"counter","help":"Total HTTP requests."}]} | ||||||||
| {"status":"success","has_more":false} | ||||||||
| ``` | ||||||||
|
|
||||||||
| This example searches label values for the `instance` label within the `up` | ||||||||
| metric: | ||||||||
|
|
||||||||
| ```bash | ||||||||
| curl -g 'http://localhost:9090/api/v1/search/label_values?label=instance&match[]=up&search[]=909&sort_by=score' | ||||||||
| ``` | ||||||||
|
|
||||||||
| ```json | ||||||||
| {"results":[{"value":"localhost:9090"},{"value":"localhost:9091"}]} | ||||||||
| {"status":"success","has_more":true} | ||||||||
| ``` | ||||||||
|
|
||||||||
| ## Querying exemplars | ||||||||
|
|
||||||||
| This is **experimental** and might change in the future. | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest documenting the default: