Skip to content
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

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 :)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you help me understand what this means? For clarity on my part, my original comment about rearchitecting wasn't a reference to removing Redux. It was a reference more broadly to any change to architecture which could break the the test. It was an attempt to explain the brittleness behind the test.

Copy link
Copy Markdown
Contributor Author

@sebelga sebelga Sep 27, 2021

Choose a reason for hiding this comment

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

And I went one step further. We are testing implementation detail and we don't want that. Once we rearchitect the UI this test will have to go away. Actually it should even go away (and replaced by CIT) before doing any change of architecture to be sure we don't have any regression.

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');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test makes sense for 8.0, but does it make sense for 7.16? In 7.16 wouldn't we want to assert that all dot-prefixed indices are hidden here, and revealed on lines 282-283?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's what the snapshots should give us. But you are right it is not very explicit (that's why I never use snapshots). I added a test to make it explicit (dc292d5)


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';
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In 7.x this will be 7.16.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this need to be hardcoded? I think you can read the Kibana version from core via PluginInitializerContext.env.packageInfo.version. See #85969 (comment).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with Alison. Would we have to remember to update these strings for each patch release (7.16.1, 8.0.1) and minor (8.1.0)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I started trying to inject dynamically the version with PluginInitializerContext.env.packageInfo.version. Then I realised it was going to change way too many files for very little benefit. I then weighted the pros and cons and thought it was much more surgical with less impact in the code base (less risk of regression) to have 2 hardcoded strings.

Would we have to remember to update these strings for each patch release

No we won't, the code only looks for the major version.

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