Skip to content

Commit

Permalink
[Index Management] Filter system indices from cat API request (elasti…
Browse files Browse the repository at this point in the history
…c#104155)

* refactor indices test and unskip
  • Loading branch information
alisonelizabeth authored and madirey committed Jul 6, 2021
1 parent 8d33934 commit ae9a2c0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
43 changes: 25 additions & 18 deletions x-pack/plugins/index_management/server/lib/fetch_indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,33 @@ async function fetchIndicesCall(
query: catQuery,
});

// The two responses should be equal in the number of indices returned
return catHits.map((hit) => {
// 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)
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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
});
});
Expand Down

0 comments on commit ae9a2c0

Please sign in to comment.