From b5a1b3a477e7c064b852b587de2af7545fde35e2 Mon Sep 17 00:00:00 2001 From: Torkel Odegaard Date: Sun, 15 Dec 2013 18:06:23 +0100 Subject: [PATCH] worked on metric key indexing and metric key search --- src/app/controllers/metricKeys.js | 18 +++----- src/app/controllers/search.js | 57 +++++++++++++++++++++----- src/app/partials/dashLoader.html | 41 ++++++++++++++++++ src/app/partials/search.html | 24 +++++++---- src/config.js | 2 +- src/css/bootstrap.dark.min.css | 2 +- src/vendor/bootstrap/less/grafana.less | 18 ++++++++ 7 files changed, 129 insertions(+), 33 deletions(-) diff --git a/src/app/controllers/metricKeys.js b/src/app/controllers/metricKeys.js index 2b5e2099e56..14e3b86a308 100644 --- a/src/app/controllers/metricKeys.js +++ b/src/app/controllers/metricKeys.js @@ -10,7 +10,6 @@ function (angular, _, config) { module.controller('MetricKeysCtrl', function($scope, $http, $q) { var elasticSearchUrlForMetricIndex = config.elasticsearch + '/' + config.grafana_index + '/'; - var loadingDefered; $scope.init = function () { $scope.metricPath = "prod.apps.api.boobarella.*"; @@ -103,7 +102,7 @@ function (angular, _, config) { function receiveMetric(result) { var data = result.data; - if (!data || data.length == 0) { + if (!data || data.length === 0) { console.log('no data'); return; } @@ -123,31 +122,24 @@ function (angular, _, config) { function saveMetricKey(metricId) { // Create request with id as title. Rethink this. - var request = ejs.Document(config.grafana_index, 'metricKey', metricId).source({ + var request = $scope.ejs.Document(config.grafana_index, 'metricKey', metricId).source({ metricPath: metricId }); return request.doIndex( - // Success - function(result) { + function() { $scope.infoText = "Indexing " + metricId; $scope.metricCounter = $scope.metricCounter + 1; }, - function(error) { + function() { $scope.errorText = "failed to save metric " + metricId; } ); } - function metricLoadError(data, status, headers, config) - { - $scope.errorText = "failed to get metric"; - } - function loadMetricsRecursive(metricPath) { - return $http({ method: 'GET', url: config.graphiteUrl + '/metrics/find/?query=' + metricPath} ) - .then(receiveMetric); + return $http.get(config.graphiteUrl + '/metrics/find/?query=' + metricPath).then(receiveMetric); } }); diff --git a/src/app/controllers/search.js b/src/app/controllers/search.js index 0b0c65af9b9..991fe208811 100644 --- a/src/app/controllers/search.js +++ b/src/app/controllers/search.js @@ -14,18 +14,38 @@ function (angular, _, config, $) { $scope.init = function() { $scope.elasticsearch = $scope.elasticsearch || {}; $scope.giveSearchFocus = 0; - $scope.search_results = { - dashboards: [], - metrics: [], - graphs: [] - }; + $scope.selectedIndex = null; + }; + + $scope.keyDown = function (evt) { + if (evt.keyCode === 40) { + $scope.selectedIndex = ($scope.selectedIndex || 0) + 1; + } + }; + + $scope.elasticsearch_dashboards = function(queryStr) { + dashboard.elasticsearch_list(queryStr + '*', 50).then(function(results) { + if(_.isUndefined(results.hits)) { + $scope.search_results = { dashboards: [] }; + return; + } + + $scope.search_results = { dashboards: results.hits.hits }; + }); }; $scope.elasticsearch_dblist = function(queryStr) { - var words = queryStr.split(" "); + queryStr = queryStr.toLowerCase(); + + if (queryStr.indexOf('d:') === 0) { + $scope.elasticsearch_dashboards(queryStr.substring(2, queryStr.length)); + return; + } + + var words = queryStr.split(' '); var query = $scope.ejs.BoolQuery(); var terms = _.map(words, function(word) { - return $scope.ejs.MatchQuery("metricPath_ng", word).boost(1.2); + return $scope.ejs.MatchQuery('metricPath_ng', word).boost(1.2); }); var ngramQuery = $scope.ejs.BoolQuery(); @@ -39,11 +59,10 @@ function (angular, _, config, $) { results.then(function(results) { if (results && results.hits && results.hits.hits.length > 0) { - $scope.search_results.metrics = results.hits.hits; - console.log("hits", $scope.search_results.metrics); + $scope.search_results = { metrics: results.hits.hits }; } else { - $scope.search_results.metrics = []; + $scope.search_results = { metric: [] }; } }); }; @@ -52,8 +71,26 @@ function (angular, _, config, $) { $scope.giveSearchFocus = $scope.giveSearchFocus + 1; }; + $scope.addMetricToCurrentDashboard = function (metricId) { + dashboard.current.rows.push({ + title: '', + height: '250px', + editable: true, + panels: [ + { + type: 'graphite', + title: 'test', + span: 12, + targets: [ { target: metricId } ] + } + ] + }); + }; + }); + + module.directive('xngFocus', function() { return function(scope, element, attrs) { $(element).click(function(e) { diff --git a/src/app/partials/dashLoader.html b/src/app/partials/dashLoader.html index c21d79bea2e..be23a0d0694 100644 --- a/src/app/partials/dashLoader.html +++ b/src/app/partials/dashLoader.html @@ -10,6 +10,47 @@
  • + +
  • diff --git a/src/app/partials/search.html b/src/app/partials/search.html index 692afd1bb04..2c22ed05935 100644 --- a/src/app/partials/search.html +++ b/src/app/partials/search.html @@ -19,19 +19,27 @@