mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 04:21:50 +08:00
API: Add endpoint for updating a data source by its UID (#49396)
* API: Add endpoint for updating a data source by UID * Update docs markdown * Update swagger * Apply suggestions from code review Co-authored-by: Selene <selenepinillos@gmail.com>
This commit is contained in:

committed by
GitHub

parent
8f4c3e94b0
commit
be0d043673
@ -415,10 +415,12 @@ Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||||
```
|
||||
|
||||
**Example Response**:
|
||||
`GET /api/datasources/:datasourceId/resources/*`
|
||||
|
||||
```http
|
||||
HTTP/1.1 200
|
||||
Content-Type: application/json
|
||||
|
||||
```
|
||||
|
||||
## Check data source health
|
||||
|
||||
@ -466,6 +468,7 @@ Content-Type: application/json
|
||||
|
||||
**Example Response**:
|
||||
|
||||
```http
|
||||
HTTP/1.1 200
|
||||
Content-Type: application/json
|
||||
|
||||
@ -495,6 +498,88 @@ Content-Type: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
```
|
||||
|
||||
## Query a data source
|
||||
|
||||
Queries a data source having a backend implementation.
|
||||
|
||||
`POST /api/ds/query`
|
||||
|
||||
> **Note:** Grafana's built-in data sources usually have a backend implementation.
|
||||
|
||||
**Example request for the Test data source**:
|
||||
|
||||
```http
|
||||
POST /api/ds/query HTTP/1.1
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
```
|
||||
|
||||
JSON Body schema:
|
||||
|
||||
- **from/to** – Specifies the time range for the queries. The time can be either epoch timestamps in milliseconds or relative using Grafana time units. For example, `now-5m`.
|
||||
- **queries** – Specifies one or more queries. Must contain at least 1.
|
||||
- **queries.datasource.uid** – Specifies the UID of data source to be queried. Each query in the request must have a unique `datasource`.
|
||||
- **queries.refId** – Specifies an identifier of the query. Defaults to "A".
|
||||
- **queries.format** – Specifies the format the data should be returned in. Valid options are `time_series` or `table` depending on the data source.
|
||||
- **queries.maxDataPoints** - Species the maximum amount of data points that a dashboard panel can render. Defaults to 100.
|
||||
- **queries.intervalMs** - Specifies the time series time interval in milliseconds. Defaults to 1000.
|
||||
|
||||
In addition, specific properties of each data source should be added in a request (for example **queries.stringInput** as shown in the request above). To better understand how to form a query for a certain data source, use the Developer Tools in your browser of choice and inspect the HTTP requests being made to `/api/ds/query`.
|
||||
|
||||
**Example Test data source time series query response:**
|
||||
|
||||
```json
|
||||
{
|
||||
"results": {
|
||||
"A": {
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"refId": "A",
|
||||
"fields": [
|
||||
{
|
||||
"name": "time",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "A-series",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "int64",
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[1644488152084, 1644488212084, 1644488272084, 1644488332084, 1644488392084, 1644488452084],
|
||||
[1, 20, 90, 30, 5, 0]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Status codes
|
||||
|
||||
| Code | Description |
|
||||
| ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 200 | All data source queries returned a successful response. |
|
||||
| 400 | Bad request due to invalid JSON, missing content type, missing or invalid fields, etc. Or one or more data source queries were unsuccessful. Refer to the body for more details. |
|
||||
| 403 | Access denied. |
|
||||
| 404 | Either the data source or plugin required to fulfil the request could not be found. |
|
||||
| 500 | Unexpected error. Refer to the body and/or server logs for more details. |
|
||||
|
||||
## Deprecated resources
|
||||
|
||||
The following resources have been deprecated. They will be removed in a future release.
|
||||
|
||||
|
Reference in New Issue
Block a user