Skip to content

Commit

Permalink
[ILM] Add index_codec to forcemerge action in hot and warm phases (#7…
Browse files Browse the repository at this point in the history
…8175)

* [ILM] Add index_codec to forcemerge action in hot and warm phases

* [ILM] Fix i18n check errors

* [ILM] Add code review suggestions

* [ILM] Add code review suggestions

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 6, 2020
1 parent 3a7d709 commit dcb646d
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export interface SerializedHotPhase extends SerializedPhase {
max_age?: string;
max_docs?: number;
};
forcemerge?: {
max_num_segments: number;
};
forcemerge?: ForcemergeAction;
set_priority?: {
priority: number | null;
};
Expand All @@ -57,9 +55,7 @@ export interface SerializedWarmPhase extends SerializedPhase {
shrink?: {
number_of_shards: number;
};
forcemerge?: {
max_num_segments: number;
};
forcemerge?: ForcemergeAction;
set_priority?: {
priority: number | null;
};
Expand Down Expand Up @@ -105,6 +101,12 @@ export interface AllocateAction {
};
}

export interface ForcemergeAction {
max_num_segments: number;
// only accepted value for index_codec
index_codec?: 'best_compression';
}

export interface Policy {
name: string;
phases: {
Expand Down Expand Up @@ -150,6 +152,7 @@ export interface PhaseWithIndexPriority {
export interface PhaseWithForcemergeAction {
forceMergeEnabled: boolean;
selectedForceMergeSegments: string;
bestCompressionEnabled: boolean;
}

export interface HotPhase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const defaultNewHotPhase: HotPhase = {
selectedMaxSizeStoredUnits: 'gb',
forceMergeEnabled: false,
selectedForceMergeSegments: '',
bestCompressionEnabled: false,
phaseIndexPriority: '100',
selectedMaxDocuments: '',
};
Expand All @@ -29,6 +30,7 @@ export const defaultNewWarmPhase: WarmPhase = {
phaseEnabled: false,
forceMergeEnabled: false,
selectedForceMergeSegments: '',
bestCompressionEnabled: false,
selectedMinimumAge: '0',
selectedMinimumAgeUnits: 'd',
selectedNodeAttrs: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
import {
EuiDescribedFormGroup,
EuiFieldNumber,
EuiFormRow,
EuiSpacer,
EuiSwitch,
EuiTextColor,
Expand All @@ -19,17 +20,25 @@ import { ErrableFormRow } from './form_errors';
import { Phases, PhaseWithForcemergeAction } from '../../../../../common/types';
import { PhaseValidationErrors } from '../../../services/policies/policy_validation';

const forcemergeLabel = i18n.translate('xpack.indexLifecycleMgmt.warmPhase.forceMergeDataLabel', {
const forcemergeLabel = i18n.translate('xpack.indexLifecycleMgmt.forcemerge.enableLabel', {
defaultMessage: 'Force merge data',
});

const bestCompressionLabel = i18n.translate(
'xpack.indexLifecycleMgmt.forcemerge.bestCompressionLabel',
{
defaultMessage: 'Compress stored fields',
}
);

interface Props {
errors?: PhaseValidationErrors<PhaseWithForcemergeAction>;
phase: keyof Phases & string;
phaseData: PhaseWithForcemergeAction;
setPhaseData: (dataKey: keyof PhaseWithForcemergeAction, value: boolean | string) => void;
isShowingErrors: boolean;
}

export const Forcemerge: React.FunctionComponent<Props> = ({
errors,
phaseData,
Expand All @@ -42,15 +51,15 @@ export const Forcemerge: React.FunctionComponent<Props> = ({
title={
<h3>
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.warmPhase.forceMergeDataText"
id="xpack.indexLifecycleMgmt.editPolicy.forceMerge.enableText"
defaultMessage="Force merge"
/>
</h3>
}
description={
<EuiTextColor color="subdued">
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.warmPhase.forceMergeDataExplanationText"
id="xpack.indexLifecycleMgmt.editPolicy.forceMerge.enableExplanationText"
defaultMessage="Reduce the number of segments in your shard by merging smaller files and clearing deleted ones."
/>{' '}
<LearnMoreLink docPath="indices-forcemerge.html" />
Expand All @@ -73,23 +82,43 @@ export const Forcemerge: React.FunctionComponent<Props> = ({
<EuiSpacer />
<div id="forcemergeContent" aria-live="polite" role="region">
{phaseData.forceMergeEnabled ? (
<ErrableFormRow
id={`${phase}-selectedForceMergeSegments`}
label={i18n.translate('xpack.indexLifecycleMgmt.warmPhase.numberOfSegmentsLabel', {
defaultMessage: 'Number of segments',
})}
isShowingErrors={isShowingErrors}
errors={errors?.selectedForceMergeSegments}
>
<EuiFieldNumber
data-test-subj={`${phase}-selectedForceMergeSegments`}
value={phaseData.selectedForceMergeSegments}
onChange={(e) => {
setPhaseData('selectedForceMergeSegments', e.target.value);
}}
min={1}
/>
</ErrableFormRow>
<>
<ErrableFormRow
id={`${phase}-selectedForceMergeSegments`}
label={i18n.translate('xpack.indexLifecycleMgmt.forceMerge.numberOfSegmentsLabel', {
defaultMessage: 'Number of segments',
})}
isShowingErrors={isShowingErrors}
errors={errors?.selectedForceMergeSegments}
>
<EuiFieldNumber
data-test-subj={`${phase}-selectedForceMergeSegments`}
value={phaseData.selectedForceMergeSegments}
onChange={(e) => {
setPhaseData('selectedForceMergeSegments', e.target.value);
}}
min={1}
/>
</ErrableFormRow>
<EuiFormRow
hasEmptyLabelSpace
helpText={
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.forceMerge.bestCompressionText"
defaultMessage="Use higher compression for stored fields at the cost of slower performance."
/>
}
>
<EuiSwitch
data-test-subj={`${phase}-bestCompression`}
label={bestCompressionLabel}
checked={phaseData.bestCompressionEnabled}
onChange={(e) => {
setPhaseData('bestCompressionEnabled', e.target.checked);
}}
/>
</EuiFormRow>
</>
) : null}
</div>
</EuiDescribedFormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { determineDataTierAllocationType } from '../../lib';
import { serializePhaseWithAllocation } from './shared';

const coldPhaseInitialization: ColdPhase = {
export const coldPhaseInitialization: ColdPhase = {
phaseEnabled: false,
selectedMinimumAge: '0',
selectedMinimumAgeUnits: 'd',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const hotPhaseInitialization: HotPhase = {
selectedMaxSizeStoredUnits: 'gb',
forceMergeEnabled: false,
selectedForceMergeSegments: '',
bestCompressionEnabled: false,
phaseIndexPriority: '',
selectedMaxDocuments: '',
};
Expand Down Expand Up @@ -64,6 +65,8 @@ export const hotPhaseFromES = (phaseSerialized?: SerializedHotPhase): HotPhase =
const forcemerge = actions.forcemerge;
phase.forceMergeEnabled = true;
phase.selectedForceMergeSegments = forcemerge.max_num_segments.toString();
// only accepted value for index_codec
phase.bestCompressionEnabled = forcemerge.index_codec === 'best_compression';
}

if (actions.set_priority) {
Expand Down Expand Up @@ -105,6 +108,10 @@ export const hotPhaseToES = (
esPhase.actions.forcemerge = {
max_num_segments: parseInt(phase.selectedForceMergeSegments, 10),
};
if (phase.bestCompressionEnabled) {
// only accepted value for index_codec
esPhase.actions.forcemerge.index_codec = 'best_compression';
}
} else {
delete esPhase.actions.forcemerge;
}
Expand Down
Loading

0 comments on commit dcb646d

Please sign in to comment.