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] Align code between branches #91862

Merged
merged 9 commits into from
Feb 24, 2021
Merged
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -21528,8 +21528,6 @@
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.indexClosedCallout.calloutDetails.reindexingTakesLongerEmphasis": "再インデックスには通常よりも時間がかかることがあります",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.indexClosedCallout.calloutTitle": "インデックスが閉じました",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.openAndCloseDocumentation": "ドキュメンテーション",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.apmReindexWarningDetail": "バージョン 7.0.0 以降、APM データは Elastic Common Schema で表示されます。過去の APM データは再インデックスされるまで表示されません。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.apmReindexWarningTitle": "このインデックスは ECS 形式に変換されます",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.destructiveCallout.calloutDetail": "インデックスをバックアップして、互換性を破るそれぞれの変更に同意することで再インデックスしてください。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.destructiveCallout.calloutTitle": "このインデックスには元に戻すことのできない破壊的な変更が含まれています",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.documentationLinkLabel": "ドキュメント",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -21578,8 +21578,6 @@
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.indexClosedCallout.calloutDetails.reindexingTakesLongerEmphasis": "重新索引可能比通常花费更多的时间",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.indexClosedCallout.calloutTitle": "索引已关闭",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.openAndCloseDocumentation": "文档",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.apmReindexWarningDetail": "从版本 7.0.0 开始,将以 Elastic Common Schema 格式表示 APM 数据。只有重新索引历史 APM 数据后,其才可见。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.apmReindexWarningTitle": "此索引将转换成 ECS 格式",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.destructiveCallout.calloutDetail": "备份您的索引,然后通过接受每个重大更改来继续重新索引。",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.destructiveCallout.calloutTitle": "此索引需要无法撤消的破坏性更改",
"xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.documentationLinkLabel": "文档",
Expand Down
15 changes: 15 additions & 0 deletions x-pack/plugins/upgrade_assistant/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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';
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this help with bundle size? Just curious ☺️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! I think I copied this from elsewhere in Kibana 😅 . I'd have to go back and compare to see how it affects the bundle size.


/*
* These constants are used only in tests to add conditional logic based on Kibana version
* On master, the version should represent the next major version (e.g., master --> 8.0.0)
* The release branch should match the release version (e.g., 7.x --> 7.0.0)
*/
export const mockKibanaVersion = '8.0.0';
export const mockKibanaSemverVersion = new SemVer(mockKibanaVersion);
2 changes: 1 addition & 1 deletion x-pack/plugins/upgrade_assistant/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type ReindexSavedObject = SavedObject<ReindexOperation>;

export enum ReindexWarning {
// 7.0 -> 8.0 warnings
apmReindex,
customTypeName,

// 8.0 -> 9.0 warnings
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import React from 'react';
import SemVer from 'semver/classes/semver';
import { mountWithIntl } from '@kbn/test/jest';
import { httpServiceMock } from 'src/core/public/mocks';
import { mockKibanaSemverVersion } from '../../../common/constants';
import { UpgradeAssistantTabs } from './tabs';
import { LoadingState } from './types';

Expand All @@ -18,7 +18,6 @@ import { OverviewTab } from './tabs/overview';
const promisesToResolve = () => new Promise((resolve) => setTimeout(resolve, 0));

const mockHttp = httpServiceMock.createSetupContract();
const mockKibanaVersion = new SemVer('8.0.0');

jest.mock('../app_context', () => {
return {
Expand All @@ -29,9 +28,9 @@ jest.mock('../app_context', () => {
ELASTIC_WEBSITE_URL: 'https://www.elastic.co/',
},
kibanaVersionInfo: {
currentMajor: mockKibanaVersion.major,
prevMajor: mockKibanaVersion.major - 1,
nextMajor: mockKibanaVersion.major + 1,
currentMajor: mockKibanaSemverVersion.major,
prevMajor: mockKibanaSemverVersion.major - 1,
nextMajor: mockKibanaSemverVersion.major + 1,
},
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { shallow } from 'enzyme';
import React from 'react';
import SemVer from 'semver/classes/semver';
import { mockKibanaSemverVersion } from '../../../../../common/constants';

import { LoadingState } from '../../types';
import AssistanceData from '../__fixtures__/checkup_api_response.json';
Expand All @@ -22,8 +22,6 @@ const defaultProps = {
setSelectedTabIndex: jest.fn(),
};

const mockKibanaVersion = new SemVer('8.0.0');

jest.mock('../../../app_context', () => {
return {
useAppContext: () => {
Expand All @@ -33,9 +31,9 @@ jest.mock('../../../app_context', () => {
ELASTIC_WEBSITE_URL: 'https://www.elastic.co/',
},
kibanaVersionInfo: {
currentMajor: mockKibanaVersion.major,
prevMajor: mockKibanaVersion.major - 1,
nextMajor: mockKibanaVersion.major + 1,
currentMajor: mockKibanaSemverVersion.major,
prevMajor: mockKibanaSemverVersion.major - 1,
nextMajor: mockKibanaSemverVersion.major + 1,
},
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ export class IndexDeprecationTable extends React.Component<

private generateActionsColumn() {
// NOTE: this naive implementation assumes all indices in the table are
// should show the reindex button. This should work for known usecases.
// should show the reindex button. This should work for known use cases.
const { indices } = this.props;
if (!indices.find((i) => i.reindex === true)) {
const hasActionsColumn = Boolean(indices.find((i) => i.reindex === true));

if (hasActionsColumn === false) {
return null;
}

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 @@ -29,7 +29,7 @@ describe('ChecklistFlyout', () => {
status: undefined,
reindexTaskPercComplete: null,
errorMessage: null,
reindexWarnings: [ReindexWarning.apmReindex],
reindexWarnings: [ReindexWarning.customTypeName],
hasRequiredPrivileges: true,
} as ReindexState,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { I18nProvider } from '@kbn/i18n/react';
import { mount, shallow } from 'enzyme';
import React from 'react';
import { mockKibanaSemverVersion } from '../../../../../../../../common/constants';

import { ReindexWarning } from '../../../../../../../../common/types';
import { idForWarning, WarningsFlyoutStep } from './warnings_step';
Expand All @@ -20,6 +21,11 @@ jest.mock('../../../../../../app_context', () => {
DOC_LINK_VERSION: 'current',
ELASTIC_WEBSITE_URL: 'https://www.elastic.co/',
},
kibanaVersionInfo: {
currentMajor: mockKibanaSemverVersion.major,
prevMajor: mockKibanaSemverVersion.major - 1,
nextMajor: mockKibanaSemverVersion.major + 1,
},
};
},
};
Expand All @@ -28,7 +34,7 @@ jest.mock('../../../../../../app_context', () => {
describe('WarningsFlyoutStep', () => {
const defaultProps = {
advanceNextStep: jest.fn(),
warnings: [ReindexWarning.apmReindex],
warnings: [ReindexWarning.customTypeName],
closeFlyout: jest.fn(),
renderGlobalCallouts: jest.fn(),
};
Expand All @@ -37,19 +43,21 @@ describe('WarningsFlyoutStep', () => {
expect(shallow(<WarningsFlyoutStep {...defaultProps} />)).toMatchSnapshot();
});

it('does not allow proceeding until all are checked', () => {
const wrapper = mount(
<I18nProvider>
<WarningsFlyoutStep {...defaultProps} />
</I18nProvider>
);
const button = wrapper.find('EuiButton');

button.simulate('click');
expect(defaultProps.advanceNextStep).not.toHaveBeenCalled();

wrapper.find(`input#${idForWarning(ReindexWarning.apmReindex)}`).simulate('change');
button.simulate('click');
expect(defaultProps.advanceNextStep).toHaveBeenCalled();
});
if (mockKibanaSemverVersion.major === 7) {
it('does not allow proceeding until all are checked', () => {
const wrapper = mount(
<I18nProvider>
<WarningsFlyoutStep {...defaultProps} />
</I18nProvider>
);
const button = wrapper.find('EuiButton');

button.simulate('click');
expect(defaultProps.advanceNextStep).not.toHaveBeenCalled();

wrapper.find(`input#${idForWarning(ReindexWarning.customTypeName)}`).simulate('change');
button.simulate('click');
expect(defaultProps.advanceNextStep).toHaveBeenCalled();
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { useState } from 'react';
import {
EuiButton,
EuiButtonEmpty,
EuiCode,
EuiCallOut,
EuiCheckbox,
EuiFlexGroup,
Expand Down Expand Up @@ -100,9 +101,9 @@ export const WarningsFlyoutStep: React.FunctionComponent<WarningsConfirmationFly
}));
};

const { docLinks } = useAppContext();
const { ELASTIC_WEBSITE_URL } = docLinks;
const observabilityDocBasePath = `${ELASTIC_WEBSITE_URL}guide/en/observability`;
const { docLinks, kibanaVersionInfo } = useAppContext();
const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = docLinks;
const esDocBasePath = `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/reference`;

return (
<>
Expand All @@ -128,25 +129,31 @@ export const WarningsFlyoutStep: React.FunctionComponent<WarningsConfirmationFly

<EuiSpacer />

{warnings.includes(ReindexWarning.apmReindex) && (
{kibanaVersionInfo.currentMajor === 7 && warnings.includes(ReindexWarning.customTypeName) && (
<WarningCheckbox
checkedIds={checkedIds}
onChange={onChange}
warning={ReindexWarning.apmReindex}
warning={ReindexWarning.customTypeName}
label={
<FormattedMessage
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.apmReindexWarningTitle"
defaultMessage="This index will be converted to ECS format"
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.customTypeNameWarningTitle"
defaultMessage="Mapping type will be changed to {defaultType}"
values={{
defaultType: <EuiCode>_doc</EuiCode>,
}}
/>
}
description={
<FormattedMessage
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.apmReindexWarningDetail"
defaultMessage="Starting in version 7.0.0, APM data will be represented in the Elastic Common Schema.
Historical APM data will not visible until it's reindexed."
id="xpack.upgradeAssistant.checkupTab.reindexing.flyout.warningsStep.customTypeNameWarningDetail"
defaultMessage="Mapping types are no longer supported in 8.0. This index mapping does not use the
default type name, {defaultType}. Ensure no application code or scripts rely on a different type."
values={{
defaultType: <EuiCode>_doc</EuiCode>,
}}
Comment on lines +148 to +153
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this new copy? If it is, it looks good to me, but it could be worth pulling in someone from esdocs@ too!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's slightly modified from 7.x 😄. I'm going to hold off on a copy review for now, as I think this UI will change as part of the redesign.

/>
}
documentationUrl={`${observabilityDocBasePath}/master/whats-new.html`}
documentationUrl={`${esDocBasePath}/${DOC_LINK_VERSION}/removal-of-types.html`}
/>
)}
</EuiFlyoutBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
* 2.0.
*/

import { SemVer } from 'semver';
import { mockKibanaSemverVersion } from '../../../common/constants';

export const MOCK_VERSION_STRING = '8.0.0';

export const getMockVersionInfo = (versionString = MOCK_VERSION_STRING) => {
const currentVersion = new SemVer(versionString);
const currentMajor = currentVersion.major;
export const getMockVersionInfo = () => {
const currentMajor = mockKibanaSemverVersion.major;

return {
currentVersion,
currentVersion: mockKibanaSemverVersion,
currentMajor,
prevMajor: currentMajor - 1,
nextMajor: currentMajor + 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('getUpgradeAssistantStatus', () => {
const resolvedIndices = {
indices: fakeIndexNames.map((f) => ({ name: f, attributes: ['open'] })),
};

// @ts-expect-error mock data is too loosely typed
const deprecationsResponse: DeprecationAPIResponse = _.cloneDeep(fakeDeprecations);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { SemVer } from 'semver';
import { IScopedClusterClient, kibanaResponseFactory } from 'src/core/server';
import { coreMock } from 'src/core/server/mocks';
import { licensingMock } from '../../../../plugins/licensing/server/mocks';
import { MOCK_VERSION_STRING, getMockVersionInfo } from './__fixtures__/version';
import { mockKibanaVersion } from '../../common/constants';
import { getMockVersionInfo } from './__fixtures__/version';

import {
esVersionCheck,
Expand Down Expand Up @@ -97,7 +98,7 @@ describe('verifyAllMatchKibanaVersion', () => {

describe('EsVersionPrecheck', () => {
beforeEach(() => {
versionService.setup(MOCK_VERSION_STRING);
versionService.setup(mockKibanaVersion);
});

it('returns a 403 when callCluster fails with a 403', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* 2.0.
*/

import { mockKibanaSemverVersion, mockKibanaVersion } from '../../../common/constants';
import { ReindexWarning } from '../../../common/types';
import { versionService } from '../version';
import { MOCK_VERSION_STRING, getMockVersionInfo } from '../__fixtures__/version';
import { getMockVersionInfo } from '../__fixtures__/version';

import {
generateNewIndexName,
Expand Down Expand Up @@ -123,7 +125,7 @@ describe('transformFlatSettings', () => {

describe('sourceNameForIndex', () => {
beforeEach(() => {
versionService.setup(MOCK_VERSION_STRING);
versionService.setup(mockKibanaVersion);
});

it('parses internal indices', () => {
Expand All @@ -144,7 +146,7 @@ describe('sourceNameForIndex', () => {

describe('generateNewIndexName', () => {
beforeEach(() => {
versionService.setup(MOCK_VERSION_STRING);
versionService.setup(mockKibanaVersion);
});

it('parses internal indices', () => {
Expand Down Expand Up @@ -177,4 +179,26 @@ describe('getReindexWarnings', () => {
})
).toEqual([]);
});

if (mockKibanaSemverVersion.major === 7) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how the test harness is being set up, but it could be a better pattern to create a nested describe blocks for the 7 cases and 8 cases with their own test setups. WDYT?

describe('customTypeName warning', () => {
it('returns customTypeName for non-_doc mapping types', () => {
expect(
getReindexWarnings({
settings: {},
mappings: { doc: {} },
})
).toEqual([ReindexWarning.customTypeName]);
});

it('does not return customTypeName for _doc mapping types', () => {
expect(
getReindexWarnings({
settings: {},
mappings: { _doc: {} },
})
).toEqual([]);
});
});
}
});
Loading