Skip to content

Commit

Permalink
docs(datasource): add request objects to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bergquist committed Mar 4, 2016
1 parent 1d8222e commit c21a210
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
71 changes: 70 additions & 1 deletion docs/sources/plugins/datasources.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ There are two datasource specific settings for the plugin.json
"metrics": true,
"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
The javascript object that communicates with the database and transforms data to times series.
Expand All @@ -37,6 +37,75 @@ annotationsQuery(options) // used dashboards to get annotations
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

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class GenericDatasource {
annotationQuery(options) {
return this.backendSrv.datasourceRequest({
url: this.url + '/annotations',
method: 'GET'
method: 'POST',
data: options
}).then(result => {
return result.data;
});
Expand Down

0 comments on commit c21a210

Please sign in to comment.