Skip to content

Commit

Permalink
[Index Management] Support Hidden Indices (#66422)
Browse files Browse the repository at this point in the history
* First iteration of supporting hidden indices in indices table

Tests probably have broken

* Remove unused code

* Fix logic when calling get index endpoint with empty array

Also remove unused translations

* More terse!

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
jloleysens and elasticmachine authored May 15, 2020
1 parent aff7f90 commit 2fe3e4e
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 114 deletions.
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) {
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) {
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

0 comments on commit 2fe3e4e

Please sign in to comment.