From 2d542aede98139b9bb3c1b43e4db1ce8f127dc85 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Mon, 15 Jul 2013 22:08:53 -0700 Subject: [PATCH] Fix for trend panel and stacking in default dashboard --- dashboards/default.json | 4 ++-- panels/trends/module.js | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/dashboards/default.json b/dashboards/default.json index 0b59b1375db..7711805c159 100644 --- a/dashboards/default.json +++ b/dashboards/default.json @@ -188,7 +188,7 @@ "spyable": true, "zoomlinks": true, "bars": true, - "stack": false, + "stack": true, "points": false, "lines": false, "legend": true, @@ -266,4 +266,4 @@ "pattern": "[logstash-]YYYY.MM.DD", "default": "logstash-*" } -} \ No newline at end of file +} diff --git a/panels/trends/module.js b/panels/trends/module.js index 0b45dd8432d..87b8f734f4c 100644 --- a/panels/trends/module.js +++ b/panels/trends/module.js @@ -48,9 +48,22 @@ angular.module('kibana.trends', []) if(dashboard.indices.length == 0) { return } else { - $scope.index = dashboard.indices + $scope.index = segment > 0 ? $scope.index : dashboard.indices; } + // Determine a time field + var timeField = _.uniq(_.pluck(filterSrv.getByType('time'),'field')) + if(timeField.length > 1) { + $scope.panel.error = "Time field must be consistent amongst time filters" + return + } else if(timeField.length == 0) { + $scope.panel.error = "A time filter must exist for this panel to function" + return + } else { + timeField = timeField[0] + } + + $scope.time = filterSrv.timeRange('min'); $scope.old_time = { from : new Date($scope.time.from.getTime() - interval_to_seconds($scope.panel.ago)*1000), to : new Date($scope.time.to.getTime() - interval_to_seconds($scope.panel.ago)*1000) @@ -58,12 +71,18 @@ angular.module('kibana.trends', []) var _segment = _.isUndefined(segment) ? 0 : segment var request = $scope.ejs.Request(); + var _ids_without_time = _.difference(filterSrv.ids,filterSrv.idsByType('time')) + // Build the question part of the query _.each(query.ids, function(id) { var q = $scope.ejs.FilteredQuery( ejs.QueryStringQuery(query.list[id].query || '*'), - filterSrv.getBoolFilter(filterSrv.ids)) + filterSrv.getBoolFilter(_ids_without_time).must( + ejs.RangeFilter(timeField) + .from($scope.time.from) + .to($scope.time.to) + )) request = request .facet($scope.ejs.QueryFacet(id) @@ -75,9 +94,11 @@ angular.module('kibana.trends', []) _.each(query.ids, function(id) { var q = $scope.ejs.FilteredQuery( ejs.QueryStringQuery(query.list[id].query || '*'), - ejs.RangeFilter($scope.time.field) + filterSrv.getBoolFilter(_ids_without_time).must( + ejs.RangeFilter(timeField) .from($scope.old_time.from) - .to($scope.old_time.to)) + .to($scope.old_time.to) + )) request = request .facet($scope.ejs.QueryFacet("old_"+id) .query(q) @@ -92,11 +113,13 @@ angular.module('kibana.trends', []) kbnIndex.indices( $scope.old_time.from, $scope.old_time.to, - $scope.time.pattern, - $scope.time.interval + dashboard.current.index.pattern, + dashboard.current.index.interval ).then(function (p) { $scope.index = _.union(p,$scope.index); - process_results(request.indices($scope.index[_segment]).doSearch()); + request = request.indices($scope.index[_segment]) + process_results(request.doSearch()); + }); } else { process_results(request.indices($scope.index[_segment]).doSearch());