From b4d1c1838186e16bd413a170bc9e9073d82fa64c Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Thu, 1 Jul 2021 13:09:37 -0400 Subject: [PATCH 1/4] filter system indices from cat API request --- .../plugins/index_management/server/lib/fetch_indices.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/index_management/server/lib/fetch_indices.ts b/x-pack/plugins/index_management/server/lib/fetch_indices.ts index a6f499ede9038..4e4c92f06c5aa 100644 --- a/x-pack/plugins/index_management/server/lib/fetch_indices.ts +++ b/x-pack/plugins/index_management/server/lib/fetch_indices.ts @@ -76,8 +76,13 @@ async function fetchIndicesCall( query: catQuery, }); + // System indices may show up in _cat APIs, as these APIs are primarily used for troubleshooting + // For now, we filter them out and only return index information for the indices we have + // In the future, we should migrate away from using cat APIs (https://github.com/elastic/kibana/issues/57286) + const filteredCatHits = catHits.filter((hit) => typeof indices[hit.index] !== 'undefined'); + // The two responses should be equal in the number of indices returned - return catHits.map((hit) => { + return filteredCatHits.map((hit) => { const index = indices[hit.index]; const aliases = Object.keys(index.aliases); From bd58d40a8973498d9088ef2327abe7e3f9c2711a Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Thu, 1 Jul 2021 14:20:20 -0400 Subject: [PATCH 2/4] refactor indices test and unskip --- .../apis/management/index_management/indices.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/x-pack/test/api_integration/apis/management/index_management/indices.js b/x-pack/test/api_integration/apis/management/index_management/indices.js index d0e17476530b7..25b1ef97d3087 100644 --- a/x-pack/test/api_integration/apis/management/index_management/indices.js +++ b/x-pack/test/api_integration/apis/management/index_management/indices.js @@ -177,12 +177,19 @@ export default function ({ getService }) { }); }); - // FLAKY: https://github.com/elastic/kibana/issues/64473 - describe.skip('list', function () { + describe('list', function () { this.tags(['skipCloud']); it('should list all the indices with the expected properties and data enrichers', async function () { - const { body } = await list().expect(200); + // Create an index that we can assert against + await createIndex('test_index'); + + // Verify indices request + const { body: indices } = await list().expect(200); + + // Find the "test_index" created to verify expected keys + const indexCreated = indices.find((index) => index.name === 'test_index'); + const expectedKeys = [ 'health', 'hidden', @@ -203,7 +210,8 @@ export default function ({ getService }) { // We need to sort the keys before comparing then, because race conditions // can cause enrichers to register in non-deterministic order. const sortedExpectedKeys = expectedKeys.sort(); - const sortedReceivedKeys = Object.keys(body[0]).sort(); + const sortedReceivedKeys = Object.keys(indexCreated).sort(); + expect(sortedReceivedKeys).to.eql(sortedExpectedKeys); }); }); From a646d2af6b43df96ec79960a21b05d6905eb91ae Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Thu, 1 Jul 2021 14:45:46 -0400 Subject: [PATCH 3/4] remove old comment --- x-pack/plugins/index_management/server/lib/fetch_indices.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/index_management/server/lib/fetch_indices.ts b/x-pack/plugins/index_management/server/lib/fetch_indices.ts index 4e4c92f06c5aa..111e9b95287d8 100644 --- a/x-pack/plugins/index_management/server/lib/fetch_indices.ts +++ b/x-pack/plugins/index_management/server/lib/fetch_indices.ts @@ -81,7 +81,6 @@ async function fetchIndicesCall( // In the future, we should migrate away from using cat APIs (https://github.com/elastic/kibana/issues/57286) const filteredCatHits = catHits.filter((hit) => typeof indices[hit.index] !== 'undefined'); - // The two responses should be equal in the number of indices returned return filteredCatHits.map((hit) => { const index = indices[hit.index]; const aliases = Object.keys(index.aliases); From 3681f571b57b3c5379a52d121e3e64b1aee81070 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Thu, 1 Jul 2021 16:04:07 -0700 Subject: [PATCH 4/4] Use reduce to retain original number of loops and vars. --- .../server/lib/fetch_indices.ts | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/index_management/server/lib/fetch_indices.ts b/x-pack/plugins/index_management/server/lib/fetch_indices.ts index 111e9b95287d8..b83843f0c615d 100644 --- a/x-pack/plugins/index_management/server/lib/fetch_indices.ts +++ b/x-pack/plugins/index_management/server/lib/fetch_indices.ts @@ -79,27 +79,30 @@ async function fetchIndicesCall( // System indices may show up in _cat APIs, as these APIs are primarily used for troubleshooting // For now, we filter them out and only return index information for the indices we have // In the future, we should migrate away from using cat APIs (https://github.com/elastic/kibana/issues/57286) - const filteredCatHits = catHits.filter((hit) => typeof indices[hit.index] !== 'undefined'); - - return filteredCatHits.map((hit) => { + return catHits.reduce((decoratedIndices, hit) => { const index = indices[hit.index]; - const aliases = Object.keys(index.aliases); - return { - health: hit.health, - status: hit.status, - name: hit.index, - uuid: hit.uuid, - primary: hit.pri, - replica: hit.rep, - documents: hit['docs.count'], - size: hit['store.size'], - isFrozen: hit.sth === 'true', // sth value coming back as a string from ES - aliases: aliases.length ? aliases : 'none', - hidden: index.settings.index.hidden === 'true', - data_stream: index.data_stream, - }; - }); + if (typeof index !== 'undefined') { + const aliases = Object.keys(index.aliases); + + decoratedIndices.push({ + health: hit.health, + status: hit.status, + name: hit.index, + uuid: hit.uuid, + primary: hit.pri, + replica: hit.rep, + documents: hit['docs.count'], + size: hit['store.size'], + isFrozen: hit.sth === 'true', // sth value coming back as a string from ES + aliases: aliases.length ? aliases : 'none', + hidden: index.settings.index.hidden === 'true', + data_stream: index.data_stream, + }); + } + + return decoratedIndices; + }, [] as Index[]); } export const fetchIndices = async (