Skip to content

Commit

Permalink
[Index lifecycle management] Add deprecated policy warnings (#174150)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba committed Jan 11, 2024
1 parent 95f949f commit 9be03fe
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 50 deletions.

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

0 comments on commit 9be03fe

Please sign in to comment.