use ecs properties in fetch_index_shard_size

This commit is contained in:
klacabane 2022-02-15 19:16:33 +01:00 committed by Jason Rhodes
parent 63759503b4
commit cdf8b2493e
2 changed files with 11 additions and 4 deletions

View file

@ -186,6 +186,7 @@ describe('fetchIndexShardSize', () => {
'_index',
'index_stats.shards.primaries',
'index_stats.primaries.store.size_in_bytes',
'elasticsearch.index.shards.primaries',
'elasticsearch.index.primaries.store.size_in_bytes',
],
},

View file

@ -90,6 +90,7 @@ export async function fetchIndexShardSize(
'_index',
'index_stats.shards.primaries',
'index_stats.primaries.store.size_in_bytes',
'elasticsearch.index.shards.primaries',
'elasticsearch.index.primaries.store.size_in_bytes',
],
},
@ -134,15 +135,20 @@ export async function fetchIndexShardSize(
}
const {
_index: monitoringIndexName,
_source: { index_stats: indexStats },
_source: { index_stats: indexStats, elasticsearch },
} = topHit;
if (!indexStats || !indexStats.primaries) {
const isLegacy = !!(indexStats && indexStats.primaries);
const isMb = !!(elasticsearch && elasticsearch.index);
if (!isLegacy && !isMb) {
continue;
}
const { primaries: totalPrimaryShards } = indexStats.shards;
const { size_in_bytes: primaryShardSizeBytes = 0 } = indexStats.primaries.store || {};
const { primaries: totalPrimaryShards } =
indexStats?.shards || elasticsearch?.index?.shards || {};
const { size_in_bytes: primaryShardSizeBytes = 0 } =
indexStats?.primaries?.store || elasticsearch?.index?.primaries?.store || {};
if (!primaryShardSizeBytes || !totalPrimaryShards) {
continue;
}