2022-05-26 23:06:25 +08:00
---
aliases:
2022-12-10 00:36:04 +08:00
- ../../../plugins/developing/datasources/
Explicitly set all front matter labels in the source files (#71548)
* Set every page to have defaults of 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/enterprise-licensing pages to have 'Enterprise' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/recorded-queries pages to have labels cloud,enterprise
* Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/stats-and-license pages to have labels cloud,enterprise
* Set alerting pages to have labels cloud,enterprise,oss
* Set breaking-changes pages to have labels cloud,enterprise,oss
* Set dashboards pages to have labels cloud,enterprise,oss
* Set datasources pages to have labels cloud,enterprise,oss
* Set explore pages to have labels cloud,enterprise,oss
* Set fundamentals pages to have labels cloud,enterprise,oss
* Set introduction/grafana-cloud pages to have labels cloud
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Fix introduction pages products
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set panels-visualizations pages to have labels cloud,enterprise,oss
* Set release-notes pages to have labels cloud,enterprise,oss
* Set search pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set troubleshooting pages to have labels cloud,enterprise,oss
* Set whatsnew pages to have labels cloud,enterprise,oss
* Apply updated labels from review
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
---------
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 16:10:12 +08:00
description: Deprecated guide for Angular plugin development.
2022-05-26 23:06:25 +08:00
keywords:
- grafana
- plugins
- documentation
Explicitly set all front matter labels in the source files (#71548)
* Set every page to have defaults of 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/enterprise-licensing pages to have 'Enterprise' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/recorded-queries pages to have labels cloud,enterprise
* Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/stats-and-license pages to have labels cloud,enterprise
* Set alerting pages to have labels cloud,enterprise,oss
* Set breaking-changes pages to have labels cloud,enterprise,oss
* Set dashboards pages to have labels cloud,enterprise,oss
* Set datasources pages to have labels cloud,enterprise,oss
* Set explore pages to have labels cloud,enterprise,oss
* Set fundamentals pages to have labels cloud,enterprise,oss
* Set introduction/grafana-cloud pages to have labels cloud
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Fix introduction pages products
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set panels-visualizations pages to have labels cloud,enterprise,oss
* Set release-notes pages to have labels cloud,enterprise,oss
* Set search pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set troubleshooting pages to have labels cloud,enterprise,oss
* Set whatsnew pages to have labels cloud,enterprise,oss
* Apply updated labels from review
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
---------
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 16:10:12 +08:00
labels:
products:
- enterprise
- oss
title: Legacy data source plugins
2022-05-26 23:06:25 +08:00
---
2016-03-03 01:01:43 +08:00
2020-05-08 00:45:52 +08:00
# Legacy data source plugins
2016-03-01 16:39:10 +08:00
2020-02-11 20:32:20 +08:00
Data source plugins enable people to develop plugins for any database that
2020-04-21 21:11:34 +08:00
communicates over HTTP. Its up to the plugin to transform the data into
2016-03-30 22:56:22 +08:00
time series data so that any grafana panel can then show it.
2019-09-20 06:04:56 +08:00
## Data source development
2016-03-30 22:56:22 +08:00
> Our goal is not to have a very extensive documentation but rather have actual
2020-04-04 04:58:50 +08:00
> code that people can look at. Example implementations of a data source can be
> found in these repos:
> - [simple-json-datasource](https://github.com/grafana/simple-json-datasource)
> - [simple-datasource](https://github.com/grafana/simple-datasource)
> - [simple-json-backend-datasource](https://github.com/grafana/simple-json-backend-datasource)
2016-03-03 01:01:43 +08:00
2020-02-11 20:32:20 +08:00
To interact with the rest of grafana the plugins module file can export 4 different components.
2016-03-03 01:01:43 +08:00
- Datasource (Required)
- QueryCtrl (Required)
- ConfigCtrl (Required)
- AnnotationsQueryCtrl
## Plugin json
2016-03-30 22:56:22 +08:00
2019-09-20 06:04:56 +08:00
There are two data source specific settings for the plugin.json
2016-03-30 22:56:22 +08:00
2020-02-11 20:32:20 +08:00
```json
2016-03-03 01:01:43 +08:00
"metrics": true,
"annotations": false,
```
2016-03-30 22:56:22 +08:00
2020-02-11 20:32:20 +08:00
These settings indicate what kind of data the plugin can deliver. At least one of them has to be true.
2016-03-03 01:01:43 +08:00
2019-09-20 06:04:56 +08:00
## Data source
2017-02-07 14:48:01 +08:00
2016-03-03 01:01:43 +08:00
The javascript object that communicates with the database and transforms data to times series.
2019-09-20 06:04:56 +08:00
The Data source should contain the following functions:
2017-02-07 14:48:01 +08:00
2017-10-06 01:01:03 +08:00
```javascript
2021-08-06 21:52:36 +08:00
query(options); // used by panels to get data
testDatasource(); // used by data source configuration page to make sure the connection is working
annotationQuery(options); // used by dashboards to get annotations
metricFindQuery(options); // used by query editor to get metric suggestions.
2016-03-03 01:01:43 +08:00
```
2017-02-07 14:48:01 +08:00
### testDatasource
2021-08-06 21:52:36 +08:00
When a user clicks on the _Save & Test_ button when adding a new data source, the details are first saved to the database and then the `testDatasource` function that is defined in your data source plugin will be called. It is recommended that this function makes a query to the data source that will also test that the authentication details are correct. This is so the data source is correctly configured when the user tries to write a query in a new dashboard.
2017-02-07 14:48:01 +08:00
2016-03-04 15:45:46 +08:00
### Query
2017-02-07 14:48:01 +08:00
Request object passed to datasource.query function:
2016-03-04 15:45:46 +08:00
```json
{
2016-03-04 15:47:22 +08:00
"range": { "from": "2015-12-22T03:06:13.851Z", "to": "2015-12-22T06:48:24.137Z" },
2016-03-04 17:10:25 +08:00
"interval": "5s",
2016-03-04 16:14:25 +08:00
"targets": [
2016-03-04 16:46:57 +08:00
{ "refId": "B", "target": "upper_75" },
{ "refId": "A", "target": "upper_90" }
2016-03-04 16:14:25 +08:00
],
2016-03-04 15:47:22 +08:00
"format": "json",
2020-02-11 20:32:20 +08:00
"maxDataPoints": 2495 // decided by the panel
2016-03-04 15:45:46 +08:00
}
```
2020-02-11 20:32:20 +08:00
There are two different kinds of results for data sources:
2019-09-20 06:04:56 +08:00
time series and table. Time series is the most common format and is supported by all data sources and panels. Table format is only supported by the InfluxDB data source and table panel. But we might see more of this in the future.
2017-02-07 14:48:01 +08:00
Time series response from datasource.query.
An array of:
2016-03-08 16:26:15 +08:00
2016-03-04 15:45:46 +08:00
```json
[
{
2021-08-06 21:52:36 +08:00
"target": "upper_75",
"datapoints": [
2018-02-03 23:21:23 +08:00
[622, 1450754160000],
[365, 1450754220000]
2016-03-04 15:45:46 +08:00
]
},
{
2021-08-06 21:52:36 +08:00
"target": "upper_90",
"datapoints": [
2018-02-03 23:21:23 +08:00
[861, 1450754160000],
[767, 1450754220000]
2016-03-04 15:45:46 +08:00
]
}
]
```
2017-02-07 14:48:01 +08:00
Table response from datasource.query.
An array of:
2016-03-08 16:26:15 +08:00
```json
[
{
"columns": [
{
"text": "Time",
"type": "time",
"sort": true,
2020-10-13 17:10:48 +08:00
"desc": true
2016-03-08 16:26:15 +08:00
},
{
2020-10-13 17:10:48 +08:00
"text": "mean"
2016-03-08 16:26:15 +08:00
},
{
2020-10-13 17:10:48 +08:00
"text": "sum"
2016-03-08 16:26:15 +08:00
}
],
"rows": [
2021-08-06 21:52:36 +08:00
[1457425380000, null, null],
[1457425370000, 1002.76215352, 1002.76215352]
2016-03-08 16:26:15 +08:00
],
"type": "table"
}
]
```
2016-03-04 15:45:46 +08:00
### Annotation Query
2017-02-07 14:48:01 +08:00
Request object passed to datasource.annotationQuery function:
2016-03-04 15:45:46 +08:00
```json
{
2016-03-04 16:46:57 +08:00
"range": { "from": "2016-03-04T04:07:55.144Z", "to": "2016-03-04T07:07:55.144Z" },
2021-08-06 21:52:36 +08:00
"rangeRaw": { "from": "now-3h", "to": "now" },
2016-03-04 16:46:57 +08:00
"annotation": {
"datasource": "generic datasource",
"enable": true,
"name": "annotation name"
2019-09-10 17:04:44 +08:00
},
"dashboard": DashboardModel
2016-03-04 15:45:46 +08:00
}
```
2017-02-07 14:48:01 +08:00
Expected result from datasource.annotationQuery:
2016-03-04 15:45:46 +08:00
```json
[
{
"annotation": {
"name": "annotation name", //should match the annotation name in grafana
"enabled": true,
2020-02-11 20:32:20 +08:00
"datasource": "generic datasource"
2021-08-06 21:52:36 +08:00
},
2016-03-04 15:45:46 +08:00
"title": "Cluster outage",
"time": 1457075272576,
"text": "Joe causes brain split",
2019-03-14 03:48:49 +08:00
"tags": ["joe", "cluster", "failure"]
2016-03-04 15:45:46 +08:00
}
]
```
2016-03-03 01:01:43 +08:00
## QueryCtrl
2020-02-11 20:32:20 +08:00
A JavaScript class that will be instantiated and treated as an Angular controller when the user edits metrics in a panel. This class has to inherit from the `app/plugins/sdk.QueryCtrl` class.
2016-03-03 01:01:43 +08:00
2020-02-11 20:32:20 +08:00
Requires a static template or `templateUrl` variable which will be rendered as the view for this controller.
2016-03-03 01:01:43 +08:00
## ConfigCtrl
2019-09-20 06:04:56 +08:00
A JavaScript class that will be instantiated and treated as an Angular controller when a user tries to edit or create a new data source of this type.
2016-03-03 01:01:43 +08:00
2020-02-11 20:32:20 +08:00
Requires a static template or `templateUrl` variable which will be rendered as the view for this controller.
2016-03-03 01:01:43 +08:00
## AnnotationsQueryCtrl
2020-02-11 20:32:20 +08:00
A JavaScript class that will be instantiated and treated as an Angular controller when the user chooses this type of data source in the templating menu in the dashboard.
2016-03-03 01:01:43 +08:00
2020-02-11 20:32:20 +08:00
Requires a static template or `templateUrl` variable which will be rendered as the view for this controller. The fields that are bound to this controller are then sent to the Database objects annotationQuery function.