Skip to content

Commit

Permalink
Closes #218 - Fixing getTimelineData to handle closed or bad indices
Browse files Browse the repository at this point in the history
Closes #219
  • Loading branch information
simianhacker committed May 19, 2014
1 parent 1f96312 commit c731b14
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 143 deletions.
2 changes: 1 addition & 1 deletion kibana/panels/shard_allocation/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ define(function (require) {
$scope.timeRange = {};

// Inject dependicies for the getTimelineData
var getTimeline = getTimelineDataGenerator($http, dashboard, filterSrv);
var getTimeline = getTimelineDataGenerator($http, dashboard, filterSrv, $scope);
var getStateSource = getStateSourceGenerator($http);

// Create a partial with the config for the first argument
Expand Down
37 changes: 29 additions & 8 deletions kibana/panels/shard_allocation/requests/getTimelineData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ define(function (require) {
'use strict';
var _ = require('lodash');
var getValueFromArrayOrString = require('../lib/getValueFromArrayOrString');
return function ($http, dashboard, filterSrv) {
var getTimelineData = function (config, size, timeRange, data) {
return function ($http, dashboard, filterSrv, $scope) {

var getTimelineData = function (config, size, timeRange, data, position) {
var newPosition = false;
size = _.isUndefined(size) ? 300 : size;
data = _.isUndefined(data) ? [] : data;
position = _.isUndefined(position) ? 0 : position;

timeRange = _.isUndefined(timeRange) ? filterSrv.timeRange(true) : timeRange;

var url = config.elasticsearch+'/'+dashboard.indices.join(',')+'/cluster_state/_search';
var url = config.elasticsearch+'/'+dashboard.indices[position]+'/cluster_state/_search';
var body = {
size: size,
from: 0,
Expand All @@ -27,20 +31,37 @@ define(function (require) {
}
};

return $http.post(url, body).then(function (resp) {
var success = function (resp) {
var nextTimeRange;
var hits = resp.data.hits;
data.push.apply(data, hits.hits);
if (hits.total > size && hits.hits.length === size) {

if (hits.hits.length === hits.total) {
position++;
newPosition = dashboard.indices[position] ? true : false;
}

if ((hits.total > size && hits.hits.length === size) || newPosition) {
nextTimeRange = {
to: getValueFromArrayOrString(hits.hits[size-1].fields['@timestamp']),
to: getValueFromArrayOrString(hits.hits[hits.hits.length-1].fields['@timestamp']),
from: timeRange.from
};
return getTimelineData(config, size, nextTimeRange, data); // call again
return getTimelineData(config, size, nextTimeRange, data, position); // call again
}
// flip data back to normal order
return data.reverse();
});
};

var error = function (resp) {
$scope.panel.error = resp.data.error;
position++;
if (dashboard.indices[position]) {
return getTimelineData(config, size, timeRange, data, position); // call again
}
return data.reverse();
};

return $http.post(url, body).then(success, error);

};

Expand Down
1 change: 1 addition & 0 deletions tasks/options/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = function (config) {
},
test: {
options: {
hostname: '<%= kibanaHost %>',
port: '6767',
base: testBase,
keepalive: false,
Expand Down
6 changes: 2 additions & 4 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<!DOCTYPE html><html><head><title>Marvel Tests</title><link rel="stylesheet" href="/test/bower_components/mocha/mocha.css"></head><body><div id="mocha"></div><script src="/test/bower_components/chai/chai.js"></script><script type="text/javascript">window.expect = window.chai.expect;</script><script src="/test/bower_components/mocha/mocha.js"></script><script src="/test/bower_components/sinon/sinon-1.9.0.js"></script><script type="text/javascript">mocha.setup('bdd');</script><script src="/test/bower_components/angular-1.1.5.js"></script><script src="/test/bower_components/angular-mocks/angular-mocks.js"></script><script src="/test/bower_components/requirejs/require.js"></script><script src="/kibana/app/components/require.config.js"></script>
<!--<script src="/test/bower_components/blanket/dist/qunit/blanket.js" data-cover-only="['kibana/app/panels','kibana/app/lib']" data-cover-adapter="/test/bower_components/grunt-blanket-mocha/support/mocha-blanket.js"></script>-->
<script type="text/javascript">if (window.PHANTOMJS) {
<!DOCTYPE html><html><head><title>Marvel Tests</title><link rel="stylesheet" href="/test/bower_components/mocha/mocha.css"></head><body><div id="mocha"></div><script src="/test/bower_components/chai/chai.js"></script><script type="text/javascript">window.expect = window.chai.expect;</script><script src="/test/bower_components/mocha/mocha.js"></script><script src="/test/bower_components/sinon/sinon-1.9.0.js"></script><script type="text/javascript">mocha.setup('bdd');</script><script src="/test/bower_components/angular-1.1.5.js"></script><script src="/test/bower_components/angular-mocks/angular-mocks.js"></script><script src="/test/bower_components/requirejs/require.js"></script><script src="/kibana/app/components/require.config.js"></script><script src="/test/bower_components/blanket/dist/qunit/blanket.js" data-cover-only="['kibana/app/panels','kibana/app/lib']" data-cover-adapter="/test/bower_components/grunt-blanket-mocha/support/mocha-blanket.js"></script><script type="text/javascript">if (window.PHANTOMJS) {
blanket.options("reporter", "../node_modules/grunt-blanket-mocha/support/grunt-reporter.js");
}
</script><script type="text/javascript">require.config({
baseUrl: '../kibana/app'
});
require(["/test/unit/lib/ClusterState/groupIndicesByState.js","/test/unit/lib/ClusterState/explainStatus.js","/test/unit/lib/ClusterState/filterShards.js","/test/unit/lib/ClusterState/getIndices.js","/test/unit/lib/ClusterState/getState.js","/test/unit/lib/ClusterState/incrementIndexShardStatusCount.js","/test/unit/lib/ClusterState/popFirstIndexAndReturnEndpoint.js","/test/unit/lib/ClusterState/refreshState.js","/test/unit/shard_allocation/calculateClass.js","/test/unit/shard_allocation/countChildren.js","/test/unit/shard_allocation/extractIp.js","/test/unit/shard_allocation/extractMarkers.js","/test/unit/shard_allocation/extractShards.js","/test/unit/shard_allocation/filterByName.js","/test/unit/shard_allocation/filterHiddenIndices.js","/test/unit/shard_allocation/generateQueryAndLink.js","/test/unit/shard_allocation/getStateSource.js","/test/unit/shard_allocation/getTimelineData.js","/test/unit/shard_allocation/hasUnassigned.js","/test/unit/shard_allocation/hasUnassignedPrimaries.js","/test/unit/shard_allocation/updateColors.js","/test/unit/shard_allocation/vents.js"], function () {
require(["/test/unit/lib/ClusterState/explainStatus.js","/test/unit/lib/ClusterState/filterShards.js","/test/unit/lib/ClusterState/getIndices.js","/test/unit/lib/ClusterState/getState.js","/test/unit/lib/ClusterState/groupIndicesByState.js","/test/unit/lib/ClusterState/incrementIndexShardStatusCount.js","/test/unit/lib/ClusterState/popFirstIndexAndReturnEndpoint.js","/test/unit/lib/ClusterState/refreshState.js","/test/unit/shard_allocation/calculateClass.js","/test/unit/shard_allocation/countChildren.js","/test/unit/shard_allocation/extractIp.js","/test/unit/shard_allocation/extractMarkers.js","/test/unit/shard_allocation/extractShards.js","/test/unit/shard_allocation/filterByName.js","/test/unit/shard_allocation/filterHiddenIndices.js","/test/unit/shard_allocation/generateQueryAndLink.js","/test/unit/shard_allocation/getStateSource.js","/test/unit/shard_allocation/getTimelineData.js","/test/unit/shard_allocation/hasUnassigned.js","/test/unit/shard_allocation/hasUnassignedPrimaries.js","/test/unit/shard_allocation/updateColors.js","/test/unit/shard_allocation/vents.js"], function () {
setTimeout(function () {
window.mochaRunner = mocha.run();
if (window.mochaRunner) {
Expand Down
130 changes: 0 additions & 130 deletions test/unit/shard_allocation/getTimelineData.js

This file was deleted.

0 comments on commit c731b14

Please sign in to comment.