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

[Upgrade Assistant] Add upgrade system indices section #110593

Merged
merged 34 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
74c09f8
Add skeleton for new step section
sabarasaba Aug 31, 2021
f40561c
wip: initial flyout and memory table
sabarasaba Sep 1, 2021
fdcb2f0
Mock data server side and add fetching strategy to ui
sabarasaba Sep 1, 2021
21719c2
Enhance types and conditionally render ctas
sabarasaba Sep 1, 2021
b04c2ef
Finish up tyding up UI states
sabarasaba Sep 2, 2021
3ee1713
Fix hardcoded translations
sabarasaba Sep 2, 2021
3b1f657
Start working on mock for post method
sabarasaba Sep 2, 2021
825d93a
Fix ts erros
sabarasaba Sep 2, 2021
190780b
Apply new UI states
sabarasaba Sep 3, 2021
910cd5c
Extract all hooks into a custom one
sabarasaba Sep 3, 2021
aa64c40
Add tests
sabarasaba Sep 3, 2021
f05c7b4
Merge branch '7.x' into ua/system_indices_upgrade
sabarasaba Oct 4, 2021
45c648e
Merge branch '7.x' into ua/system_indices_upgrade
sabarasaba Oct 5, 2021
91feb78
Fix linter issues
sabarasaba Oct 4, 2021
8fd00da
Replace server side api routes with real ES calls
sabarasaba Oct 5, 2021
b3e70dc
Mark step as completed when no upgrade is needed
sabarasaba Oct 5, 2021
2d422c4
Add tests for server routes
sabarasaba Oct 5, 2021
811c93c
Add tests for step completion flow
sabarasaba Oct 5, 2021
b145383
Refactor existing tests
sabarasaba Oct 5, 2021
9bf7378
Replace hardcoded docs link
sabarasaba Oct 5, 2021
e20fcd3
Add missing tests for flyout
sabarasaba Oct 5, 2021
c98f5ad
Address changes from draft review
sabarasaba Oct 5, 2021
088eec2
Deal with completed features in flyout
sabarasaba Oct 5, 2021
520ea0c
Fix polling mechanism to only kick in after migration starts
sabarasaba Oct 5, 2021
7187022
Fix hardcoded copy
sabarasaba Oct 5, 2021
8aa178a
Address CR changes
sabarasaba Oct 6, 2021
e8379fe
Address feedback from copy review
sabarasaba Oct 6, 2021
bb07f52
Rename files and variables to use migration nomenclature instead of
sabarasaba Oct 6, 2021
e06d7cb
Replace harcoded majorVersion
sabarasaba Oct 6, 2021
7b43613
Remove docs link
sabarasaba Oct 7, 2021
d564445
Merge branch '7.x' into ua/system_indices_upgrade
kibanamachine Oct 7, 2021
eaa8126
Merge branch '7.x' into ua/system_indices_upgrade
kibanamachine Oct 7, 2021
781d9f0
Add missing types
sabarasaba Oct 12, 2021
95c4e12
Merge branch '7.x' into ua/system_indices_upgrade
sabarasaba Oct 12, 2021
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 @@ -158,6 +158,17 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
]);
};

const setLoadSystemIndicesMigrationStatus = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;

server.respondWith('GET', `${API_BASE_PATH}/system_indices_migration`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};

const setLoadMlUpgradeModeResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;
Expand All @@ -169,6 +180,17 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
]);
};

const setSystemIndicesMigrationResponse = (response?: object, error?: ResponseError) => {
const status = error ? error.statusCode || 400 : 200;
const body = error ? error : response;

server.respondWith('POST', `${API_BASE_PATH}/system_indices_migration`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
]);
};

return {
setLoadCloudBackupStatusResponse,
setLoadEsDeprecationsResponse,
Expand All @@ -179,6 +201,8 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
setDeleteMlSnapshotResponse,
setUpgradeMlSnapshotStatusResponse,
setLoadDeprecationLogsCountResponse,
setLoadSystemIndicesMigrationStatus,
setSystemIndicesMigrationResponse,
setDeleteLogsCacheResponse,
setStartReindexingResponse,
setReindexStatusResponse,
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
@@ -0,0 +1,42 @@
/*
* 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 { act } from 'react-dom/test-utils';

import { OverviewTestBed, setupOverviewPage } from '../overview.helpers';
import { setupEnvironment } from '../../helpers';
import { systemIndicesMigrationStatus } from './mocks';

describe('Overview - Migrate system indices - Flyout', () => {
let testBed: OverviewTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();

beforeEach(async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus(systemIndicesMigrationStatus);

await act(async () => {
testBed = await setupOverviewPage();
});

testBed.component.update();
});

afterAll(() => {
server.restore();
});

test('shows correct features in flyout table', async () => {
const { actions, table } = testBed;

await actions.clickViewSystemIndicesState();

const { tableCellsValues } = table.getMetaData('flyoutDetails');

expect(tableCellsValues.length).toBe(systemIndicesMigrationStatus.features.length);
expect(tableCellsValues).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* 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 { act } from 'react-dom/test-utils';

import { setupEnvironment } from '../../helpers';
import { OverviewTestBed, setupOverviewPage } from '../overview.helpers';

describe('Overview - Migrate system indices', () => {
let testBed: OverviewTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();

beforeEach(async () => {
testBed = await setupOverviewPage();
testBed.component.update();
});

afterAll(() => {
server.restore();
});

describe('Error state', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus(undefined, {
statusCode: 400,
message: 'error',
});

testBed = await setupOverviewPage();
});

test('Is rendered', () => {
const { exists, component } = testBed;
component.update();

expect(exists('systemIndicesStatusErrorCallout')).toBe(true);
});

test('Lets the user attempt to reload migration status', async () => {
const { exists, component, actions } = testBed;
component.update();

httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
upgrade_status: 'NO_UPGRADE_NEEDED',
});

await actions.clickRetrySystemIndicesButton();

expect(exists('noMigrationNeededSection')).toBe(true);
});
});

test('No migration needed', async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
upgrade_status: 'NO_UPGRADE_NEEDED',
});

testBed = await setupOverviewPage();

const { exists, component } = testBed;

component.update();

expect(exists('noMigrationNeededSection')).toBe(true);
expect(exists('startSystemIndicesMigrationButton')).toBe(false);
expect(exists('viewSystemIndicesStateButton')).toBe(false);
});

test('Migration in progress', async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
upgrade_status: 'IN_PROGRESS',
});

testBed = await setupOverviewPage();

const { exists, component, find } = testBed;

component.update();

// Start migration is disabled
expect(exists('startSystemIndicesMigrationButton')).toBe(true);
expect(find('startSystemIndicesMigrationButton').props().disabled).toBe(true);
// But we keep view system indices CTA
expect(exists('viewSystemIndicesStateButton')).toBe(true);
});

describe('Migration needed', () => {
test('Initial state', async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
upgrade_status: 'UPGRADE_NEEDED',
});

testBed = await setupOverviewPage();

const { exists, component, find } = testBed;

component.update();

// Start migration should be enabled
expect(exists('startSystemIndicesMigrationButton')).toBe(true);
expect(find('startSystemIndicesMigrationButton').props().disabled).toBe(false);
// Same for view system indices status
expect(exists('viewSystemIndicesStateButton')).toBe(true);
});

test('Handles errors when migrating', async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
upgrade_status: 'UPGRADE_NEEDED',
});
httpRequestsMockHelpers.setSystemIndicesMigrationResponse(undefined, {
statusCode: 400,
message: 'error',
});

testBed = await setupOverviewPage();

const { exists, component, find } = testBed;

await act(async () => {
find('startSystemIndicesMigrationButton').simulate('click');
});

component.update();

// Error is displayed
expect(exists('startSystemIndicesMigrationCalloutError')).toBe(true);
// CTA is enabled
expect(exists('startSystemIndicesMigrationButton')).toBe(true);
expect(find('startSystemIndicesMigrationButton').props().disabled).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 { SystemIndicesMigrationStatus } from '../../../../common/types';

export const systemIndicesMigrationStatus: SystemIndicesMigrationStatus = {
upgrade_status: 'UPGRADE_NEEDED',
features: [
{
feature_name: 'security',
minimum_index_version: '7.1.1',
upgrade_status: 'ERROR',
indices: [
{
index: '.security-7',
version: '7.1.1',
},
],
},
{
feature_name: 'machine_learning',
minimum_index_version: '7.1.2',
upgrade_status: 'IN_PROGRESS',
indices: [
{
index: '.ml-config',
version: '7.1.2',
},
],
},
{
feature_name: 'kibana',
minimum_index_version: '7.1.3',
upgrade_status: 'UPGRADE_NEEDED',
indices: [
{
index: '.kibana',
version: '7.1.3',
},
],
},
{
feature_name: 'logstash',
minimum_index_version: '7.1.4',
upgrade_status: 'NO_UPGRADE_NEEDED',
indices: [
{
index: '.logstash-config',
version: '7.1.4',
},
],
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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 { act } from 'react-dom/test-utils';

import { OverviewTestBed, setupOverviewPage } from '../overview.helpers';
import { setupEnvironment, advanceTime } from '../../helpers';
import { SYSTEM_INDICES_MIGRATION_POLL_INTERVAL_MS } from '../../../../common/constants';

describe('Overview - Migrate system indices - Step completion', () => {
let testBed: OverviewTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();

afterAll(() => {
server.restore();
});

test(`It's complete when no upgrade is needed`, async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
upgrade_status: 'NO_UPGRADE_NEEDED',
});

await act(async () => {
testBed = await setupOverviewPage();
});

const { exists, component } = testBed;

component.update();

expect(exists(`migrateSystemIndicesStep-complete`)).toBe(true);
});

test(`It's incomplete when migration is needed`, async () => {
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
upgrade_status: 'UPGRADE_NEEDED',
});

await act(async () => {
testBed = await setupOverviewPage();
});

const { exists, component } = testBed;

component.update();

expect(exists(`migrateSystemIndicesStep-incomplete`)).toBe(true);
});

describe('Poll for new status', () => {
beforeEach(async () => {
jest.useFakeTimers();

// First request should make the step be incomplete
httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
upgrade_status: 'IN_PROGRESS',
});

testBed = await setupOverviewPage();
});

afterEach(() => {
jest.useRealTimers();
});

test('renders step as complete when a upgraded needed status is followed by a no upgrade needed', async () => {
const { exists } = testBed;

expect(exists('migrateSystemIndicesStep-incomplete')).toBe(true);

httpRequestsMockHelpers.setLoadSystemIndicesMigrationStatus({
upgrade_status: 'NO_UPGRADE_NEEDED',
});

// Resolve the polling timeout.
await advanceTime(SYSTEM_INDICES_MIGRATION_POLL_INTERVAL_MS);
testBed.component.update();

expect(exists('migrateSystemIndicesStep-complete')).toBe(true);
});
});
});
Loading