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

[Index lifecycle management] Add deprecated policy warnings #174150

Merged
merged 14 commits into from
Jan 11, 2024
Merged

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 @@ -43,6 +43,7 @@ const testPolicy = {

const isUsedByAnIndex = (i: number) => i % 2 === 0;
const isDesignatedManagedPolicy = (i: number) => i > 0 && i % 3 === 0;
const isDeprecatedPolicy = (i: number) => i > 0 && i % 2 === 0;

const policies: PolicyFromES[] = [testPolicy];
for (let i = 1; i < 105; i++) {
Expand All @@ -54,6 +55,7 @@ for (let i = 1; i < 105; i++) {
name: `testy${i}`,
policy: {
name: `testy${i}`,
deprecated: i % 2 === 0,
phases: {},
...(isDesignatedManagedPolicy(i)
? {
Expand Down Expand Up @@ -96,6 +98,7 @@ const getPolicies = (rendered: ReactWrapper) => {
version,
name,
isManagedPolicy: isDesignatedManagedPolicy(version),
isDeprecatedPolicy: isDeprecatedPolicy(version),
isUsedByAnIndex: isUsedByAnIndex(version),
};
});
Expand Down Expand Up @@ -198,6 +201,24 @@ describe('policy table', () => {
});
});

test('shows deprecated policies with Deprecated badges', () => {
const rendered = mountWithIntl(component);

// Initially the switch is off so we should not see any deprecated policies
let deprecatedPolicies = findTestSubject(rendered, 'deprecatedPolicyBadge');
expect(deprecatedPolicies.length).toBe(0);

// Enable filtering by deprecated policies
const searchInput = rendered.find('.euiFieldSearch').first();
(searchInput.instance() as unknown as HTMLInputElement).value = 'is:policy.deprecated';
searchInput.simulate('keyup', { key: 'Enter', keyCode: 13, which: 13 });
rendered.update();

// Now we should see all deprecated policies
deprecatedPolicies = findTestSubject(rendered, 'deprecatedPolicyBadge');
expect(deprecatedPolicies.length).toBeGreaterThan(0);
});

test('filters based on content of search input', () => {
const rendered = mountWithIntl(component);
const searchInput = rendered.find('.euiFieldSearch').first();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type PhaseWithDownsample = 'hot' | 'warm' | 'cold';
export interface SerializedPolicy {
name: string;
phases: Phases;
deprecated?: boolean;
_meta?: Record<string, any>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const POLICY_MANAGED_BY_ES: PolicyFromES = {
modifiedDate: Date.now().toString(),
policy: {
name: POLICY_NAME,
deprecated: true,
phases: {
hot: {
min_age: '0ms',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ describe('<EditPolicy /> edit warning', () => {
expect(exists('editManagedPolicyCallOut')).toBe(true);
});

test('an edit warning callout is shown for a deprecated policy', async () => {
httpRequestsMockHelpers.setLoadPolicies([POLICY_MANAGED_BY_ES]);

await act(async () => {
testBed = await initTestBed(httpSetup);
});
const { exists, component } = testBed;
component.update();

expect(exists('editWarning')).toBe(true);
expect(exists('editPolicyWithDeprecation')).toBe(true);
});

test('no indices link if no indices', async () => {
httpRequestsMockHelpers.setLoadPolicies([
{ ...getDefaultHotPhasePolicy(POLICY_NAME), indices: [] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const EditWarning: FunctionComponent = () => {
indexTemplatesLink
);
const isManagedPolicy = policy?._meta?.managed;
const isDeprecatedPolicy = policy?.deprecated;

return (
<>
Expand Down Expand Up @@ -102,6 +103,30 @@ export const EditWarning: FunctionComponent = () => {
<EuiSpacer />
</>
)}
{isDeprecatedPolicy && (
<>
<EuiCallOut
title={
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicyModal.deprecatedPolicyTitle"
defaultMessage="This policy is deprecated"
/>
}
color="warning"
iconType="warning"
data-test-subj="editPolicyWithDeprecation"
>
<p>
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicyModal.deprecatedPolicyDescription"
defaultMessage="This policy is no longer supported and might be removed in a future release. Instead, use one of the other policies available or create a new one."
/>
</p>
</EuiCallOut>
<EuiSpacer />
</>
)}

<p>
<strong>
<FormattedMessage
Expand Down
Loading