Skip to content

Commit 4c83710

Browse files
[ILM] Update show/hide data tier logic on cloud (#81455)
* Update show/hide data tier logic only show data tier options on cloud if the cluster is not using the deprecated node.data config and there is a data_* role present. this will likely be a role like data_content which will ensure that the cluster is configured with the new data tier roles. * refactor node role types for clarity * added comment Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 27163f7 commit 4c83710

9 files changed

Lines changed: 42 additions & 27 deletions

File tree

x-pack/plugins/index_lifecycle_management/__jest__/components/edit_policy.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,8 @@ describe('edit policy', () => {
796796
test('should hide data tier option on cloud using legacy node role configuration', async () => {
797797
http.setupNodeListResponse({
798798
nodesByAttributes: { test: ['123'] },
799-
nodesByRoles: { data: ['test'], data_hot: ['test'], data_warm: ['test'] },
799+
// On cloud, if using legacy config there will not be any "data_*" roles set.
800+
nodesByRoles: { data: ['test'] },
800801
isUsingDeprecatedDataRoleConfig: true,
801802
});
802803
const rendered = mountWithIntl(component);

x-pack/plugins/index_lifecycle_management/common/constants/data_tiers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
// Order of node roles matters here, the warm phase prefers allocating data
88
// to the data_warm role.
9-
import { NodeDataRole, PhaseWithAllocation } from '../types';
9+
import { DataTierRole, PhaseWithAllocation } from '../types';
1010

11-
const WARM_PHASE_NODE_PREFERENCE: NodeDataRole[] = ['data_warm', 'data_hot'];
11+
const WARM_PHASE_NODE_PREFERENCE: DataTierRole[] = ['data_warm', 'data_hot'];
1212

13-
const COLD_PHASE_NODE_PREFERENCE: NodeDataRole[] = ['data_cold', 'data_warm', 'data_hot'];
13+
const COLD_PHASE_NODE_PREFERENCE: DataTierRole[] = ['data_cold', 'data_warm', 'data_hot'];
1414

15-
export const phaseToNodePreferenceMap: Record<PhaseWithAllocation, NodeDataRole[]> = Object.freeze({
15+
export const phaseToNodePreferenceMap: Record<PhaseWithAllocation, DataTierRole[]> = Object.freeze({
1616
warm: WARM_PHASE_NODE_PREFERENCE,
1717
cold: COLD_PHASE_NODE_PREFERENCE,
1818
});

x-pack/plugins/index_lifecycle_management/common/types/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { NodeDataRoleWithCatchAll } from '.';
7+
import { AnyDataRole } from '.';
88

99
export interface ListNodesRouteResponse {
1010
nodesByAttributes: { [attributePair: string]: string[] };
11-
nodesByRoles: { [role in NodeDataRoleWithCatchAll]?: string[] };
11+
nodesByRoles: { [role in AnyDataRole]?: string[] };
1212

1313
/**
1414
* A flag to indicate whether a node is using `settings.node.data` which is the now deprecated way cloud configured

x-pack/plugins/index_lifecycle_management/common/types/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ export * from './api';
99
export * from './policies';
1010

1111
/**
12-
* These roles reflect how nodes are stratified into different data tiers. The "data" role
13-
* is a catch-all that can be used to store data in any phase.
12+
* These roles reflect how nodes are stratified into different data tiers.
1413
*/
15-
export type NodeDataRole = 'data_hot' | 'data_warm' | 'data_cold';
16-
export type NodeDataRoleWithCatchAll = 'data' | NodeDataRole;
14+
export type DataTierRole = 'data_hot' | 'data_warm' | 'data_cold';
15+
16+
/**
17+
* The "data_content" role can store all data the ES stack uses for feature
18+
* functionality like security-related indices.
19+
*/
20+
export type DataRole = 'data_content' | DataTierRole;
21+
22+
/**
23+
* The "data" role can store data allocated to any tier.
24+
*/
25+
export type AnyDataRole = 'data' | DataRole;

x-pack/plugins/index_lifecycle_management/public/application/lib/data_tiers/get_available_node_roles_for_phase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
*/
66

77
import {
8-
NodeDataRole,
8+
DataTierRole,
99
ListNodesRouteResponse,
1010
PhaseWithAllocation,
1111
} from '../../../../common/types';
1212

1313
import { phaseToNodePreferenceMap } from '../../../../common/constants';
1414

15-
export type AllocationNodeRole = NodeDataRole | 'none';
15+
export type AllocationNodeRole = DataTierRole | 'none';
1616

1717
/**
1818
* Given a phase and current cluster node roles, determine which nodes the phase

x-pack/plugins/index_lifecycle_management/public/application/lib/data_tiers/is_node_role_first_preference.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { NodeDataRole, PhaseWithAllocation } from '../../../../common/types';
7+
import { DataTierRole, PhaseWithAllocation } from '../../../../common/types';
88
import { phaseToNodePreferenceMap } from '../../../../common/constants';
99

10-
export const isNodeRoleFirstPreference = (phase: PhaseWithAllocation, nodeRole: NodeDataRole) => {
10+
export const isNodeRoleFirstPreference = (phase: PhaseWithAllocation, nodeRole: DataTierRole) => {
1111
return phaseToNodePreferenceMap[phase][0] === nodeRole;
1212
};

x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/default_allocation_notice.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { i18n } from '@kbn/i18n';
88
import React, { FunctionComponent } from 'react';
99
import { EuiCallOut } from '@elastic/eui';
1010

11-
import { PhaseWithAllocation, NodeDataRole } from '../../../../../../common/types';
11+
import { PhaseWithAllocation, DataTierRole } from '../../../../../../common/types';
1212

1313
import { AllocationNodeRole } from '../../../../lib';
1414

15-
const i18nTextsNodeRoleToDataTier: Record<NodeDataRole, string> = {
15+
const i18nTextsNodeRoleToDataTier: Record<DataTierRole, string> = {
1616
data_hot: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.dataTierHotLabel', {
1717
defaultMessage: 'hot',
1818
}),
@@ -31,7 +31,7 @@ const i18nTexts = {
3131
'xpack.indexLifecycleMgmt.warmPhase.dataTier.defaultAllocationNotice.warm.title',
3232
{ defaultMessage: 'No nodes assigned to the warm tier' }
3333
),
34-
body: (nodeRole: NodeDataRole) =>
34+
body: (nodeRole: DataTierRole) =>
3535
i18n.translate('xpack.indexLifecycleMgmt.warmPhase.dataTier.defaultAllocationNotice.warm', {
3636
defaultMessage:
3737
'This policy will move data in the warm phase to {tier} tier nodes instead.',
@@ -43,7 +43,7 @@ const i18nTexts = {
4343
'xpack.indexLifecycleMgmt.warmPhase.dataTier.defaultAllocationNotice.cold.title',
4444
{ defaultMessage: 'No nodes assigned to the cold tier' }
4545
),
46-
body: (nodeRole: NodeDataRole) =>
46+
body: (nodeRole: DataTierRole) =>
4747
i18n.translate('xpack.indexLifecycleMgmt.warmPhase.dataTier.defaultAllocationNotice.cold', {
4848
defaultMessage:
4949
'This policy will move data in the cold phase to {tier} tier nodes instead.',

x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared/data_tier_allocation_field.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,19 @@ export const DataTierAllocationField: FunctionComponent<Props> = ({
5555
return (
5656
<NodesDataProvider>
5757
{({ nodesByRoles, nodesByAttributes, isUsingDeprecatedDataRoleConfig }) => {
58+
const hasDataNodeRoles = Object.keys(nodesByRoles).some((nodeRole) =>
59+
// match any of the "data_" roles, including data_content.
60+
nodeRole.trim().startsWith('data_')
61+
);
5862
const hasNodeAttrs = Boolean(Object.keys(nodesByAttributes ?? {}).length);
5963

6064
const renderNotice = () => {
6165
switch (phaseData.dataTierAllocationType) {
6266
case 'default':
6367
const isCloudEnabled = cloud?.isCloudEnabled ?? false;
6468
if (isCloudEnabled && phase === 'cold') {
65-
const isUsingNodeRolesAllocation = !isUsingDeprecatedDataRoleConfig;
69+
const isUsingNodeRolesAllocation =
70+
!isUsingDeprecatedDataRoleConfig && hasDataNodeRoles;
6671
const hasNoNodesWithNodeRole = !nodesByRoles.data_cold?.length;
6772

6873
if (isUsingNodeRolesAllocation && hasNoNodesWithNodeRole) {
@@ -120,9 +125,9 @@ export const DataTierAllocationField: FunctionComponent<Props> = ({
120125
phaseData={phaseData}
121126
isShowingErrors={isShowingErrors}
122127
nodes={nodesByAttributes}
123-
disableDataTierOption={
124-
!!(isUsingDeprecatedDataRoleConfig && cloud?.isCloudEnabled)
125-
}
128+
disableDataTierOption={Boolean(
129+
cloud?.isCloudEnabled && !hasDataNodeRoles && isUsingDeprecatedDataRoleConfig
130+
)}
126131
/>
127132

128133
{/* Data tier related warnings and call-to-action notices */}

x-pack/plugins/index_lifecycle_management/server/routes/api/nodes/register_list_route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { ListNodesRouteResponse, NodeDataRole } from '../../../../common/types';
7+
import { ListNodesRouteResponse, DataTierRole } from '../../../../common/types';
88

99
import { RouteDependencies } from '../../../types';
1010
import { addBasePath } from '../../../services';
@@ -39,10 +39,10 @@ export function convertSettingsIntoLists(
3939
}
4040
}
4141

42-
const dataRoles = nodeSettings.roles.filter((r) => r.startsWith('data')) as NodeDataRole[];
42+
const dataRoles = nodeSettings.roles.filter((r) => r.startsWith('data')) as DataTierRole[];
4343
for (const role of dataRoles) {
44-
accum.nodesByRoles[role as NodeDataRole] = accum.nodesByRoles[role] ?? [];
45-
accum.nodesByRoles[role as NodeDataRole]!.push(nodeId);
44+
accum.nodesByRoles[role as DataTierRole] = accum.nodesByRoles[role] ?? [];
45+
accum.nodesByRoles[role as DataTierRole]!.push(nodeId);
4646
}
4747

4848
// If we detect a single node using legacy "data:true" setting we know we are not using data roles for

0 commit comments

Comments
 (0)