mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
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
This commit is contained in:
parent
e80494390a
commit
8eb112d119
@ -102,8 +102,9 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
|
|||||||
datasources[ds.Name] = dsMap
|
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 {
|
for _, ds := range plugins.DataSources {
|
||||||
if ds.AlwaysDisplay {
|
if ds.BuiltIn {
|
||||||
datasources[ds.Name] = map[string]interface{}{
|
datasources[ds.Name] = map[string]interface{}{
|
||||||
"type": ds.Type,
|
"type": ds.Type,
|
||||||
"name": ds.Name,
|
"name": ds.Name,
|
||||||
|
@ -4,13 +4,12 @@ import "encoding/json"
|
|||||||
|
|
||||||
type DataSourcePlugin struct {
|
type DataSourcePlugin struct {
|
||||||
FrontendPluginBase
|
FrontendPluginBase
|
||||||
Annotations bool `json:"annotations"`
|
Annotations bool `json:"annotations"`
|
||||||
Metrics bool `json:"metrics"`
|
Metrics bool `json:"metrics"`
|
||||||
Alerting bool `json:"alerting"`
|
Alerting bool `json:"alerting"`
|
||||||
BuiltIn bool `json:"builtIn"`
|
BuiltIn bool `json:"builtIn"`
|
||||||
Mixed bool `json:"mixed"`
|
Mixed bool `json:"mixed"`
|
||||||
AlwaysDisplay bool `json:"alwaysDisplay"`
|
App string `json:"app"`
|
||||||
App string `json:"app"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
||||||
|
@ -101,18 +101,16 @@ function (angular, _, coreModule, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
metricSources.sort(function(a, b) {
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (b.meta.id === "mixed" || b.meta.id === "grafana") {
|
||||||
if (b.meta.builtIn) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.name.toLowerCase() < b.name.toLowerCase()) {
|
if (a.name.toLowerCase() < b.name.toLowerCase()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ export class VariableEditorCtrl {
|
|||||||
$scope.mode = 'list';
|
$scope.mode = 'list';
|
||||||
|
|
||||||
$scope.datasources = _.filter(datasourceSrv.getMetricSources(), function(ds) {
|
$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) {
|
$scope.datasourceTypes = _($scope.datasources).uniqBy('meta.id').map(function(ds) {
|
||||||
|
@ -5,38 +5,16 @@ import _ from 'lodash';
|
|||||||
class GrafanaDatasource {
|
class GrafanaDatasource {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private backendSrv) {}
|
constructor(private backendSrv, private $q) {}
|
||||||
|
|
||||||
query(options) {
|
query(options) {
|
||||||
return this.backendSrv.post('/api/tsdb/query', {
|
return this.$q.when({data: []});
|
||||||
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};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metricFindQuery() {
|
||||||
|
return this.$q.when([]);
|
||||||
|
};
|
||||||
|
|
||||||
annotationQuery(options) {
|
annotationQuery(options) {
|
||||||
return this.backendSrv.get('/api/annotations', {
|
return this.backendSrv.get('/api/annotations', {
|
||||||
from: options.range.from.valueOf(),
|
from: options.range.from.valueOf(),
|
||||||
|
@ -5,6 +5,5 @@
|
|||||||
|
|
||||||
"builtIn": true,
|
"builtIn": true,
|
||||||
"annotations": true,
|
"annotations": true,
|
||||||
"alwaysDisplay": true,
|
|
||||||
"metrics": true
|
"metrics": true
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,5 @@
|
|||||||
|
|
||||||
"builtIn": true,
|
"builtIn": true,
|
||||||
"mixed": true,
|
"mixed": true,
|
||||||
"alwaysDisplay": true,
|
|
||||||
"metrics": true
|
"metrics": true
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,13 @@ define([
|
|||||||
type: 'test-db',
|
type: 'test-db',
|
||||||
meta: { metrics: {m: 1} }
|
meta: { metrics: {m: 1} }
|
||||||
},
|
},
|
||||||
|
'--Grafana--': {
|
||||||
|
type: 'grafana',
|
||||||
|
meta: {builtIn: true, metrics: {m: 1}, id: "grafana"}
|
||||||
|
},
|
||||||
'--Mixed--': {
|
'--Mixed--': {
|
||||||
type: 'test-db',
|
type: 'test-db',
|
||||||
meta: {builtIn: true, metrics: {m: 1} }
|
meta: {builtIn: true, metrics: {m: 1}, id: "mixed"}
|
||||||
},
|
},
|
||||||
'ZZZ': {
|
'ZZZ': {
|
||||||
type: 'test-db',
|
type: 'test-db',
|
||||||
@ -51,7 +55,8 @@ define([
|
|||||||
expect(metricSources[1].name).to.be('BBB');
|
expect(metricSources[1].name).to.be('BBB');
|
||||||
expect(metricSources[2].name).to.be('mmm');
|
expect(metricSources[2].name).to.be('mmm');
|
||||||
expect(metricSources[3].name).to.be('ZZZ');
|
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--');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user