Commit 8eb112d1 by Torkel Ödegaard

plugins: refactoring builtIn data source concept, now means data source plugins…

plugins: refactoring builtIn data source concept, now means data source plugins that you do not need to add via data sources page, that is automatically added as selectable data source, #8095
parent e8049439
......@@ -102,8 +102,9 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
datasources[ds.Name] = dsMap
}
// add datasources that are built in (meaning they are not added via data sources page, nor have any entry in datasource table)
for _, ds := range plugins.DataSources {
if ds.AlwaysDisplay {
if ds.BuiltIn {
datasources[ds.Name] = map[string]interface{}{
"type": ds.Type,
"name": ds.Name,
......
......@@ -4,13 +4,12 @@ import "encoding/json"
type DataSourcePlugin struct {
FrontendPluginBase
Annotations bool `json:"annotations"`
Metrics bool `json:"metrics"`
Alerting bool `json:"alerting"`
BuiltIn bool `json:"builtIn"`
Mixed bool `json:"mixed"`
AlwaysDisplay bool `json:"alwaysDisplay"`
App string `json:"app"`
Annotations bool `json:"annotations"`
Metrics bool `json:"metrics"`
Alerting bool `json:"alerting"`
BuiltIn bool `json:"builtIn"`
Mixed bool `json:"mixed"`
App string `json:"app"`
}
func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
......
......@@ -101,18 +101,16 @@ function (angular, _, coreModule, config) {
}
metricSources.sort(function(a, b) {
if (a.meta.builtIn) {
// these two should always be at the bottom
if (a.meta.id === "mixed" || a.meta.id === "grafana") {
return 1;
}
if (b.meta.builtIn) {
if (b.meta.id === "mixed" || b.meta.id === "grafana") {
return -1;
}
if (a.name.toLowerCase() > b.name.toLowerCase()) {
return 1;
}
if (a.name.toLowerCase() < b.name.toLowerCase()) {
return -1;
}
......
......@@ -36,7 +36,7 @@ export class VariableEditorCtrl {
$scope.mode = 'list';
$scope.datasources = _.filter(datasourceSrv.getMetricSources(), function(ds) {
return !ds.meta.builtIn && ds.value !== null;
return !ds.meta.mixed && ds.value !== null;
});
$scope.datasourceTypes = _($scope.datasources).uniqBy('meta.id').map(function(ds) {
......
......@@ -5,38 +5,16 @@ import _ from 'lodash';
class GrafanaDatasource {
/** @ngInject */
constructor(private backendSrv) {}
constructor(private backendSrv, private $q) {}
query(options) {
return this.backendSrv.post('/api/tsdb/query', {
from: options.range.from.valueOf().toString(),
to: options.range.to.valueOf().toString(),
queries: [
{
"refId": "A",
"scenarioId": "random_walk",
"intervalMs": options.intervalMs,
"maxDataPoints": options.maxDataPoints,
}
]
}).then(res => {
var data = [];
if (res.results) {
_.forEach(res.results, queryRes => {
for (let series of queryRes.series) {
data.push({
target: series.name,
datapoints: series.points
});
}
});
}
return {data: data};
});
return this.$q.when({data: []});
}
metricFindQuery() {
return this.$q.when([]);
};
annotationQuery(options) {
return this.backendSrv.get('/api/annotations', {
from: options.range.from.valueOf(),
......
......@@ -5,6 +5,5 @@
"builtIn": true,
"annotations": true,
"alwaysDisplay": true,
"metrics": true
}
......@@ -5,6 +5,5 @@
"builtIn": true,
"mixed": true,
"alwaysDisplay": true,
"metrics": true
}
......@@ -24,9 +24,13 @@ define([
type: 'test-db',
meta: { metrics: {m: 1} }
},
'--Grafana--': {
type: 'grafana',
meta: {builtIn: true, metrics: {m: 1}, id: "grafana"}
},
'--Mixed--': {
type: 'test-db',
meta: {builtIn: true, metrics: {m: 1} }
meta: {builtIn: true, metrics: {m: 1}, id: "mixed"}
},
'ZZZ': {
type: 'test-db',
......@@ -51,7 +55,8 @@ define([
expect(metricSources[1].name).to.be('BBB');
expect(metricSources[2].name).to.be('mmm');
expect(metricSources[3].name).to.be('ZZZ');
expect(metricSources[4].name).to.be('--Mixed--');
expect(metricSources[4].name).to.be('--Grafana--');
expect(metricSources[5].name).to.be('--Mixed--');
});
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment