From 4e47447dec991aa1963c0ae95390f2748f712e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 29 Jul 2014 11:26:05 +0200 Subject: [PATCH] began work on ES annotation datasource, #201 --- src/app/controllers/dashLoader.js | 6 ++-- src/app/dashboards/empty.json | 4 +-- src/app/directives/grafanaGraph.js | 1 - src/app/panels/annotations/editor.js | 7 +--- .../elasticsearch/annotation_editor.html | 1 + src/app/services/datasourceSrv.js | 17 +++++++--- .../services/elasticsearch/es-datasource.js | 32 +++++++++++++++++++ 7 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 src/app/partials/elasticsearch/annotation_editor.html create mode 100644 src/app/services/elasticsearch/es-datasource.js diff --git a/src/app/controllers/dashLoader.js b/src/app/controllers/dashLoader.js index 16ee360c4dc..dc29006bcdc 100644 --- a/src/app/controllers/dashLoader.js +++ b/src/app/controllers/dashLoader.js @@ -12,8 +12,6 @@ function (angular, _, moment) { module.controller('dashLoader', function($scope, $rootScope, $http, alertSrv, $location, playlistSrv, elastic) { $scope.init = function() { - $scope.elasticsearch = $scope.elasticsearch || {}; - $scope.onAppEvent('save-dashboard', function() { $scope.saveDashboard(); }); @@ -35,10 +33,10 @@ function (angular, _, moment) { var _l = $scope.dashboard.loader; if(type === 'load') { - return (_l.load_elasticsearch || _l.load_gist); + return (_l.load_elasticsearch); } if(type === 'save') { - return (_l.save_elasticsearch || _l.save_gist); + return (_l.save_elasticsearch); } return false; }; diff --git a/src/app/dashboards/empty.json b/src/app/dashboards/empty.json index 588c476dd19..8072eb34f59 100644 --- a/src/app/dashboards/empty.json +++ b/src/app/dashboards/empty.json @@ -66,16 +66,14 @@ } ], "loader": { - "save_gist": false, "save_elasticsearch": true, "save_default": true, "save_temp": true, "save_temp_ttl_enable": true, "save_temp_ttl": "30d", - "load_gist": false, "load_elasticsearch": true, "load_elasticsearch_size": 20, "hide": false }, "refresh": false -} \ No newline at end of file +} diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 23a6e238307..0e5d4cc4127 100755 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -167,7 +167,6 @@ function (angular, $, kbn, moment, _) { // if legend is to the right delay plot draw a few milliseconds // so the legend width calculation can be done if (shouldDelayDraw(panel)) { - console.log('delay'); legendSideLastValue = panel.legend.rightSide; setTimeout(function() { plot = $.plot(elem, data, options); diff --git a/src/app/panels/annotations/editor.js b/src/app/panels/annotations/editor.js index dfca8fd9573..a8b9bb16eb6 100644 --- a/src/app/panels/annotations/editor.js +++ b/src/app/panels/annotations/editor.js @@ -56,12 +56,7 @@ function (angular, app, _) { $scope.add = function() { $scope.currentAnnotation.datasource = $scope.currentDatasource.name; $scope.panel.annotations.push($scope.currentAnnotation); - $scope.currentAnnnotation = angular.copy(annotationDefaults); - }; - - $scope.hide = function (annotation) { - annotation.enable = !annotation.enable; - $rootScope.$broadcast('refresh'); + $scope.currentAnnotation = angular.copy(annotationDefaults); }; }); diff --git a/src/app/partials/elasticsearch/annotation_editor.html b/src/app/partials/elasticsearch/annotation_editor.html new file mode 100644 index 00000000000..12bba7fc20d --- /dev/null +++ b/src/app/partials/elasticsearch/annotation_editor.html @@ -0,0 +1 @@ +

Elasticsearch

diff --git a/src/app/services/datasourceSrv.js b/src/app/services/datasourceSrv.js index 34998352483..d3f9defb96e 100644 --- a/src/app/services/datasourceSrv.js +++ b/src/app/services/datasourceSrv.js @@ -5,13 +5,14 @@ define([ './graphite/graphiteDatasource', './influxdb/influxdbDatasource', './opentsdb/opentsdbDatasource', + './elasticsearch/es-datasource', ], function (angular, _, config) { 'use strict'; var module = angular.module('grafana.services'); - module.service('datasourceSrv', function($q, filterSrv, $http, GraphiteDatasource, InfluxDatasource, OpenTSDBDatasource) { + module.service('datasourceSrv', function($q, filterSrv, $http, $injector) { var datasources = {}; this.init = function() { @@ -29,14 +30,22 @@ function (angular, _, config) { }; this.datasourceFactory = function(ds) { + var Datasource = null; switch(ds.type) { case 'graphite': - return new GraphiteDatasource(ds); + Datasource = $injector.get('GraphiteDatasource'); + break; case 'influxdb': - return new InfluxDatasource(ds); + Datasource = $injector.get('InfluxDatasource'); + break; case 'opentsdb': - return new OpenTSDBDatasource(ds); + Datasource = $injector.get('OpenTSDBDatasource'); + break; + case 'elasticsearch': + Datasource = $injector.get('ElasticDatasource'); + break; } + return new Datasource(ds); }; this.get = function(name) { diff --git a/src/app/services/elasticsearch/es-datasource.js b/src/app/services/elasticsearch/es-datasource.js new file mode 100644 index 00000000000..83a89cd58d1 --- /dev/null +++ b/src/app/services/elasticsearch/es-datasource.js @@ -0,0 +1,32 @@ +define([ + 'angular', + 'underscore', + 'jquery', + 'config', + 'kbn', + 'moment' +], +function (angular, _, $, config, kbn, moment) { + 'use strict'; + + var module = angular.module('grafana.services'); + + module.factory('ElasticDatasource', function($q, $http) { + + function ElasticDatasource(datasource) { + this.type = 'elastic'; + this.basicAuth = datasource.basicAuth; + this.url = datasource.url; + this.name = datasource.name; + this.supportAnnotations = true; + this.annotationEditorSrc = 'app/partials/elasticsearch/annotation_editor.html'; + } + + ElasticDatasource.prototype.annotationQuery = function(annotation, filterSrv, rangeUnparsed) { + }; + + return ElasticDatasource; + + }); + +});