Skip to content

Commit 04a19e3

Browse files
authored
fix misleading copy and fix serialization of custom without node attribute (#81908)
1 parent 564d6d0 commit 04a19e3

File tree

4 files changed

+71
-8
lines changed

4 files changed

+71
-8
lines changed

x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/constants.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,28 @@ export const POLICY_WITH_NODE_ROLE_ALLOCATION: PolicyFromES = {
9494
},
9595
name: POLICY_NAME,
9696
};
97+
98+
export const POLICY_WITH_MIGRATE_OFF: PolicyFromES = {
99+
version: 1,
100+
modified_date: Date.now().toString(),
101+
policy: {
102+
name: 'my_policy',
103+
phases: {
104+
hot: {
105+
min_age: '0ms',
106+
actions: {
107+
rollover: {
108+
max_age: '30d',
109+
max_size: '50gb',
110+
},
111+
},
112+
},
113+
warm: {
114+
actions: {
115+
migrate: { enabled: false },
116+
},
117+
},
118+
},
119+
},
120+
name: 'my_policy',
121+
};

x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
DELETE_PHASE_POLICY,
1515
NEW_SNAPSHOT_POLICY_NAME,
1616
SNAPSHOT_POLICY_NAME,
17+
POLICY_WITH_MIGRATE_OFF,
1718
POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION,
1819
POLICY_WITH_NODE_ROLE_ALLOCATION,
1920
} from './constants';
@@ -142,6 +143,40 @@ describe('<EditPolicy />', () => {
142143
});
143144

144145
describe('data allocation', () => {
146+
beforeEach(async () => {
147+
httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_MIGRATE_OFF]);
148+
httpRequestsMockHelpers.setListNodes({
149+
nodesByRoles: {},
150+
nodesByAttributes: { test: ['123'] },
151+
isUsingDeprecatedDataRoleConfig: false,
152+
});
153+
httpRequestsMockHelpers.setLoadSnapshotPolicies([]);
154+
155+
await act(async () => {
156+
testBed = await setup();
157+
});
158+
159+
const { component } = testBed;
160+
component.update();
161+
});
162+
163+
test('setting node_attr based allocation, but not selecting node attribute should leave allocation unchanged', async () => {
164+
const { actions, find, component } = testBed;
165+
act(() => {
166+
find(`warm-dataTierAllocationControls.dataTierSelect`).simulate('click');
167+
});
168+
component.update();
169+
await act(async () => {
170+
find(`warm-dataTierAllocationControls.customDataAllocationOption`).simulate('click');
171+
});
172+
component.update();
173+
await actions.savePolicy();
174+
const latestRequest = server.requests[server.requests.length - 1];
175+
const warmPhase = JSON.parse(JSON.parse(latestRequest.requestBody).body).phases.warm;
176+
177+
expect(warmPhase.actions.migrate).toEqual({ enabled: false });
178+
});
179+
145180
describe('node roles', () => {
146181
beforeEach(async () => {
147182
httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_NODE_ROLE_ALLOCATION]);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const i18nTexts = {
1919
'xpack.indexLifecycleMgmt.editPolicy.warm.nodeAttributesMissingDescription',
2020
{
2121
defaultMessage:
22-
'Define custom node attributes in elasticsearch.yml to use attribute-based allocation. Warm nodes will be used instead.',
22+
'Define custom node attributes in elasticsearch.yml to use attribute-based allocation.',
2323
}
2424
),
2525
},
@@ -28,7 +28,7 @@ const i18nTexts = {
2828
'xpack.indexLifecycleMgmt.editPolicy.cold.nodeAttributesMissingDescription',
2929
{
3030
defaultMessage:
31-
'Define custom node attributes in elasticsearch.yml to use attribute-based allocation. Cold nodes will be used instead.',
31+
'Define custom node attributes in elasticsearch.yml to use attribute-based allocation.',
3232
}
3333
),
3434
},

x-pack/plugins/index_lifecycle_management/public/application/services/policies/shared/serialize_phase_with_allocation.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ export const serializePhaseWithAllocation = (
2020
): SerializedPhase['actions'] => {
2121
const esPhaseActions: SerializedPhase['actions'] = cloneDeep(originalPhaseActions);
2222

23-
if (phase.dataTierAllocationType === 'custom' && phase.selectedNodeAttrs) {
24-
const [name, value] = phase.selectedNodeAttrs.split(':');
25-
esPhaseActions.allocate = esPhaseActions.allocate || ({} as AllocateAction);
26-
esPhaseActions.allocate.require = {
27-
[name]: value,
28-
};
23+
if (phase.dataTierAllocationType === 'custom') {
24+
if (phase.selectedNodeAttrs) {
25+
const [name, value] = phase.selectedNodeAttrs.split(':');
26+
esPhaseActions.allocate = esPhaseActions.allocate || ({} as AllocateAction);
27+
esPhaseActions.allocate.require = {
28+
[name]: value,
29+
};
30+
}
31+
// else leave the policy configuration unchanged.
2932
} else if (phase.dataTierAllocationType === 'none') {
3033
esPhaseActions.migrate = { enabled: false };
3134
if (esPhaseActions.allocate) {

0 commit comments

Comments
 (0)