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

[ILM] Cloud-specific changes for 7.10 #79650

Merged
merged 15 commits into from
Oct 13, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import {
fatalErrorsServiceMock,
} from '../../../../../src/core/public/mocks';
import { usageCollectionPluginMock } from '../../../../../src/plugins/usage_collection/public/mocks';
import { CloudSetup } from '../../../cloud/public';

import { EditPolicy } from '../../public/application/sections/edit_policy/edit_policy';
import { KibanaContextProvider } from '../../public/shared_imports';
import { init as initHttp } from '../../public/application/services/http';
import { init as initUiMetric } from '../../public/application/services/ui_metric';
import { init as initNotification } from '../../public/application/services/notification';
Expand Down Expand Up @@ -148,7 +150,14 @@ const save = (rendered: ReactWrapper) => {
describe('edit policy', () => {
beforeEach(() => {
component = (
<EditPolicy history={history} getUrlForApp={jest.fn()} policies={policies} policyName={''} />
<KibanaContextProvider services={{ cloud: { isCloudEnabled: false } as CloudSetup }}>
<EditPolicy
history={history}
getUrlForApp={jest.fn()}
policies={policies}
policyName={''}
/>
</KibanaContextProvider>
);

({ http } = editPolicyHelpers.setup());
Expand Down Expand Up @@ -447,6 +456,7 @@ describe('edit policy', () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data: ['node1'] },
isUsingDeprecatedDataRoleConfig: false,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
Expand Down Expand Up @@ -495,6 +505,7 @@ describe('edit policy', () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: {},
isUsingDeprecatedDataRoleConfig: false,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
Expand All @@ -507,6 +518,7 @@ describe('edit policy', () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data_hot: ['test'], data_cold: ['test'] },
isUsingDeprecatedDataRoleConfig: false,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
Expand All @@ -519,6 +531,7 @@ describe('edit policy', () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data: ['test'] },
isUsingDeprecatedDataRoleConfig: false,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
Expand Down Expand Up @@ -568,6 +581,7 @@ describe('edit policy', () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data: ['node1'] },
isUsingDeprecatedDataRoleConfig: false,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
Expand Down Expand Up @@ -626,6 +640,7 @@ describe('edit policy', () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: {},
isUsingDeprecatedDataRoleConfig: false,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
Expand All @@ -638,6 +653,7 @@ describe('edit policy', () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data_hot: ['test'], data_warm: ['test'] },
isUsingDeprecatedDataRoleConfig: false,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
Expand All @@ -650,6 +666,7 @@ describe('edit policy', () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data: ['test'] },
isUsingDeprecatedDataRoleConfig: false,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
Expand Down Expand Up @@ -679,4 +696,104 @@ describe('edit policy', () => {
expectedErrorMessages(rendered, [positiveNumberRequiredMessage]);
});
});
describe('not on cloud', () => {
beforeEach(() => {
server.respondImmediately = true;
});
test('should show all allocation options, even if using legacy config', async () => {
http.setupNodeListResponse({
nodesByAttributes: { test: ['123'] },
nodesByRoles: { data: ['test'], data_hot: ['test'], data_warm: ['test'] },
isUsingDeprecatedDataRoleConfig: true,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
setPolicyName(rendered, 'mypolicy');
await activatePhase(rendered, 'warm');
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();

// Assert that only the custom and off options exist
findTestSubject(rendered, 'dataTierSelect').simulate('click');
expect(findTestSubject(rendered, 'defaultDataAllocationOption').exists()).toBeTruthy();
expect(findTestSubject(rendered, 'customDataAllocationOption').exists()).toBeTruthy();
expect(findTestSubject(rendered, 'noneDataAllocationOption').exists()).toBeTruthy();
});
});
describe('on cloud', () => {
beforeEach(() => {
component = (
<KibanaContextProvider services={{ cloud: { isCloudEnabled: true } as CloudSetup }}>
<EditPolicy
history={history}
getUrlForApp={jest.fn()}
policies={policies}
policyName="test"
/>
</KibanaContextProvider>
);
({ http } = editPolicyHelpers.setup());
({ server, httpRequestsMockHelpers } = http);
server.respondImmediately = true;

httpRequestsMockHelpers.setPoliciesResponse(policies);
});

describe('with legacy data role config', () => {
test('should hide data tier option on cloud using legacy node role configuration', async () => {
http.setupNodeListResponse({
nodesByAttributes: { test: ['123'] },
nodesByRoles: { data: ['test'], data_hot: ['test'], data_warm: ['test'] },
isUsingDeprecatedDataRoleConfig: true,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
setPolicyName(rendered, 'mypolicy');
await activatePhase(rendered, 'warm');
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();

// Assert that only the custom and off options exist
findTestSubject(rendered, 'dataTierSelect').simulate('click');
expect(findTestSubject(rendered, 'defaultDataAllocationOption').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'customDataAllocationOption').exists()).toBeTruthy();
expect(findTestSubject(rendered, 'noneDataAllocationOption').exists()).toBeTruthy();
});
});

describe('with node role config', () => {
test('should show off, custom and data role options on cloud with data roles', async () => {
http.setupNodeListResponse({
nodesByAttributes: { test: ['123'] },
nodesByRoles: { data: ['test'], data_hot: ['test'], data_warm: ['test'] },
isUsingDeprecatedDataRoleConfig: false,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
setPolicyName(rendered, 'mypolicy');
await activatePhase(rendered, 'warm');
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();

findTestSubject(rendered, 'dataTierSelect').simulate('click');
expect(findTestSubject(rendered, 'defaultDataAllocationOption').exists()).toBeTruthy();
expect(findTestSubject(rendered, 'customDataAllocationOption').exists()).toBeTruthy();
expect(findTestSubject(rendered, 'noneDataAllocationOption').exists()).toBeTruthy();
});

test('should show cloud notice when cold tier nodes do not exist', async () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data: ['test'], data_hot: ['test'], data_warm: ['test'] },
isUsingDeprecatedDataRoleConfig: false,
});
const rendered = mountWithIntl(component);
noRollover(rendered);
setPolicyName(rendered, 'mypolicy');
await activatePhase(rendered, 'cold');
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'cloudDataTierCallout').exists()).toBeTruthy();
// Assert that other notices are not showing
expect(findTestSubject(rendered, 'defaultAllocationNotice').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'noNodeAttributesWarning').exists()).toBeFalsy();
});
});
});
});
8 changes: 8 additions & 0 deletions x-pack/plugins/index_lifecycle_management/common/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ import { NodeDataRoleWithCatchAll } from '.';
export interface ListNodesRouteResponse {
nodesByAttributes: { [attributePair: string]: string[] };
nodesByRoles: { [role in NodeDataRoleWithCatchAll]?: string[] };

/**
* A flag to indicate whether a node is using `settings.node.data` which is the now deprecated way cloud configured
* nodes to have data (and other) roles.
*
* If this is true, it means the cluster is using legacy cloud configuration for data allocation, not node roles.
*/
isUsingDeprecatedDataRoleConfig: boolean;
}
1 change: 1 addition & 0 deletions x-pack/plugins/index_lifecycle_management/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"features"
],
"optionalPlugins": [
"cloud",
"usageCollection",
"indexManagement",
"home"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { I18nStart, ScopedHistory, ApplicationStart } from 'kibana/public';
import { UnmountCallback } from 'src/core/public';
import { CloudSetup } from '../../../cloud/public';

import { KibanaContextProvider } from '../shared_imports';

import { App } from './app';

Expand All @@ -16,11 +19,14 @@ export const renderApp = (
I18nContext: I18nStart['Context'],
history: ScopedHistory,
navigateToApp: ApplicationStart['navigateToApp'],
getUrlForApp: ApplicationStart['getUrlForApp']
getUrlForApp: ApplicationStart['getUrlForApp'],
cloud?: CloudSetup
): UnmountCallback => {
render(
<I18nContext>
<App history={history} navigateToApp={navigateToApp} getUrlForApp={getUrlForApp} />
<KibanaContextProvider services={{ cloud }}>
<App history={history} navigateToApp={navigateToApp} getUrlForApp={getUrlForApp} />
</KibanaContextProvider>
</I18nContext>,
element
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';
import React, { FunctionComponent } from 'react';
import { EuiCallOut } from '@elastic/eui';

const i18nTexts = {
title: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.title', {
defaultMessage: 'Create a cold tier',
}),
body: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.body', {
defaultMessage: 'Edit your Elastic Cloud deployment to set up a cold tier.',
}),
};

export const CloudDataTierCallout: FunctionComponent = () => {
return (
<EuiCallOut title={i18nTexts.title} data-test-subj="cloudDataTierCallout">
{i18nTexts.body}
</EuiCallOut>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FunctionComponent } from 'react';
import React, { FunctionComponent, useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiText, EuiFormRow, EuiSpacer, EuiSuperSelect, EuiSuperSelectOption } from '@elastic/eui';

Expand Down Expand Up @@ -90,7 +90,25 @@ const i18nTexts = {
};

export const DataTierAllocation: FunctionComponent<SharedProps> = (props) => {
const { phaseData, setPhaseData, phase, hasNodeAttributes } = props;
const { phaseData, setPhaseData, phase, hasNodeAttributes, disableDataTierOption } = props;

useEffect(() => {
if (disableDataTierOption && phaseData.dataTierAllocationType === 'default') {
/**
* @TODO
* This is a slight hack because we only know we should disable the "default" option further
* down the component tree (i.e., after the policy has been deserialized).
*
* We reset the value to "custom" if we deserialized to "default".
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to read this comment a few times to understand what the intention was. I interpret this as meaning, "If the initial data tier allocation value is default, we'll override this with custom if this option is disallowed." Is that right?

The "slight hack" part confuses me because I'm not sure what the "right" way to do it would be or why it isn't possible and therefore why we're forced to resort to a hack. Can we elaborate to explain what's hacky about this and why the hack is justified?

*
* It would be better if we had all the information we needed before deserializing and
* were able to handle this at the deserialization step instead of patching further down
* the component tree - this should be a future refactor.
*/
setPhaseData('dataTierAllocationType', 'custom');
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<div data-test-subj={`${phase}-dataTierAllocationControls`}>
Expand All @@ -102,21 +120,40 @@ export const DataTierAllocation: FunctionComponent<SharedProps> = (props) => {
onChange={(value) => setPhaseData('dataTierAllocationType', value)}
options={
[
disableDataTierOption
? undefined
: {
'data-test-subj': 'defaultDataAllocationOption',
value: 'default',
inputDisplay: i18nTexts.allocationOptions[phase].default.input,
dropdownDisplay: (
<>
<strong>{i18nTexts.allocationOptions[phase].default.input}</strong>
<EuiText size="s" color="subdued">
<p className="euiTextColor--subdued">
{i18nTexts.allocationOptions[phase].default.helpText}
</p>
</EuiText>
</>
),
},
{
value: 'default',
inputDisplay: i18nTexts.allocationOptions[phase].default.input,
'data-test-subj': 'customDataAllocationOption',
value: 'custom',
inputDisplay: i18nTexts.allocationOptions[phase].custom.inputDisplay,
dropdownDisplay: (
<>
<strong>{i18nTexts.allocationOptions[phase].default.input}</strong>
<strong>{i18nTexts.allocationOptions[phase].custom.inputDisplay}</strong>
<EuiText size="s" color="subdued">
<p className="euiTextColor--subdued">
{i18nTexts.allocationOptions[phase].default.helpText}
{i18nTexts.allocationOptions[phase].custom.helpText}
</p>
</EuiText>
</>
),
},
{
'data-test-subj': 'noneDataAllocationOption',
value: 'none',
inputDisplay: i18nTexts.allocationOptions[phase].none.inputDisplay,
dropdownDisplay: (
Expand All @@ -130,22 +167,7 @@ export const DataTierAllocation: FunctionComponent<SharedProps> = (props) => {
</>
),
},
{
'data-test-subj': 'customDataAllocationOption',
value: 'custom',
inputDisplay: i18nTexts.allocationOptions[phase].custom.inputDisplay,
dropdownDisplay: (
<>
<strong>{i18nTexts.allocationOptions[phase].custom.inputDisplay}</strong>
<EuiText size="s" color="subdued">
<p className="euiTextColor--subdued">
{i18nTexts.allocationOptions[phase].custom.helpText}
</p>
</EuiText>
</>
),
},
] as SelectOptions[]
].filter(Boolean) as SelectOptions[]
}
/>
</EuiFormRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { i18n } from '@kbn/i18n';
import React, { FunctionComponent } from 'react';
import { EuiCallOut, EuiSpacer } from '@elastic/eui';
import { EuiCallOut } from '@elastic/eui';

import { PhaseWithAllocation, NodeDataRole } from '../../../../../../common/types';

Expand Down Expand Up @@ -102,10 +102,5 @@ export const DefaultAllocationNotice: FunctionComponent<Props> = ({ phase, targe
</EuiCallOut>
);

return (
<>
<EuiSpacer size="s" />
{content}
</>
);
return content;
};
Loading