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
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,22 @@ describe('policy table', () => {
});
});

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

visiblePolicies.forEach((p) => {
const policyRow = findTestSubject(rendered, `policyTableRow-${p.name}`);
const deprecatedBadge = findTestSubject(policyRow, 'deprecatedPolicyBadge');

if (p.isDeprecatedPolicy) {
expect(deprecatedBadge.exists()).toBeTruthy();
} else {
expect(deprecatedBadge.exists()).toBeFalsy();
}
});
});

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 deprecated and should not be relied on."
sabarasaba marked this conversation as resolved.
Show resolved Hide resolved
/>
</p>
</EuiCallOut>
<EuiSpacer />
</>
)}

<p>
<strong>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ const managedPolicyTooltips = {
),
};

const deprecatedPolicyTooltips = {
badge: i18n.translate('xpack.indexLifecycleMgmt.policyTable.templateBadgeType.deprecatedLabel', {
defaultMessage: 'Deprecated',
}),
badgeTooltip: i18n.translate(
'xpack.indexLifecycleMgmt.policyTable.templateBadgeType.deprecatedDescription',
{
defaultMessage: 'This policy is deprecated and should not be relied on.',
sabarasaba marked this conversation as resolved.
Show resolved Hide resolved
}
),
};

interface Props {
policies: PolicyFromES[];
}
Expand Down Expand Up @@ -124,6 +136,8 @@ export const PolicyTable: React.FunctionComponent<Props> = ({ policies }) => {
sortable: true,
render: (value: string, item) => {
const isManaged = item.policy?._meta?.managed;
const isDeprecated = item.policy?.deprecated;

return (
<>
<EuiLink
Expand All @@ -136,6 +150,17 @@ export const PolicyTable: React.FunctionComponent<Props> = ({ policies }) => {
{value}
</EuiLink>

{isDeprecated && (
<>
&nbsp;
<EuiToolTip content={deprecatedPolicyTooltips.badgeTooltip}>
<EuiBadge color="warning" data-test-subj="deprecatedPolicyBadge">
{deprecatedPolicyTooltips.badge}
</EuiBadge>
</EuiToolTip>
</>
)}

{isManaged && (
<>
&nbsp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function deserializeTemplate(
composed_of: composedOf,
data_stream: dataStream,
allow_auto_create: allowAutoCreate,
deprecated,
} = templateEs;
const { settings } = template;

Expand All @@ -77,6 +78,7 @@ export function deserializeTemplate(
composedOf: composedOf ?? [],
dataStream,
allowAutoCreate,
deprecated,
_meta,
_kbnMeta: {
type,
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/index_management/common/types/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface TemplateSerialized {
_meta?: { [key: string]: any };
data_stream?: {};
allow_auto_create?: boolean;
deprecated?: boolean;
}

/**
Expand All @@ -42,6 +43,7 @@ export interface TemplateDeserialized {
aliases?: Aliases;
mappings?: Mappings;
};
deprecated?: boolean;
sabarasaba marked this conversation as resolved.
Show resolved Hide resolved
lifecycle?: DataRetention;
composedOf?: string[]; // Composable template only
version?: number;
Expand Down