Skip to content

Commit

Permalink
[Index management] Treat indices beginning with a period as regular i…
Browse files Browse the repository at this point in the history
…ndices (#112990)
  • Loading branch information
sebelga committed Sep 28, 2021
1 parent d2eb1b0 commit e28f429
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 72 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const indexWithoutLifecyclePolicy: Index = {
primary_size: '3.4kb',
aliases: 'none',
isFrozen: false,
hidden: false,
ilm: {
index: 'testy1',
managed: false,
Expand All @@ -68,6 +69,7 @@ const indexWithLifecyclePolicy: Index = {
primary_size: '6.5kb',
aliases: 'none',
isFrozen: false,
hidden: false,
ilm: {
index: 'testy3',
managed: true,
Expand Down Expand Up @@ -95,6 +97,7 @@ const indexWithLifecycleError = {
primary_size: '6.5kb',
aliases: 'none',
isFrozen: false,
hidden: false,
ilm: {
index: 'testy3',
managed: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* 2.0.
*/

export const BRANCH = '8.x';
export const MAJOR_VERSION = '8.0.0';
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import './mocks';

export { nextTick, getRandomString, findTestSubject, TestBed } from '@kbn/test/jest';

export { setupEnvironment, WithAppDependencies, services } from './setup_environment';
export {
setupEnvironment,
WithAppDependencies,
services,
kibanaVersion,
} from './setup_environment';

export { TestSubjects } from './test_subjects';

export { BRANCH } from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import axios from 'axios';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
import { merge } from 'lodash';
import { SemVer } from 'semver';

import {
notificationServiceMock,
Expand All @@ -31,10 +32,13 @@ import {
} from '../../../public/application/components';
import { componentTemplatesMockDependencies } from '../../../public/application/components/component_templates/__jest__';
import { init as initHttpRequests } from './http_requests';
import { MAJOR_VERSION } from './constants';

const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });
const { GlobalFlyoutProvider } = GlobalFlyout;

export const kibanaVersion = new SemVer(MAJOR_VERSION);

export const services = {
extensionsService: new ExtensionsService(),
uiMetricService: new UiMetricService('index_management'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { act } from 'react-dom/test-utils';

import '../../../test/global_mocks';
import * as fixtures from '../../../test/fixtures';
import { setupEnvironment, BRANCH } from '../helpers';
import { setupEnvironment, kibanaVersion } from '../helpers';

import { TEMPLATE_NAME, SETTINGS, ALIASES, MAPPINGS as DEFAULT_MAPPING } from './constants';
import { setup } from './template_edit.helpers';
Expand Down Expand Up @@ -263,8 +263,7 @@ describe('<TemplateEdit />', () => {
});
});

// @ts-expect-error
if (BRANCH === '7.x') {
if (kibanaVersion.major < 8) {
describe('legacy index templates', () => {
const legacyTemplateToEdit = fixtures.getTemplate({
name: 'legacy_index_template',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { setUiMetricService } from '../../public/application/services/api';
import { indexManagementStore } from '../../public/application/store';
import { setExtensionsService } from '../../public/application/store/selectors/extension_service';
import { ExtensionsService } from '../../public/services';
import { kibanaVersion } from '../client_integration/helpers';

/* eslint-disable @kbn/eslint/no-restricted-paths */
import { notificationServiceMock } from '../../../../../src/core/public/notifications/notifications_service.mock';
Expand All @@ -43,24 +44,30 @@ let server = null;
let store = null;
const indices = [];

for (let i = 0; i < 105; i++) {
const baseFake = {
health: i % 2 === 0 ? 'green' : 'yellow',
status: i % 2 === 0 ? 'open' : 'closed',
const getBaseFakeIndex = (isOpen) => {
return {
health: isOpen ? 'green' : 'yellow',
status: isOpen ? 'open' : 'closed',
primary: 1,
replica: 1,
documents: 10000,
documents_deleted: 100,
size: '156kb',
primary_size: '156kb',
};
};

for (let i = 0; i < 105; i++) {
indices.push({
...baseFake,
...getBaseFakeIndex(true),
name: `testy${i}`,
});
indices.push({
...baseFake,
...getBaseFakeIndex(false),
name: `.admin${i}`,
// Add 2 hidden indices in the list in position 3 & 7
// note: for each loop iteration we add 2 indices
hidden: i === 1 || i === 3 ? true : false, // ".admin1" and ".admin3" are the only hidden in 8.x
});
}

Expand Down Expand Up @@ -110,6 +117,7 @@ const testAction = (rendered, buttonIndex, rowIndex = 0) => {
// so we "time" our assertion based on how many Redux actions we observe. This is brittle because it
// depends upon how our UI is architected, which will affect how many actions are dispatched.
// Expect this to break when we rearchitect the UI.
// Update: Expect this to be removed when we rearchitect the UI :)
let dispatchedActionsCount = 0;
store.subscribe(() => {
if (dispatchedActionsCount === 1) {
Expand Down Expand Up @@ -254,15 +262,44 @@ describe('index table', () => {
expect(button.text()).toEqual('Manage 2 indices');
});

test('should show system indices only when the switch is turned on', async () => {
test('should show hidden indices only when the switch is turned on', async () => {
const rendered = mountWithIntl(component);
await runAllPromises();
rendered.update();

snapshot(rendered.find('.euiPagination li').map((item) => item.text()));
const switchControl = rendered.find('.euiSwitch__button');
// We have manually set `.admin1` and `.admin3` as hidden indices
// We **don't** expect them to be in this list as by default we don't show hidden indices
let indicesInTable = namesText(rendered);
expect(indicesInTable).not.toContain('.admin1');
expect(indicesInTable).not.toContain('.admin3');

if (kibanaVersion.major >= 8) {
// From 8.x indices starting with a period are treated as normal indices
expect(indicesInTable).toContain('.admin0');
expect(indicesInTable).toContain('.admin2');
} else if (kibanaVersion.major < 8) {
// In 7.x those are treated as system and are thus hidden
expect(indicesInTable).not.toContain('.admin0');
expect(indicesInTable).not.toContain('.admin2');
}

snapshot(indicesInTable);

// Enable "Show hidden indices"
const switchControl = findTestSubject(rendered, 'indexTableIncludeHiddenIndicesToggle');
switchControl.simulate('click');
snapshot(rendered.find('.euiPagination li').map((item) => item.text()));

// We do expect now the `.admin1` and `.admin3` indices to be in the list
indicesInTable = namesText(rendered);
expect(indicesInTable).toContain('.admin1');
expect(indicesInTable).toContain('.admin3');

if (kibanaVersion.major < 8) {
expect(indicesInTable).toContain('.admin0');
expect(indicesInTable).toContain('.admin2');
}

snapshot(indicesInTable);
});

test('should filter based on content of search input', async () => {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/index_management/common/types/indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ export interface Index {
uuid: string;
primary: string;
replica: string;
documents: any;
documents?: string;
size: any;
isFrozen: boolean;
hidden: boolean;
aliases: string | string[];
data_stream?: string;
[key: string]: any;
Expand Down
27 changes: 27 additions & 0 deletions x-pack/plugins/index_management/public/application/lib/indices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import SemVer from 'semver/classes/semver';
import { Index } from '../../../common';

const version = '8.0.0';
const kibanaVersion = new SemVer(version);

export const isHiddenIndex = (index: Index): boolean => {
if (kibanaVersion.major < 8) {
// In 7.x we consider hidden index all indices whose name start with a dot
return (index.name ?? '').startsWith('.') || index.hidden === true;
}
return index.hidden === true;
};

export const isSystemIndex = (index: Index): boolean => {
if (kibanaVersion.major < 8) {
return (index.name ?? '').startsWith('.');
}
// From 8.0 we won't surface system indices in Index management
return false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
const mapStateToProps = (state, ownProps) => {
const indexStatusByName = {};
const { indexNames } = ownProps;
const allIndices = state.indices.byId;

indexNames.forEach((indexName) => {
indexStatusByName[indexName] = getIndexStatusByIndexName(state, indexName);
Expand All @@ -42,8 +43,8 @@ const mapStateToProps = (state, ownProps) => {
return {
indexStatusByName,
indices: getIndicesByName(state, indexNames),
isSystemIndexByName: getIsSystemIndexByName(indexNames),
hasSystemIndex: hasSystemIndex(indexNames),
isSystemIndexByName: getIsSystemIndexByName(indexNames, allIndices),
hasSystemIndex: hasSystemIndex(indexNames, allIndices),
};
};

Expand Down
Loading

0 comments on commit e28f429

Please sign in to comment.