Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spy #2514

Merged
merged 2 commits into from
Jan 5, 2015
Merged

Fix spy #2514

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/kibana/components/courier/fetch/_call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ define(function (require) {

// Now that all of THAT^^^ is out of the way, lets actually
// call out to elasticsearch
Promise.resolve(strategy.convertReqsToBody(executable))
Promise.map(executable, function (req) {
return Promise.try(req.getFetchParams, void 0, req)
.then(function (fetchParams) {
return (req.fetchParams = fetchParams);
});
})
.then(function (reqsFetchParams) {
return strategy.reqsFetchParamsToBody(reqsFetchParams);
})
.then(function (body) {
// while the strategy was converting, our request was aborted
if (esPromise === ABORTED) {
Expand Down
3 changes: 2 additions & 1 deletion src/kibana/components/courier/fetch/request/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ define(function (require) {
}

if (source.history) {
source.history = _.first(source.history.concat(this), 20);
source.history.push(this);
source.history = _.last(source.history, 20);
}
};

Expand Down
13 changes: 4 additions & 9 deletions src/kibana/components/courier/fetch/strategy/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ define(function (require) {
* @param {array} requests - an array of flattened requests
* @return {string} - the request body
*/
convertReqsToBody: function (reqs) {
return Promise.map(reqs, function (req) {
return req.getFetchParams();
})
.then(function (reqsParams) {
return {
docs: reqsParams
};
});
reqsFetchParamsToBody: function (reqsFetchParams) {
return {
docs: reqsFetchParams
};
},

/**
Expand Down
36 changes: 15 additions & 21 deletions src/kibana/components/courier/fetch/strategy/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,23 @@ define(function (require) {
* @param {array} requests - the requests to serialize
* @return {string} - the request body
*/
convertReqsToBody: function (reqs) {
return Promise.map(reqs, function (req) {
return req.getFetchParams();
})
.then(function (reqsParams) {
return reqsParams.map(function (reqParams) {
var indexList = reqParams.index;
reqsFetchParamsToBody: function (reqsFetchParams) {
return reqsFetchParams.map(function (fetchParams) {
var indexList = fetchParams.index;

if (_.isFunction(_.deepGet(indexList, 'toIndexList'))) {
var timeBounds = timefilter.getBounds();
indexList = indexList.toIndexList(timeBounds.min, timeBounds.max);
}
if (_.isFunction(_.deepGet(indexList, 'toIndexList'))) {
var timeBounds = timefilter.getBounds();
indexList = indexList.toIndexList(timeBounds.min, timeBounds.max);
}

return JSON.stringify({
index: indexList,
type: reqParams.type,
ignore_unavailable: true
})
+ '\n'
+ JSON.stringify(reqParams.body || {});

}).join('\n') + '\n';
});
return JSON.stringify({
index: indexList,
type: fetchParams.type,
ignore_unavailable: true
})
+ '\n'
+ JSON.stringify(fetchParams.body || {});
}).join('\n') + '\n';
},

/**
Expand Down
24 changes: 10 additions & 14 deletions src/kibana/components/visualize/spy/_req_resp_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,25 @@ define(function (require) {

if (!$scope.searchSource) return;

var searchHistory = $scope.searchSource.history;
if (!searchHistory) return;
var req = $scope.entry = _.last(_.deepGet($scope, 'searchSource.history'));
if (!req) return;

var entry = $scope.entry = _.find(searchHistory, 'state');
if (!entry) return;

var state = entry.state;
var resp = entry.resp;
var resp = req.resp;
var meta = [];

if (resp && resp.took != null) meta.push(['Query Duration', resp.took + 'ms']);
if (entry && entry.ms != null) meta.push(['Request Duration', entry.ms + 'ms']);
if (req && req.ms != null) meta.push(['Request Duration', req.ms + 'ms']);
if (resp && resp.hits) meta.push(['Hits', resp.hits.total]);

if (state.index) meta.push(['Index', state.index]);
if (state.type) meta.push(['Type', state.type]);
if (state.id) meta.push(['Id', state.id]);
if (req.fetchParams.index) meta.push(['Index', req.fetchParams.index]);
if (req.fetchParams.type) meta.push(['Type', req.fetchParams.type]);
if (req.fetchParams.id) meta.push(['Id', req.fetchParams.id]);

$scope.history = {
meta: meta,
req: state.body,
resp: entry.resp,
complete: entry.complete
req: req.fetchParams.body,
resp: req.resp,
complete: req.complete
};
});
};
Expand Down