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] TS conversion of Index Management plugin extension #76308

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8ef8841
[ILM] TS conversion of Index Management plugin extension
yuliacech Aug 31, 2020
ee73c59
Upgrade EUI to v28.2.0 (#75700)
thompsongl Aug 31, 2020
20cb816
[ML] Remove "Are you sure" from filter lists (#76180)
lcawl Aug 31, 2020
047c608
[Security Solution] Refactor FirstLastSeenHost to use Search Strategy…
patrykkopycinski Aug 31, 2020
7826246
Handle cloud test failures (#74162)
chrisronline Aug 31, 2020
0068c87
chore(NA): add elastic prefix to eslint-config-kibana (#76059)
mistic Aug 31, 2020
1e5f5df
[canvas] remove unused file (#76295)
Aug 31, 2020
3fb839e
[Snapshot & Restore] Decode URIs and fix editing of a policy (#76278)
jloleysens Aug 31, 2020
ef63dc8
[Security Solution] Refactor Network TLS to use Search Strategy (#76241)
patrykkopycinski Aug 31, 2020
325b82b
replace /elasticsearch/_msearch usages with custom endpoint (#76259)
pgayvallet Aug 31, 2020
e13d8dc
Fix es_ui_shared eslint violations for useRequest hook (#72947)
cjcenizal Aug 31, 2020
3dc2c70
[Maps] fix duplicate EuiPopover id's (#76202)
nreese Aug 31, 2020
de9b7a4
Add cacheClear & cacheDelete methods (#76306)
Aug 31, 2020
a8b2810
Added validation to display an error when creating index action in al…
YulNaumenko Aug 31, 2020
08f9dcc
Added deprecation for renaming config option 'xpack.actions.whitelist…
YulNaumenko Aug 31, 2020
7b807b7
[Canvas] Add telemetry around workpad variable usage (#75683)
poffdeluxe Aug 31, 2020
630d2d5
Exposed separate from ProxySettings rejectUnauthorized configuration …
YulNaumenko Sep 1, 2020
086e488
allow multiple registration of the same feature (#76272)
pgayvallet Sep 1, 2020
e70ef65
Delete src/legacy/ui/public folder (#76085)
pgayvallet Sep 1, 2020
69461cc
[APM UI] Rephrase BDD steps for RUM scenarios (#72492)
mdelapenya Sep 1, 2020
ec1c158
restore dummy documentation_links.ts file to fix doc build (#76354)
pgayvallet Sep 1, 2020
e7966e9
[Security Solution] Add tests for import / export timelines (#75537)
angorayc Sep 1, 2020
d802bf0
xpack_main legacy plugin pre-removal cleanup (#76257)
pgayvallet Sep 1, 2020
6daf79f
[ILM] TS conversion of Index Management plugin extension
yuliacech Aug 31, 2020
283d74c
Merge remote-tracking branch 'origin/ilm_index_management' into ilm_i…
yuliacech Sep 1, 2020
e6e5939
Merge branch 'master' into ilm_index_management
elasticmachine Sep 1, 2020
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 @@ -8,7 +8,8 @@ import moment from 'moment-timezone';
import axios from 'axios';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';

import { mountWithIntl } from '../../../test_utils/enzyme_helpers';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { usageCollectionPluginMock } from '../../../../src/plugins/usage_collection/public/mocks';
import {
retryLifecycleActionExtension,
removeLifecyclePolicyActionExtension,
Expand All @@ -23,11 +24,13 @@ import { init as initUiMetric } from '../public/application/services/ui_metric';
// We need to init the http with a mock for any tests that depend upon the http service.
// For example, add_lifecycle_confirm_modal makes an API request in its componentDidMount
// lifecycle method. If we don't mock this, CI will fail with "Call retries were exceeded".
initHttp(axios.create({ adapter: axiosXhrAdapter }), (path) => path);
initUiMetric({ reportUiStats: () => {} });
// This expects HttpSetup but we're giving it AxiosInstance.
// @ts-ignore
initHttp(axios.create({ adapter: axiosXhrAdapter }));
initUiMetric(usageCollectionPluginMock.createSetupContract());

jest.mock('../../../plugins/index_management/public', async () => {
const { indexManagementMock } = await import('../../../plugins/index_management/public/mocks.ts');
const { indexManagementMock } = await import('../../../plugins/index_management/public/mocks');
return indexManagementMock.createSetup();
});

Expand Down Expand Up @@ -115,7 +118,7 @@ const indexWithLifecycleError = {

moment.tz.setDefault('utc');

const getUrlForApp = (appId, options) => {
const getUrlForApp = (appId: string, options: any) => {
return appId + '/' + (options ? options.path : '');
};

Expand Down Expand Up @@ -175,10 +178,10 @@ describe('extend index management', () => {

describe('add lifecycle policy action extension', () => {
test('should return null when index has index lifecycle policy', () => {
const extension = addLifecyclePolicyActionExtension(
{ indices: [indexWithLifecyclePolicy] },
getUrlForApp
);
const extension = addLifecyclePolicyActionExtension({
indices: [indexWithLifecyclePolicy],
getUrlForApp,
});
expect(extension).toBeNull();
});

Expand All @@ -195,8 +198,8 @@ describe('extend index management', () => {
indices: [indexWithoutLifecyclePolicy],
getUrlForApp,
});
expect(extension.renderConfirmModal).toBeDefined;
const component = extension.renderConfirmModal(jest.fn());
expect(extension?.renderConfirmModal).toBeDefined();
const component = extension!.renderConfirmModal(jest.fn());
const rendered = mountWithIntl(component);
expect(rendered.exists('.euiModal--confirmation'));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
UIM_POLICY_ATTACH_INDEX_TEMPLATE,
UIM_POLICY_DETACH_INDEX,
UIM_INDEX_RETRY_STEP,
} from '../constants/ui_metric';
} from '../constants';

import { trackUiMetric } from './ui_metric';
import { sendGet, sendPost, sendDelete, useRequest } from './http';
Expand Down Expand Up @@ -78,7 +78,11 @@ export const removeLifecycleForIndex = async (indexNames: string[]) => {
return response;
};

export const addLifecyclePolicyToIndex = async (body: GenericObject) => {
export const addLifecyclePolicyToIndex = async (body: {
indexName: string;
policyName: string;
alias: string;
}) => {
const response = await sendPost(`index/add`, body);
// Only track successful actions.
trackUiMetric(METRIC_TYPE.COUNT, UIM_POLICY_ATTACH_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import React, { Component, Fragment } from 'react';
import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { ApplicationStart } from 'kibana/public';

import {
EuiLink,
EuiSelect,
Expand All @@ -26,9 +28,25 @@ import {
import { loadPolicies, addLifecyclePolicyToIndex } from '../../application/services/api';
import { showApiError } from '../../application/services/api_errors';
import { toasts } from '../../application/services/notification';
import { PolicyFromES } from '../../application/services/policies/types';

interface Props {
indexName: string;
closeModal: () => void;
index: any;
reloadIndices: () => void;
getUrlForApp: ApplicationStart['getUrlForApp'];
}

interface State {
selectedPolicyName: string;
selectedAlias: string;
policies: PolicyFromES[];
policyError?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: might be more clear as policyErrorMessage. I know this was pre-existing, so feel free to ignore 😄

}

export class AddLifecyclePolicyConfirmModal extends Component {
constructor(props) {
export class AddLifecyclePolicyConfirmModal extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
policies: [],
Expand Down Expand Up @@ -81,7 +99,7 @@ export class AddLifecyclePolicyConfirmModal extends Component {
);
}
};
renderAliasFormElement = (selectedPolicy) => {
renderAliasFormElement = (selectedPolicy?: PolicyFromES) => {
const { selectedAlias } = this.state;
const { index } = this.props;
const showAliasSelect =
Expand Down Expand Up @@ -109,15 +127,15 @@ export class AddLifecyclePolicyConfirmModal extends Component {
defaultMessage="Policy {policyName} is configured for rollover,
but index {indexName} does not have an alias, which is required for rollover."
values={{
policyName: selectedPolicy.name,
policyName: selectedPolicy?.name,
indexName: index.name,
}}
/>
</EuiCallOut>
</Fragment>
);
}
const aliasOptions = aliases.map((alias) => {
const aliasOptions = aliases.map((alias: string) => {
return {
text: alias,
value: alias,
Expand Down Expand Up @@ -155,7 +173,7 @@ export class AddLifecyclePolicyConfirmModal extends Component {
const { policies, selectedPolicyName, policyError } = this.state;
const selectedPolicy = selectedPolicyName
? policies.find((policy) => policy.name === selectedPolicyName)
: null;
: undefined;

const options = policies.map(({ name }) => {
return {
Expand Down Expand Up @@ -188,7 +206,7 @@ export class AddLifecyclePolicyConfirmModal extends Component {
options={options}
value={selectedPolicyName}
onChange={(e) => {
this.setState({ policyError: null, selectedPolicyName: e.target.value });
this.setState({ policyError: undefined, selectedPolicyName: e.target.value });
}}
/>
</EuiFormRow>
Expand All @@ -198,7 +216,7 @@ export class AddLifecyclePolicyConfirmModal extends Component {
}
async componentDidMount() {
try {
const policies = await loadPolicies(false, this.props.httpClient);
const policies = await loadPolicies(false);
this.setState({ policies });
} catch (err) {
showApiError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ import {
EuiPopoverTitle,
} from '@elastic/eui';

import { ApplicationStart } from 'kibana/public';
import { getPolicyPath } from '../../application/services/navigation';

const getHeaders = () => {
interface Headers {
policy: string;
phase: string;
action: string;
action_time_millis: string;
failed_step: string;
}
const getHeaders = (): Headers => {
return {
policy: i18n.translate(
'xpack.indexLifecycleMgmt.indexLifecycleMgmtSummary.headers.lifecyclePolicyHeader',
Expand Down Expand Up @@ -60,8 +68,18 @@ const getHeaders = () => {
),
};
};
export class IndexLifecycleSummary extends Component {
constructor(props) {

interface Props {
index: any;
getUrlForApp: ApplicationStart['getUrlForApp'];
}
interface State {
showStackPopover: boolean;
showPhaseExecutionPopover: boolean;
}

export class IndexLifecycleSummary extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
showStackPopover: false,
Expand All @@ -80,7 +98,7 @@ export class IndexLifecycleSummary extends Component {
closePhaseExecutionPopover = () => {
this.setState({ showPhaseExecutionPopover: false });
};
renderStackPopoverButton(ilm) {
renderStackPopoverButton(ilm: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we avoid using any here?

if (!ilm.stack_trace) {
return null;
}
Expand All @@ -105,10 +123,7 @@ export class IndexLifecycleSummary extends Component {
</EuiPopover>
);
}
renderPhaseExecutionPopoverButton(ilm) {
if (!ilm.phase_execution) {
return null;
}
renderPhaseExecutionPopoverButton(ilm: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we avoid using any here?

const button = (
<EuiLink onClick={this.togglePhaseExecutionPopover}>
<FormattedMessage
Expand Down Expand Up @@ -153,11 +168,14 @@ export class IndexLifecycleSummary extends Component {
index: { ilm = {} },
} = this.props;
const headers = getHeaders();
const rows = {
const rows: {
left: JSX.Element[];
right: JSX.Element[];
} = {
left: [],
right: [],
};
Object.keys(headers).forEach((fieldName, arrayIndex) => {
Object.entries(headers).forEach(([fieldName, label], arrayIndex) => {
const value = ilm[fieldName];
let content;
if (fieldName === 'action_time_millis') {
Expand All @@ -176,21 +194,25 @@ export class IndexLifecycleSummary extends Component {
content = value;
}
content = content || '-';
const cell = [
<EuiDescriptionListTitle key={fieldName}>
<strong>{headers[fieldName]}</strong>
</EuiDescriptionListTitle>,
<EuiDescriptionListDescription key={fieldName + '_desc'}>
{content}
</EuiDescriptionListDescription>,
];
const cell = (
<Fragment>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can also use <></> for fragments

<EuiDescriptionListTitle key={fieldName}>
<strong>{label}</strong>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription key={fieldName + '_desc'}>
{content}
</EuiDescriptionListDescription>
</Fragment>
);
if (arrayIndex % 2 === 0) {
rows.left.push(cell);
} else {
rows.right.push(cell);
}
});
rows.right.push(this.renderPhaseExecutionPopoverButton(ilm));
if (ilm.phase_execution) {
rows.right.push(this.renderPhaseExecutionPopoverButton(ilm));
}
return rows;
}

Expand Down

This file was deleted.

Loading