From d5c156be75254f41ff14905fa74548d2d14cf8cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 12 Dec 2013 22:30:20 +0100 Subject: [PATCH] working on metric key search --- src/app/components/settings.js | 3 +- src/app/controllers/all.js | 3 +- src/app/controllers/metricKeys.js | 113 +++++++++++++++++++++++++ src/app/controllers/search.js | 53 +++++++++--- src/app/panels/graphite/graphiteSrv.js | 2 +- src/app/partials/dashLoader.html | 92 -------------------- src/app/partials/dasheditor.html | 9 +- src/app/partials/loadmetrics.html | 25 ++++++ src/app/partials/search.html | 12 ++- src/css/bootstrap.dark.min.css | 2 +- src/vendor/bootstrap/less/grafana.less | 5 ++ 11 files changed, 202 insertions(+), 117 deletions(-) create mode 100644 src/app/controllers/metricKeys.js create mode 100644 src/app/partials/loadmetrics.html diff --git a/src/app/components/settings.js b/src/app/components/settings.js index 8d255530162..d97c3a725a8 100644 --- a/src/app/components/settings.js +++ b/src/app/components/settings.js @@ -14,7 +14,8 @@ function (_) { panel_names : [], kibana_index : 'kibana-int', graphiteUrl : null, - default_route : '/dashboard/file/default.json' + default_route : '/dashboard/file/default.json', + grafana_index : 'grafana-int2' }; // This initializes a new hash on purpose, to avoid adding parameters to diff --git a/src/app/controllers/all.js b/src/app/controllers/all.js index 12ca7b16d03..f11d3974cf2 100644 --- a/src/app/controllers/all.js +++ b/src/app/controllers/all.js @@ -4,5 +4,6 @@ define([ './row', './pulldown', './zoom', - './search' + './search', + './metricKeys' ], function () {}); \ No newline at end of file diff --git a/src/app/controllers/metricKeys.js b/src/app/controllers/metricKeys.js new file mode 100644 index 00000000000..c1b00f34310 --- /dev/null +++ b/src/app/controllers/metricKeys.js @@ -0,0 +1,113 @@ +define([ + 'angular', + 'underscore', + 'config' +], +function (angular, _, config) { + 'use strict'; + + var module = angular.module('kibana.controllers'); + + module.controller('MetricKeysCtrl', function($scope, $http) { + + $scope.init = function () { + $scope.metricPath = "prod.apps.api.boobarella.*"; + }; + + $scope.loadMetricsFromPath = function () { + $scope.infoText = 'loading'; + loadMetricsRecursive($scope.metricPath) + + /*$http.put(config.elasticsearch + "/grafana-int/", { +{ + "settings": { + "analysis": { + "analyzer": { + "category_path": { + "type": "custom", + "tokenizer": "category_path" + }, + "my_ngram_analyzer" : { + "tokenizer" : "my_ngram_tokenizer" + } + }, + "tokenizer": { + "category_path": { + "type": "path_hierarchy", + "delimiter": "." + }, + "my_ngram_tokenizer" : { + "type" : "nGram", + "min_gram" : "4", + "max_gram" : "8", + "token_chars": [ "letter", "digit" ] + } + } + } + }, + "mappings": { + "metricKey": { + "properties": { + "metricPath": { + "type": "string", + "index": "analyzed", + "index_analyzer": "my_ngram_analyzer" + } + } + } + } +} + });*/ + }; + + function receiveMetric(data) { + if (!data || data.length == 0) { + console.log('no data'); + return; + } + + _.each(data, function(metric) { + if (metric.expandable) { + console.log('Loading children: ' + metric.id); + loadMetricsRecursive(metric.id + ".*"); + } + if (metric.leaf) { + saveMetricKey(metric.id); + } + }); + } + + function saveMetricKey(metricId) { + + // Create request with id as title. Rethink this. + var request = ejs.Document(config.grafana_index, 'metricKey', metricId).source({ + metricPath: metricId + }); + + request.doIndex( + // Success + function(result) { + console.log('save metric success', result); + }, + function(error) { + console.log('save metric error', error); + } + ); + } + + function metricLoadError(data, status, headers, config) + { + console.log('error: ' + status); + $scope.error = "failed to get metrics from graphite"; + } + + function loadMetricsRecursive(metricPath, data, callback) + { + $http({ method: 'GET', url: config.graphiteUrl + '/metrics/find/?query=' + metricPath} ) + .success(receiveMetric) + .error(metricLoadError); + } + + }); + +}); \ No newline at end of file diff --git a/src/app/controllers/search.js b/src/app/controllers/search.js index 0f8b4e4cc56..41638c82fe7 100644 --- a/src/app/controllers/search.js +++ b/src/app/controllers/search.js @@ -1,7 +1,10 @@ define([ - 'angular' + 'angular', + 'underscore', + 'config', + 'jquery' ], -function (angular) { +function (angular, _, config, $) { 'use strict'; var module = angular.module('kibana.controllers'); @@ -11,14 +14,33 @@ function (angular) { $scope.init = function() { $scope.elasticsearch = $scope.elasticsearch || {}; $scope.giveSearchFocus = 0; + $scope.search_results = { + dashboards: [], + metrics: [], + graphs: [] + }; }; $scope.elasticsearch_dblist = function(query) { - dashboard.elasticsearch_list(query,100).then( - function(result) { - if(!_.isUndefined(result.hits)) { - $scope.hits = result.hits.total; - $scope.elasticsearch.dashboards = result.hits.hits; + var words = query.split(" "); + var query = $scope.ejs.BoolQuery(); + var terms = _.map(words, function(word) { + return $scope.ejs.MatchQuery("metricPath", word); + }); + + console.log("query: ", terms); + query.must(terms); + + var request = $scope.ejs.Request().indices(config.grafana_index).types('metricKey'); + var results = request.query(query).size(20).doSearch(); + + 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); + } + else { + $scope.search_results.metrics = []; } }); }; @@ -31,13 +53,16 @@ function (angular) { module.directive('xngFocus', function() { return function(scope, element, attrs) { - scope.$watch(attrs.xngFocus, - function (newValue) { - setTimeout(function() { - newValue && element.focus(); - }, 200); - },true); - }; + $(element).click(function(e) { + e.stopPropagation(); + }); + + scope.$watch(attrs.xngFocus,function (newValue) { + setTimeout(function() { + newValue && element.focus(); + }, 200); + },true); + }; }); }); \ No newline at end of file diff --git a/src/app/panels/graphite/graphiteSrv.js b/src/app/panels/graphite/graphiteSrv.js index 4828d9bd56d..938c2c28cbf 100644 --- a/src/app/panels/graphite/graphiteSrv.js +++ b/src/app/panels/graphite/graphiteSrv.js @@ -84,7 +84,7 @@ function ($, RQ, config) { accepts: { text: 'application/json' }, cache: false, dataType: 'json', - url: config.graphiteUrl, + url: config.graphiteUrl + '/render/', type: "POST", data: parameters.join('&') }); diff --git a/src/app/partials/dashLoader.html b/src/app/partials/dashLoader.html index 12bc24a0de4..c21d79bea2e 100644 --- a/src/app/partials/dashLoader.html +++ b/src/app/partials/dashLoader.html @@ -11,99 +11,7 @@
  • - -
  • diff --git a/src/app/partials/dasheditor.html b/src/app/partials/dasheditor.html index 70950471951..f6475f57fab 100644 --- a/src/app/partials/dasheditor.html +++ b/src/app/partials/dasheditor.html @@ -2,7 +2,7 @@
    Dashboard settings
    -
    +
    @@ -122,12 +122,15 @@
    -
    +
    + +
    + +
    -