mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
docs(datasource): add request objects to docs
This commit is contained in:
@@ -24,7 +24,7 @@ There are two datasource specific settings for the plugin.json
|
|||||||
"metrics": true,
|
"metrics": true,
|
||||||
"annotations": false,
|
"annotations": false,
|
||||||
```
|
```
|
||||||
These settings idicates what kind of data the plugin can deliver. Atleast one of them have to be true
|
These settings indicates what kind of data the plugin can deliver. At least one of them have to be true
|
||||||
|
|
||||||
## Datasource
|
## Datasource
|
||||||
The javascript object that communicates with the database and transforms data to times series.
|
The javascript object that communicates with the database and transforms data to times series.
|
||||||
@@ -37,6 +37,75 @@ annotationsQuery(options) // used dashboards to get annotations
|
|||||||
metricFindQuery(options) // used by query editor to get metric suggestions.
|
metricFindQuery(options) // used by query editor to get metric suggestions.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Query
|
||||||
|
|
||||||
|
Request object passed to datasource.query function
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
range: { from: '2015-12-22T03:06:13.851Z',to: '2015-12-22T06:48:24.137Z' },
|
||||||
|
interval: '5s',
|
||||||
|
targets:
|
||||||
|
[ { refId: 'B', target: 'upper_75' },
|
||||||
|
{ refId: 'A', target: 'upper_90' } ],
|
||||||
|
format: 'json',
|
||||||
|
maxDataPoints: 2495 //decided by the panel
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected response from datasource.query
|
||||||
|
An array of
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"target":"upper_75",
|
||||||
|
"datapoints":[
|
||||||
|
[622,1450754160000],
|
||||||
|
[365,1450754220000]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"target":"upper_90",
|
||||||
|
"datapoints":[
|
||||||
|
[861,1450754160000],
|
||||||
|
[767,1450754220000]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Annotation Query
|
||||||
|
|
||||||
|
Request object passed to datasource.annotationsQuery function
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
range: { from: '2016-03-04T04:07:55.144Z', to: '2016-03-04T07:07:55.144Z' },
|
||||||
|
rangeRaw: { from: 'now-3h', to: 'now' },
|
||||||
|
annotation: {
|
||||||
|
datasource: 'generic datasource',
|
||||||
|
enable: true,
|
||||||
|
name: 'annotation name'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected result from datasource.annotationQuery
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"annotation": {
|
||||||
|
"name": "annotation name", //should match the annotation name in grafana
|
||||||
|
"enabled": true,
|
||||||
|
"datasource": "generic datasource",
|
||||||
|
},
|
||||||
|
"title": "Cluster outage",
|
||||||
|
"time": 1457075272576,
|
||||||
|
"text": "Joe causes brain split",
|
||||||
|
"tags": "joe, cluster, failure"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## QueryCtrl
|
## QueryCtrl
|
||||||
|
|
||||||
A javascript class that will be instantiated and treated as an Angular controller when the user edits metrics in a panel. This class have to inherit from the app/plugins/sdk.QueryCtrl class.
|
A javascript class that will be instantiated and treated as an Angular controller when the user edits metrics in a panel. This class have to inherit from the app/plugins/sdk.QueryCtrl class.
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ export class GenericDatasource {
|
|||||||
annotationQuery(options) {
|
annotationQuery(options) {
|
||||||
return this.backendSrv.datasourceRequest({
|
return this.backendSrv.datasourceRequest({
|
||||||
url: this.url + '/annotations',
|
url: this.url + '/annotations',
|
||||||
method: 'GET'
|
method: 'POST',
|
||||||
|
data: options
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
return result.data;
|
return result.data;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user