Skip to content

Commit b85f492

Browse files
committed
fix for correctly detecting policy data tier type
- with jest tests see origin here: elastic#81642
1 parent 750992e commit b85f492

File tree

4 files changed

+112
-2
lines changed

4 files changed

+112
-2
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,58 @@ export const DELETE_PHASE_POLICY: PolicyFromES = {
9595
},
9696
name: POLICY_NAME,
9797
};
98+
99+
export const POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION: PolicyFromES = {
100+
version: 1,
101+
modified_date: Date.now().toString(),
102+
policy: {
103+
phases: {
104+
hot: {
105+
min_age: '0ms',
106+
actions: {
107+
rollover: {
108+
max_size: '50gb',
109+
},
110+
},
111+
},
112+
warm: {
113+
actions: {
114+
allocate: {
115+
require: {},
116+
include: { test: '123' },
117+
exclude: {},
118+
},
119+
},
120+
},
121+
cold: {
122+
actions: {
123+
migrate: { enabled: false },
124+
},
125+
},
126+
},
127+
name: POLICY_NAME,
128+
},
129+
name: POLICY_NAME,
130+
};
131+
132+
export const POLICY_WITH_NODE_ROLE_ALLOCATION: PolicyFromES = {
133+
version: 1,
134+
modified_date: Date.now().toString(),
135+
policy: {
136+
phases: {
137+
hot: {
138+
min_age: '0ms',
139+
actions: {
140+
rollover: {
141+
max_size: '50gb',
142+
},
143+
},
144+
},
145+
warm: {
146+
actions: {},
147+
},
148+
},
149+
name: POLICY_NAME,
150+
},
151+
name: POLICY_NAME,
152+
};

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
SNAPSHOT_POLICY_NAME,
1717
DEFAULT_POLICY,
1818
POLICY_WITH_INCLUDE_EXCLUDE,
19+
POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION,
20+
POLICY_WITH_NODE_ROLE_ALLOCATION,
1921
} from './constants';
2022

2123
window.scrollTo = jest.fn();
@@ -381,4 +383,57 @@ describe('<EditPolicy />', () => {
381383
expect(testBed.find('policiesErrorCallout').exists()).toBeTruthy();
382384
});
383385
});
386+
387+
describe('data allocation', () => {
388+
describe('node roles', () => {
389+
beforeEach(async () => {
390+
httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_NODE_ROLE_ALLOCATION]);
391+
httpRequestsMockHelpers.setListNodes({
392+
isUsingDeprecatedDataRoleConfig: false,
393+
nodesByAttributes: { test: ['123'] },
394+
nodesByRoles: { data: ['123'] },
395+
});
396+
397+
await act(async () => {
398+
testBed = await setup();
399+
});
400+
401+
const { component } = testBed;
402+
component.update();
403+
});
404+
test('showing "default" type', () => {
405+
const { find } = testBed;
406+
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).toContain(
407+
'recommended'
408+
);
409+
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).not.toContain(
410+
'Custom'
411+
);
412+
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).not.toContain('Off');
413+
});
414+
});
415+
describe('node attr and none', () => {
416+
beforeEach(async () => {
417+
httpRequestsMockHelpers.setLoadPolicies([POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION]);
418+
httpRequestsMockHelpers.setListNodes({
419+
isUsingDeprecatedDataRoleConfig: false,
420+
nodesByAttributes: { test: ['123'] },
421+
nodesByRoles: { data: ['123'] },
422+
});
423+
424+
await act(async () => {
425+
testBed = await setup();
426+
});
427+
428+
const { component } = testBed;
429+
component.update();
430+
});
431+
432+
test('showing "custom" and "off" types', () => {
433+
const { find } = testBed;
434+
expect(find('warm-dataTierAllocationControls.dataTierSelect').text()).toContain('Custom');
435+
expect(find('cold-dataTierAllocationControls.dataTierSelect').text()).toContain('Off');
436+
});
437+
});
438+
});
384439
});

x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/deserializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const deserializer = (policy: SerializedPolicy): FormInternal => {
2626
warmPhaseOnRollover: Boolean(policy.phases.warm?.min_age === '0ms'),
2727
forceMergeEnabled: Boolean(policy.phases.warm?.actions?.forcemerge),
2828
bestCompression: policy.phases.warm?.actions?.forcemerge?.index_codec === 'best_compression',
29-
dataTierAllocationType: determineDataTierAllocationType(policy.phases.warm?.actions.allocate),
29+
dataTierAllocationType: determineDataTierAllocationType(policy.phases.warm?.actions),
3030
},
3131
};
3232

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const coldPhaseFromES = (phaseSerialized?: SerializedColdPhase): ColdPhas
3535

3636
phase.phaseEnabled = true;
3737

38-
if (phaseSerialized.actions.allocate) {
38+
if (phaseSerialized.actions) {
3939
phase.dataTierAllocationType = determineDataTierAllocationTypeLegacy(phaseSerialized.actions);
4040
}
4141

0 commit comments

Comments
 (0)