From c21a2101989ed0b303072b9a8fefed60fd7a6236 Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 4 Mar 2016 08:45:46 +0100 Subject: [PATCH] docs(datasource): add request objects to docs --- docs/sources/plugins/datasources.md | 71 ++++++++++++++++++- .../src/datasource.js | 3 +- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/docs/sources/plugins/datasources.md b/docs/sources/plugins/datasources.md index 41055cf84ed..2edb8be5231 100644 --- a/docs/sources/plugins/datasources.md +++ b/docs/sources/plugins/datasources.md @@ -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. @@ -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. diff --git a/examples/datasource-plugin-genericdatasource/src/datasource.js b/examples/datasource-plugin-genericdatasource/src/datasource.js index 1a7fe9643dd..a59362f8268 100644 --- a/examples/datasource-plugin-genericdatasource/src/datasource.js +++ b/examples/datasource-plugin-genericdatasource/src/datasource.js @@ -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; });