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

[Index Management] Support Hidden Indices #66422

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getPager,
getFilter,
isDetailPanelOpen,
showSystemIndices,
showHiddenIndices,
getSortField,
isSortAscending,
getIndicesAsArray,
Expand All @@ -26,7 +26,7 @@ import {
pageChanged,
pageSizeChanged,
sortChanged,
showSystemIndicesChanged,
showHiddenIndicesChanged,
loadIndices,
reloadIndices,
toggleChanged,
Expand All @@ -42,7 +42,7 @@ const mapStateToProps = state => {
indices: getPageOfIndices(state),
pager: getPager(state),
filter: getFilter(state),
showSystemIndices: showSystemIndices(state),
showHiddenIndices: showHiddenIndices(state),
sortField: getSortField(state),
isSortAscending: isSortAscending(state),
indicesLoading: indicesLoading(state),
Expand All @@ -65,8 +65,8 @@ const mapDispatchToProps = dispatch => {
sortChanged: (sortField, isSortAscending) => {
dispatch(sortChanged({ sortField, isSortAscending }));
},
showSystemIndicesChanged: showSystemIndices => {
dispatch(showSystemIndicesChanged({ showSystemIndices }));
showHiddenIndicesChanged: showHiddenIndices => {
dispatch(showHiddenIndicesChanged({ showHiddenIndices }));
},
toggleChanged: (toggleName, toggleValue) => {
dispatch(toggleChanged({ toggleName, toggleValue }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ export class IndexTable extends Component {
render() {
const {
filter,
showSystemIndices,
showSystemIndicesChanged,
showHiddenIndices,
showHiddenIndicesChanged,
indices,
loadIndices,
indicesLoading,
Expand Down Expand Up @@ -459,13 +459,13 @@ export class IndexTable extends Component {
})}
<EuiFlexItem grow={false}>
<EuiSwitch
id="checkboxShowSystemIndices"
checked={showSystemIndices}
onChange={event => showSystemIndicesChanged(event.target.checked)}
id="checkboxShowHiddenIndices"
checked={showHiddenIndices}
onChange={event => showHiddenIndicesChanged(event.target.checked)}
label={
<FormattedMessage
id="xpack.idxMgmt.indexTable.systemIndicesSwitchLabel"
defaultMessage="Include system indices"
id="xpack.idxMgmt.indexTable.hiddenIndicesSwitchLabel"
defaultMessage="Include hidden indices"
/>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const pageSizeChanged = createAction('INDEX_MANAGEMENT_PAGE_SIZE_CHANGED'

export const sortChanged = createAction('INDEX_MANAGEMENT_SORT_CHANGED');

export const showSystemIndicesChanged = createAction(
'INDEX_MANAGEMENT_SHOW_SYSTEM_INDICES_CHANGED'
export const showHiddenIndicesChanged = createAction(
'INDEX_MANAGEMENT_SHOW_HIDDEN_INDICES_CHANGED'
);

export const toggleChanged = createAction('INDEX_MANAGEMENT_TOGGLE_CHANGED');
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
pageChanged,
pageSizeChanged,
sortChanged,
showSystemIndicesChanged,
showHiddenIndicesChanged,
toggleChanged,
} from '../actions';

Expand All @@ -20,7 +20,7 @@ export const defaultTableState = {
currentPage: 0,
sortField: 'index.name',
isSortAscending: true,
showSystemIndices: false,
showHiddenIndices: false,
};

export const tableState = handleActions(
Expand All @@ -33,12 +33,12 @@ export const tableState = handleActions(
currentPage: 0,
};
},
[showSystemIndicesChanged](state, action) {
const { showSystemIndices } = action.payload;
[showHiddenIndicesChanged](state, action) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also feel like you're reading the docs? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 quite!

const { showHiddenIndices } = action.payload;

return {
...state,
showSystemIndices,
showHiddenIndices,
};
},
[toggleChanged](state, action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ const getFilteredIndices = createSelector(
(indices, allIds, tableState) => {
let indexArray = allIds.map(indexName => indices[indexName]);
indexArray = filterByToggles(indexArray, tableState.toggleNameToVisibleMap);
const systemFilteredIndexes = tableState.showSystemIndices
const systemFilteredIndexes = tableState.showHiddenIndices
? indexArray
: indexArray.filter(index => !(index.name + '').startsWith('.'));
: indexArray.filter(index => !(index.name + '').startsWith('.') && !index.hidden);
const filter = tableState.filter || EuiSearchBar.Query.MATCH_ALL;
return EuiSearchBar.Query.execute(filter, systemFilteredIndexes, {
defaultFields: defaultFilterFields,
Expand Down Expand Up @@ -151,9 +151,9 @@ export const getCurrentPage = createSelector(getPager, pager => {

export const getFilter = createSelector(getTableState, ({ filter }) => filter);

export const showSystemIndices = createSelector(
export const showHiddenIndices = createSelector(
getTableState,
({ showSystemIndices }) => showSystemIndices
({ showHiddenIndices }) => showHiddenIndices
);

export const isSortAscending = createSelector(
Expand Down
46 changes: 0 additions & 46 deletions x-pack/plugins/index_management/server/lib/fetch_aliases.test.ts

This file was deleted.

16 changes: 0 additions & 16 deletions x-pack/plugins/index_management/server/lib/fetch_aliases.ts

This file was deleted.

83 changes: 56 additions & 27 deletions x-pack/plugins/index_management/server/lib/fetch_indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { CatIndicesParams } from 'elasticsearch';
import { IndexDataEnricher } from '../services';
import { Index, CallAsCurrentUser } from '../types';
import { fetchAliases } from './fetch_aliases';

interface Hit {
health: string;
Expand All @@ -17,20 +17,64 @@ interface Hit {
'docs.count': any;
'store.size': any;
sth: 'true' | 'false';
hidden: boolean;
}

interface Aliases {
[key: string]: string[];
interface IndexInfo {
aliases: { [aliasName: string]: unknown };
mappings: unknown;
settings: {
index: {
hidden: 'true' | 'false';
};
};
}

interface Params {
format: string;
h: string;
index?: string[];
interface GetIndicesResponse {
[indexName: string]: IndexInfo;
}

function formatHits(hits: Hit[], aliases: Aliases): Index[] {
return hits.map((hit: Hit) => {
async function fetchIndicesCall(
callAsCurrentUser: CallAsCurrentUser,
indexNames?: string[]
): Promise<Index[]> {
const indexNamesString = indexNames && indexNames.length ? indexNames.join(',') : '*';

// This call retrieves alias and settings (incl. hidden status) information about indices
const indices: GetIndicesResponse = await callAsCurrentUser('transport.request', {
method: 'GET',
path: `/${indexNamesString}`,
query: {
expand_wildcards: 'hidden,all',
},
});

if (!Object.keys(indices).length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we know that the GET /<indices> is slower than the _cat/indices, we might better then fetch first the cat indices and exit early from there. WDYT?

Copy link
Contributor Author

@jloleysens jloleysens May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spoke to @danhermann about this, he mentioned that both _cat/indices and /<indices> would suffer a performance hit on clusters with many indices + shards but that there is a new endpoint that will support this being built #64858 we can use that will be released soon. We can review after it is available - perhaps we will need to remove some values we have in the table at the moment.

return [];
}

const catQuery: Pick<CatIndicesParams, 'format' | 'h'> & {
expand_wildcards: string;
index?: string;
} = {
format: 'json',
h: 'health,status,index,uuid,pri,rep,docs.count,sth,store.size',
expand_wildcards: 'hidden,all',
index: indexNamesString,
};

// This call retrieves health and other high-level information about indices.
const catHits: Hit[] = await callAsCurrentUser('transport.request', {
method: 'GET',
path: '/_cat/indices',
query: catQuery,
});

// The two responses should be equal in the number of indices returned
return catHits.map(hit => {
const index = indices[hit.index];
const aliases = Object.keys(index.aliases);

return {
health: hit.health,
status: hit.status,
Expand All @@ -41,32 +85,17 @@ function formatHits(hits: Hit[], aliases: Aliases): Index[] {
documents: hit['docs.count'],
size: hit['store.size'],
isFrozen: hit.sth === 'true', // sth value coming back as a string from ES
aliases: aliases.hasOwnProperty(hit.index) ? aliases[hit.index] : 'none',
aliases: aliases.length ? aliases : 'none',
hidden: index.settings.index.hidden === 'true',
};
});
}

async function fetchIndicesCall(callAsCurrentUser: CallAsCurrentUser, indexNames?: string[]) {
const params: Params = {
format: 'json',
h: 'health,status,index,uuid,pri,rep,docs.count,sth,store.size',
};

if (indexNames) {
params.index = indexNames;
}

return await callAsCurrentUser('cat.indices', params);
}

export const fetchIndices = async (
callAsCurrentUser: CallAsCurrentUser,
indexDataEnricher: IndexDataEnricher,
indexNames?: string[]
) => {
const aliases = await fetchAliases(callAsCurrentUser);
const hits = await fetchIndicesCall(callAsCurrentUser, indexNames);
const indices = formatHits(hits, aliases);

const indices = await fetchIndicesCall(callAsCurrentUser, indexNames);
return await indexDataEnricher.enrichIndices(indices, callAsCurrentUser);
};
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -6736,7 +6736,6 @@
"xpack.idxMgmt.indexTable.serverErrorTitle": "インデックスの読み込み中にエラーが発生",
"xpack.idxMgmt.indexTable.systemIndicesSearchIndicesAriaLabel": "インデックスの検索",
"xpack.idxMgmt.indexTable.systemIndicesSearchInputPlaceholder": "検索",
"xpack.idxMgmt.indexTable.systemIndicesSwitchLabel": "システムインデックスを含める",
"xpack.idxMgmt.indexTemplatesList.emptyPrompt.noIndexTemplatesTitle": "まだテンプレートがありません",
"xpack.idxMgmt.indexTemplatesList.loadingIndexTemplatesDescription": "テンプレートを読み込み中…",
"xpack.idxMgmt.indexTemplatesList.loadingIndexTemplatesErrorMessage": "テンプレートの読み込み中にエラーが発生",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -6741,7 +6741,6 @@
"xpack.idxMgmt.indexTable.serverErrorTitle": "加载索引时出错",
"xpack.idxMgmt.indexTable.systemIndicesSearchIndicesAriaLabel": "搜索索引",
"xpack.idxMgmt.indexTable.systemIndicesSearchInputPlaceholder": "搜索",
"xpack.idxMgmt.indexTable.systemIndicesSwitchLabel": "包括系统索引",
"xpack.idxMgmt.indexTemplatesList.emptyPrompt.noIndexTemplatesTitle": "您尚未有任何模板",
"xpack.idxMgmt.indexTemplatesList.loadingIndexTemplatesDescription": "正在加载模板……",
"xpack.idxMgmt.indexTemplatesList.loadingIndexTemplatesErrorMessage": "加载模板时出错",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export default function({ getService }) {
const { body } = await list().expect(200);
const expectedKeys = [
'health',
'hidden',
'status',
'name',
'uuid',
Expand Down Expand Up @@ -214,6 +215,7 @@ export default function({ getService }) {
const { body } = await reload().expect(200);
const expectedKeys = [
'health',
'hidden',
'status',
'name',
'uuid',
Expand Down