Skip to content

Commit

Permalink
[Upgrade Assistant] Add upgrade system indices section (elastic#110593)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba committed Oct 14, 2021
1 parent 676beb2 commit 4d78f7a
Show file tree
Hide file tree
Showing 22 changed files with 1,159 additions and 27 deletions.
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

0 comments on commit 4d78f7a

Please sign in to comment.