浏览代码

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

Torkel Ödegaard 8 年之前
父节点
当前提交
8eb112d119

+ 2 - 1
pkg/api/frontendsettings.go

@@ -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,

+ 6 - 7
pkg/plugins/datasource_plugin.go

@@ -4,13 +4,12 @@ import "encoding/json"
 
 
 type DataSourcePlugin struct {
 type DataSourcePlugin struct {
 	FrontendPluginBase
 	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 {
 func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {

+ 3 - 5
public/app/core/services/datasource_srv.js

@@ -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.builtIn) {
+        if (b.meta.id === "mixed" || b.meta.id === "grafana") {
           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;
         }
         }

+ 1 - 1
public/app/features/templating/editor_ctrl.ts

@@ -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) {

+ 6 - 28
public/app/plugins/datasource/grafana/datasource.ts

@@ -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', {
-      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) {
   annotationQuery(options) {
     return this.backendSrv.get('/api/annotations', {
     return this.backendSrv.get('/api/annotations', {
       from: options.range.from.valueOf(),
       from: options.range.from.valueOf(),

+ 0 - 1
public/app/plugins/datasource/grafana/plugin.json

@@ -5,6 +5,5 @@
 
 
   "builtIn": true,
   "builtIn": true,
   "annotations": true,
   "annotations": true,
-  "alwaysDisplay": true,
   "metrics": true
   "metrics": true
 }
 }

+ 0 - 1
public/app/plugins/datasource/mixed/plugin.json

@@ -5,6 +5,5 @@
 
 
   "builtIn": true,
   "builtIn": true,
   "mixed": true,
   "mixed": true,
-  "alwaysDisplay": true,
   "metrics": true
   "metrics": true
 }
 }

+ 7 - 2
public/test/specs/datasource_srv_specs.js

@@ -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--');
       });
       });
     });
     });
   });
   });