Mock responses when intentionally searching no indexes

Elasticsearch requests for a search with no matching indexes will
actually be rejected by shield with a 404, and we're doing such a search
automatically whenever we know there are no matching indexes that
contain data in the current time interval.

Instead of throwing a fatal error, we instead can handle this case
gracefully in the same way we do when there are no matching documents.

Fixes #5571
This commit is contained in:
Court Ewing 2015-12-04 14:07:10 -05:00 committed by Joe Fleming
parent a7056d34ee
commit 2038c7c816
2 changed files with 29 additions and 1 deletions

View file

@ -93,7 +93,12 @@ define(function (require) {
ignore_unavailable: true,
preference: sessionId,
body: body
}));
}))
.catch(function (err) {
return strategy.handleResponseError
? strategy.handleResponseError(executable, err)
: Promise.reject(err);
});
})
.then(function (clientResp) {
return strategy.getResponses(clientResp);

View file

@ -4,9 +4,32 @@ define(function (require) {
var angular = require('angular');
var toJson = require('ui/utils/aggressive_parse').toJson;
function emptyResponse() {
return { hits: { total: 0, hits: [] } };
};
return {
clientMethod: 'msearch',
/**
* Recover from a 404 when searching against no indexes
*
* If we get a 404 while intentionally searching for no indexes, we can
* simply mock an empty result since that is ultimately what kibana cares
* about.
*
* @param {object} response - the client response from elasticsearch
* @return {Promise} - fulfilled by mock or rejected with original error
*/
handleResponseError: function (requests, response) {
var is404 = _.get(response, 'status') === 404;
var isEmptyIndexList = _.get(response, 'body.error.index') === '[-*]';
return is404 && isEmptyIndexList
? Promise.resolve({ responses: requests.map(emptyResponse) })
: Promise.reject(response);
},
/**
* Flatten a series of requests into as ES request body
*