Просмотр исходного кода

further work on unifying datasources, #630

Torkel Ödegaard 11 лет назад
Родитель
Сommit
c61e4c02bd

+ 15 - 19
src/app/components/settings.js

@@ -13,18 +13,10 @@ function (_, crypto) {
      * @type {Object}
      */
     var defaults = {
-      elasticsearch                 : "http://"+window.location.hostname+":9200",
-      datasources                   : {
-        default: {
-          url: "http://"+window.location.hostname+":8080",
-          default: true
-        }
-      },
+      datasources                   : {},
       panels                        : ['graph', 'text'],
       plugins                       : {},
       default_route                 : '/dashboard/file/default.json',
-      grafana_index                 : 'grafana-dash',
-      elasticsearch_all_disabled    : false,
       playlist_timespan             : "1m",
       unsaved_changes_warning       : true,
       admin: {}
@@ -57,13 +49,21 @@ function (_, crypto) {
       return datasource;
     };
 
+    // backward compatible with old config
     if (options.graphiteUrl) {
-      settings.datasources = {
-        graphite: {
-          type: 'graphite',
-          url: options.graphiteUrl,
-          default: true
-        }
+      settings.datasources.graphite = {
+        type: 'graphite',
+        url: options.graphiteUrl,
+        default: true
+      };
+    }
+
+    if (options.elasticsearch) {
+      settings.datasources.elasticsearch = {
+        type: 'elasticsearch',
+        url: options.elasticsearch,
+        index: options.grafana_index,
+        grafanaDB: true
       };
     }
 
@@ -73,10 +73,6 @@ function (_, crypto) {
       if (datasource.type === 'influxdb') { parseMultipleHosts(datasource); }
     });
 
-    var elasticParsed = parseBasicAuth({ url: settings.elasticsearch });
-    settings.elasticsearchBasicAuth = elasticParsed.basicAuth;
-    settings.elasticsearch = elasticParsed.url;
-
     if (settings.plugins.panels) {
       settings.panels = _.union(settings.panels, settings.plugins.panels);
     }

+ 1 - 0
src/app/services/annotationsSrv.js

@@ -37,6 +37,7 @@ define([
 
       var promises  = _.map(annotations, function(annotation) {
         var datasource = datasourceSrv.get(annotation.datasource);
+
         return datasource.annotationQuery(annotation, filterSrv, rangeUnparsed)
           .then(this.receiveAnnotationResults)
           .then(null, errorHandler);

+ 5 - 5
src/app/services/elasticsearch/es-datasource.js

@@ -31,10 +31,10 @@ function (angular, _, $, config, kbn, moment) {
         method: method,
         data: data
       };
-      // TODO: fix basic auth
-      if (config.elasticsearchBasicAuth) {
+
+      if (this.basicAuth) {
         options.headers = {
-          "Authorization": "Basic " + config.elasticsearchBasicAuth
+          "Authorization": "Basic " + this.basicAuth
         };
       }
 
@@ -117,8 +117,8 @@ function (angular, _, $, config, kbn, moment) {
           } else {
             return false;
           }
-        }, function(data, status) {
-          if(status === 0) {
+        }, function(data) {
+          if(data.status === 0) {
             throw "Could not contact Elasticsearch. Please ensure that Elasticsearch is reachable from your browser.";
           } else {
             throw "Could not find dashboard " + id;