[Monitoring] Get ready for hits total format change (#26442)

* Update the specific places we care about hits.total

* PR feedback

* Fix test
This commit is contained in:
Chris Roberson 2019-01-22 12:35:26 -05:00 committed by GitHub
parent c91ec0d1ef
commit c37cf1eab2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 7 deletions

View file

@ -11,7 +11,6 @@ describe('get_last_recovery', () => {
// Note: times are from the epoch!
const resp = {
hits: {
total: 1, // We expect either 0 or 1; never more.
hits: [
{
_source: {
@ -48,7 +47,7 @@ describe('get_last_recovery', () => {
it('No hits results in an empty array', () => {
// Note: we don't expect it to touch hits without total === 1
expect(handleLastRecoveries({ hits: { total: 0 } }, new Date(0))).to.have.length(0);
expect(handleLastRecoveries({ hits: { hits: [] } }, new Date(0))).to.have.length(0);
});
it('Filters on stop time', () => {

View file

@ -36,7 +36,7 @@ export function filterOldShardActivity(startMs) {
* @returns {Object[]} An array of shards representing active shard activity from {@code _source.index_recovery.shards}.
*/
export function handleLastRecoveries(resp, start) {
if (resp.hits.total >= 1) {
if (resp.hits.hits.length === 1) {
const data = _.get(resp.hits.hits[0], '_source.index_recovery.shards', []).filter(filterOldShardActivity(start.getTime()));
data.sort((a, b) => b.start_time_in_millis - a.start_time_in_millis);
return data;

View file

@ -78,7 +78,6 @@ export async function getNodes(req, esIndexPattern, clusterStats, shardStats) {
sort: [ { timestamp: { order: 'desc' } } ]
},
filterPath: [
'hits.total',
'hits.hits._source.source_node',
'aggregations.nodes.buckets.key',
...LISTING_METRICS_PATHS,

View file

@ -18,7 +18,7 @@ import { LISTING_METRICS_NAMES } from './nodes_listing_metrics';
* @return {Array} node info combined with metrics for each node
*/
export function handleResponse(response, clusterStats, shardStats, timeOptions = {}) {
if (!get(response, 'hits.total')) {
if (!get(response, 'hits.hits')) {
return [];
}

View file

@ -17,8 +17,9 @@ export function handleResponse(resp, includeNodes, includeIndices, cluster) {
let indicesTotals;
let nodes;
if (resp && resp.hits && resp.hits.total !== 0) {
indices = resp.aggregations.indices.buckets.reduce(normalizeIndexShards, {});
const buckets = get(resp, 'aggregations.indices.buckets');
if (buckets && buckets.length !== 0) {
indices = buckets.reduce(normalizeIndexShards, {});
indicesTotals = calculateIndicesTotals(indices);
if (includeNodes) {