Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,30 @@ describe('edit policy', () => {
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'defaultAllocationWarning').exists()).toBeTruthy();
});
test('should show default allocation notice when hot tier exists, but not warm tier', async () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data_hot: ['test'], data_cold: ['test'] },
});
const rendered = mountWithIntl(component);
noRollover(rendered);
setPolicyName(rendered, 'mypolicy');
await activatePhase(rendered, 'warm');
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'defaultAllocationNotice').exists()).toBeTruthy();
});
test('should not show default allocation notice when node with "data" role exists', async () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data: ['test'] },
});
const rendered = mountWithIntl(component);
noRollover(rendered);
setPolicyName(rendered, 'mypolicy');
await activatePhase(rendered, 'warm');
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'defaultAllocationNotice').exists()).toBeFalsy();
});
});
describe('cold phase', () => {
beforeEach(() => {
Expand Down Expand Up @@ -610,6 +634,30 @@ describe('edit policy', () => {
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'defaultAllocationWarning').exists()).toBeTruthy();
});
test('should show default allocation notice when warm or hot tiers exists, but not cold tier', async () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data_hot: ['test'], data_warm: ['test'] },
});
const rendered = mountWithIntl(component);
noRollover(rendered);
setPolicyName(rendered, 'mypolicy');
await activatePhase(rendered, 'cold');
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'defaultAllocationNotice').exists()).toBeTruthy();
});
test('should not show default allocation notice when node with "data" role exists', async () => {
http.setupNodeListResponse({
nodesByAttributes: {},
nodesByRoles: { data: ['test'] },
});
const rendered = mountWithIntl(component);
noRollover(rendered);
setPolicyName(rendered, 'mypolicy');
await activatePhase(rendered, 'cold');
expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy();
expect(findTestSubject(rendered, 'defaultAllocationNotice').exists()).toBeFalsy();
});
});
describe('delete phase', () => {
test('should allow 0 for phase timing', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// Order of node roles matters here, the warm phase prefers allocating data
// to the data_warm role.
import { NodeDataRole, PhaseWithAllocation } from '../types';

const WARM_PHASE_NODE_PREFERENCE: NodeDataRole[] = ['data_warm', 'data_hot'];

const COLD_PHASE_NODE_PREFERENCE: NodeDataRole[] = ['data_cold', 'data_warm', 'data_hot'];

export const phaseToNodePreferenceMap: Record<PhaseWithAllocation, NodeDataRole[]> = Object.freeze({
warm: WARM_PHASE_NODE_PREFERENCE,
cold: COLD_PHASE_NODE_PREFERENCE,
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { i18n } from '@kbn/i18n';
import { LicenseType } from '../../../licensing/common/types';

export { phaseToNodePreferenceMap } from './data_tiers';

const basicLicense: LicenseType = 'basic';

export const PLUGIN = {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/index_lifecycle_management/common/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

export type NodeDataRole = 'data' | 'data_hot' | 'data_warm' | 'data_cold' | 'data_frozen';
import { NodeDataRoleWithCatchAll } from '.';

export interface ListNodesRouteResponse {
nodesByAttributes: { [attributePair: string]: string[] };
nodesByRoles: { [role in NodeDataRole]?: string[] };
nodesByRoles: { [role in NodeDataRoleWithCatchAll]?: string[] };
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@
export * from './api';

export * from './policies';

/**
* These roles reflect how nodes are stratified into different data tiers. The "data" role
* is a catch-all that can be used to store data in any phase.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love these comments!

export type NodeDataRole = 'data_hot' | 'data_warm' | 'data_cold';
export type NodeDataRoleWithCatchAll = 'data' | NodeDataRole;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import {
NodeDataRole,
ListNodesRouteResponse,
PhaseWithAllocation,
} from '../../../../common/types';

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

export type AllocationNodeRole = NodeDataRole | 'none';

/**
* Given a phase and current cluster node roles, determine which nodes the phase
* will allocate data to. For instance, for the warm phase, with warm
* tier nodes, we would expect "data_warm".
*
* If no nodes can be identified for allocation (very special case) then
* we return "none".
*/
export const determineAllocationNodeRole = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: a name that mentions "phase" would communicate the interaction between phase and node role to me, e.g. getAvailableNodeRoleForPhase.

phase: PhaseWithAllocation,
nodesByRoles: ListNodesRouteResponse['nodesByRoles']
): AllocationNodeRole => {
// The 'data' role covers all node roles, so if we have at least one node with the data role
// we can allocate to our first preference.
if (nodesByRoles.data?.length) {
return phaseToNodePreferenceMap[phase][0];
}

const preferredNodeRoles = phaseToNodePreferenceMap[phase];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Since we refer to phaseToNodePreferenceMap[phase] on line 32, maybe we can define this variable on line 29 and refer to it on line 32?

return preferredNodeRoles.find((role) => Boolean(nodesByRoles[role]?.length)) ?? 'none';
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

export * from './determine_allocation_type';

export * from './check_phase_compatibility';
export * from './determine_allocation_node_role';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { NodeDataRole, PhaseWithAllocation } from '../../../../common/types';
import { phaseToNodePreferenceMap } from '../../../../common/constants';

export const isNodeRoleFirstPreference = (phase: PhaseWithAllocation, nodeRole: NodeDataRole) => {
return phaseToNodePreferenceMap[phase][0] === nodeRole;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';
import React, { FunctionComponent } from 'react';
import { EuiCallOut, EuiSpacer } from '@elastic/eui';

import { PhaseWithAllocation, NodeDataRole } from '../../../../../../common/types';

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

const i18nTextsNodeRoleToDataTier: Record<NodeDataRole, string> = {
data_hot: i18n.translate('xpack.indexLifecycleMgmt.common.dataTier.hot', {
Copy link
Contributor

@cjcenizal cjcenizal Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should follow the i18n naming guidelines throughout this file: https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/GUIDELINE.md

defaultMessage: 'hot tier',
}),
data_warm: i18n.translate('xpack.indexLifecycleMgmt.common.dataTier.warm', {
defaultMessage: 'warm tier',
}),
data_cold: i18n.translate('xpack.indexLifecycleMgmt.common.dataTier.cold', {
defaultMessage: 'cold tier',
}),
};

const i18nTexts = {
notice: {
warm: {
title: i18n.translate(
'xpack.indexLifecycleMgmt.warmPhase.dataTier.defaultAllocationNotice.warm.title',
{ defaultMessage: 'No nodes assigned to the warm tier' }
),
body: (nodeRole: NodeDataRole) =>
i18n.translate('xpack.indexLifecycleMgmt.warmPhase.dataTier.defaultAllocationNotice.warm', {
defaultMessage:
'There are no nodes in the warm tier. Data in this phase will be allocated to the {tier}.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't repeat what the heading says.

Suggested change
'There are no nodes in the warm tier. Data in this phase will be allocated to the {tier}.',
'Data in the warm phase will be allocated to the {tier} instead.',

values: { tier: i18nTextsNodeRoleToDataTier[nodeRole] },
}),
},
cold: {
title: i18n.translate(
'xpack.indexLifecycleMgmt.warmPhase.dataTier.defaultAllocationNotice.cold.title',
{ defaultMessage: 'No nodes assigned to the cold tier' }
),
body: (nodeRole: NodeDataRole) =>
i18n.translate('xpack.indexLifecycleMgmt.warmPhase.dataTier.defaultAllocationNotice.cold', {
defaultMessage:
'There are no nodes in the cold tier. Data in this phase will be allocated to the {tier}.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'There are no nodes in the cold tier. Data in this phase will be allocated to the {tier}.',
'Data in the cold phase will be allocated to the {tier} instead.',

values: { tier: i18nTextsNodeRoleToDataTier[nodeRole] },
}),
},
},
warning: {
warm: {
title: i18n.translate(
'xpack.indexLifecycleMgmt.warmPhase.dataTier.defaultAllocationNotAvailableTitle',
{ defaultMessage: 'No nodes assigned to the warm tier' }
),
body: i18n.translate(
'xpack.indexLifecycleMgmt.warmPhase.dataTier.defaultAllocationNotAvailableBody',
{
defaultMessage:
'Assign at least one node to the warm or hot tier to use role-based allocation. The policy will fail to complete allocation if there are no warm nodes.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Assign at least one node to the warm or hot tier to use role-based allocation. The policy will fail to complete allocation if there are no warm nodes.',
'Assign at least one node to the warm or hot tier to use role-based allocation. The policy will fail to complete allocation if there are no available nodes.',

}
),
},
cold: {
title: i18n.translate(
'xpack.indexLifecycleMgmt.coldPhase.dataTier.defaultAllocationNotAvailableTitle',
{ defaultMessage: 'No nodes assigned to the cold tier' }
),
body: i18n.translate(
'xpack.indexLifecycleMgmt.coldPhase.dataTier.defaultAllocationNotAvailableBody',
{
defaultMessage:
'Assign at least one node to the cold, warm or hot tier to use role-based allocation. The policy will fail to complete allocation if there are no cold nodes.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Assign at least one node to the cold, warm or hot tier to use role-based allocation. The policy will fail to complete allocation if there are no cold nodes.',
'Assign at least one node to the cold, warm, or hot tier to use role-based allocation. The policy will fail to complete allocation if there are no available nodes.',

}
),
},
},
};

interface Props {
phase: PhaseWithAllocation;
targetNodeRole: AllocationNodeRole;
}

export const DefaultAllocationNotice: FunctionComponent<Props> = ({ phase, targetNodeRole }) => {
const content =
targetNodeRole === 'none' ? (
<EuiCallOut
data-test-subj="defaultAllocationWarning"
title={i18nTexts.warning[phase].title}
color="warning"
>
{i18nTexts.warning[phase].body}
</EuiCallOut>
) : (
<EuiCallOut data-test-subj="defaultAllocationNotice" title={i18nTexts.notice[phase].title}>
{i18nTexts.notice[phase].body(targetNodeRole)}
</EuiCallOut>
);

return (
<>
<EuiSpacer size="s" />
{content}
</>
);
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export { NodesDataProvider } from './node_data_provider';
export { NodeAllocation } from './node_allocation';
export { NodeAttrsDetails } from './node_attrs_details';
export { DataTierAllocation } from './data_tier_allocation';
export { DefaultAllocationWarning } from './default_allocation_warning';
export { DefaultAllocationNotice } from './default_allocation_notice';
export { NoNodeAttributesWarning } from './no_node_attributes_warning';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export {
NodeAllocation,
NodeAttrsDetails,
NodesDataProvider,
DefaultAllocationWarning,
DefaultAllocationNotice,
} from './data_tier_allocation';
export { DescribedFormField } from './described_form_field';
export { Forcemerge } from './forcemerge';
Loading