Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable TSDB downsampling ILM configuration #138748

Merged
merged 14 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,130 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding these tests 👍

* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { act } from 'react-dom/test-utils';
import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts';

import { PhaseWithDownsample } from '../../../../common/types';
import { setupEnvironment } from '../../helpers';
import { setupValidationTestBed, ValidationTestBed } from './validation.helpers';

describe('<EditPolicy /> downsample interval validation', () => {
let testBed: ValidationTestBed;
let actions: ValidationTestBed['actions'];
const { httpSetup, httpRequestsMockHelpers } = setupEnvironment();

beforeAll(() => {
jest.useFakeTimers();
});

afterAll(() => {
jest.useRealTimers();
});

beforeEach(async () => {
httpRequestsMockHelpers.setDefaultResponses();
httpRequestsMockHelpers.setLoadPolicies([]);

await act(async () => {
testBed = await setupValidationTestBed(httpSetup);
});

const { component } = testBed;
component.update();
({ actions } = testBed);
await actions.setPolicyName('mypolicy');
});

[
{
name: `doesn't allow empty interval`,
value: '',
error: [i18nTexts.editPolicy.errors.numberRequired],
},
{
name: `doesn't allow 0 for interval`,
value: '0',
error: [i18nTexts.editPolicy.errors.numberGreatThan0Required],
},
{
name: `doesn't allow -1 for interval`,
value: '-1',
error: [i18nTexts.editPolicy.errors.numberGreatThan0Required],
},
{
name: `doesn't allow decimals for timing (with dot)`,
value: '5.5',
error: [i18nTexts.editPolicy.errors.integerRequired],
},
{
name: `doesn't allow decimals for timing (with comma)`,
value: '5,5',
error: [i18nTexts.editPolicy.errors.integerRequired],
},
].forEach((testConfig: { name: string; value: string; error: string[] }) => {
(['hot', 'warm', 'cold'] as PhaseWithDownsample[]).forEach((phase: PhaseWithDownsample) => {
const { name, value, error } = testConfig;
test(`${phase}: ${name}`, async () => {
if (phase !== 'hot') {
await actions.togglePhase(phase);
}

await actions[phase].downsample.toggle();

// 1. We first set as dummy value to have a starting min_age value
await actions[phase].downsample.setDownsampleInterval('111');
// 2. At this point we are sure there will be a change of value and that any validation
// will be displayed under the field.
await actions[phase].downsample.setDownsampleInterval(value);

actions.errors.waitForValidation();

actions.errors.expectMessages(error);
});
});
});

test('should validate an interval is greater or multiple than previous phase interval', async () => {
await actions.togglePhase('warm');
await actions.togglePhase('cold');

await actions.hot.downsample.toggle();
await actions.hot.downsample.setDownsampleInterval('60', 'm');

await actions.warm.downsample.toggle();
await actions.warm.downsample.setDownsampleInterval('1', 'h');

actions.errors.waitForValidation();
actions.errors.expectMessages(
['Must be greater than and a multiple of the hot phase value (60m)'],
'warm'
);

await actions.cold.downsample.toggle();
await actions.cold.downsample.setDownsampleInterval('90', 'm');
actions.errors.waitForValidation();
actions.errors.expectMessages(
['Must be greater than and a multiple of the warm phase value (1h)'],
'cold'
);

// disable warm phase;
await actions.togglePhase('warm');
// TODO: there is a bug that disabling a phase doesn't trigger downsample validation in other phases,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a separate issue open to address this? Will the validation work as expected on save?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will the validation work as expected on saving?

Yes! the form state stays in the error state until the validation is triggered again.
More details on the case here: #138748 (comment)

note: there is the following edge case:
Have the warm downsample action enabled and set 1d
Have the cold downsample action enabled and set 1d -> see the error
Disable the warm step completely -> error on cold downsample action is still there > until triggering change or saving.
To fix this, we need to validate downsample actions when steps are toggled. But I thought this is an overkill for this edge case.

Is there a separate issue open to address this?

I wanted to leave a TODO comment to point this out as a known bug/edge case but didn't think this was worth an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll see if I can fix this with low effort: #140628

// users can work around it by changing the value
await actions.cold.downsample.setDownsampleInterval('120', 'm');
actions.errors.waitForValidation();
actions.errors.expectMessages([], 'cold');

await actions.cold.downsample.setDownsampleInterval('90', 'm');
actions.errors.waitForValidation();
actions.errors.expectMessages(
['Must be greater than and a multiple of the hot phase value (60m)'],
'cold'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ describe('<EditPolicy /> serialization', () => {
await actions.hot.setShrinkCount('2');
await actions.hot.toggleReadonly();
await actions.hot.setIndexPriority('123');
await actions.hot.downsample.toggle();
await actions.hot.downsample.setDownsampleInterval('2', 'h');

await actions.savePolicy();

Expand Down Expand Up @@ -231,6 +233,7 @@ describe('<EditPolicy /> serialization', () => {
priority: 123,
},
readonly: {},
downsample: { fixed_interval: '2h' },
},
},
},
Expand Down Expand Up @@ -323,6 +326,8 @@ describe('<EditPolicy /> serialization', () => {
await actions.warm.setBestCompression(true);
await actions.warm.toggleReadonly();
await actions.warm.setIndexPriority('123');
await actions.warm.downsample.toggle();
await actions.warm.downsample.setDownsampleInterval('20', 'm');
await actions.savePolicy();

expect(httpSetup.post).toHaveBeenLastCalledWith(
Expand Down Expand Up @@ -360,6 +365,7 @@ describe('<EditPolicy /> serialization', () => {
number_of_replicas: 123,
},
readonly: {},
downsample: { fixed_interval: '20m' },
},
},
},
Expand Down Expand Up @@ -463,6 +469,8 @@ describe('<EditPolicy /> serialization', () => {
await actions.cold.setReplicas('123');
await actions.cold.toggleReadonly();
await actions.cold.setIndexPriority('123');
await actions.cold.downsample.toggle();
await actions.cold.downsample.setDownsampleInterval('5');

await actions.savePolicy();

Expand Down Expand Up @@ -494,6 +502,7 @@ describe('<EditPolicy /> serialization', () => {
number_of_replicas: 123,
},
readonly: {},
downsample: { fixed_interval: '5d' },
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { TestBed } from '@kbn/test-jest-helpers';
import { act } from 'react-dom/test-utils';
import { Phase } from '../../../../common/types';
import { createFormToggleAction } from '..';

const createSetDownsampleIntervalAction =
(testBed: TestBed, phase: Phase) => async (value: string, units?: string) => {
const { find, component } = testBed;

await act(async () => {
find(`${phase}-downsampleFixedInterval`).simulate('change', { target: { value } });
});
component.update();

if (units) {
act(() => {
find(`${phase}-downsampleFixedIntervalUnits.show-filters-button`).simulate('click');
});
component.update();

act(() => {
find(`${phase}-downsampleFixedIntervalUnits.filter-option-${units}`).simulate('click');
});
component.update();
}
};

export const createDownsampleActions = (testBed: TestBed, phase: Phase) => {
const { exists } = testBed;
return {
downsample: {
exists: () => exists(`${phase}-downsampleSwitch`),
toggle: createFormToggleAction(testBed, `${phase}-downsampleSwitch`),
setDownsampleInterval: createSetDownsampleIntervalAction(testBed, phase),
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export { createForceMergeActions } from './forcemerge_actions';
export { createReadonlyActions } from './readonly_actions';
export { createIndexPriorityActions } from './index_priority_actions';
export { createShrinkActions } from './shrink_actions';
export { createDownsampleActions } from './downsample_actions';
export {
createHotPhaseActions,
createWarmPhaseActions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
createNodeAllocationActions,
createReplicasAction,
createSnapshotPolicyActions,
createDownsampleActions,
} from '.';

export const createHotPhaseActions = (testBed: TestBed) => {
Expand All @@ -26,6 +27,7 @@ export const createHotPhaseActions = (testBed: TestBed) => {
...createReadonlyActions(testBed, 'hot'),
...createIndexPriorityActions(testBed, 'hot'),
...createSearchableSnapshotActions(testBed, 'hot'),
...createDownsampleActions(testBed, 'hot'),
},
};
};
Expand All @@ -39,6 +41,7 @@ export const createWarmPhaseActions = (testBed: TestBed) => {
...createIndexPriorityActions(testBed, 'warm'),
...createNodeAllocationActions(testBed, 'warm'),
...createReplicasAction(testBed, 'warm'),
...createDownsampleActions(testBed, 'warm'),
},
};
};
Expand All @@ -51,6 +54,7 @@ export const createColdPhaseActions = (testBed: TestBed) => {
...createIndexPriorityActions(testBed, 'cold'),
...createNodeAllocationActions(testBed, 'cold'),
...createSearchableSnapshotActions(testBed, 'cold'),
...createDownsampleActions(testBed, 'cold'),
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export type PhaseWithTiming = keyof Omit<Phases, 'hot'>;

export type PhaseExceptDelete = keyof Omit<Phases, 'delete'>;

export type PhaseWithDownsample = 'hot' | 'warm' | 'cold';

export interface SerializedPolicy {
name: string;
phases: Phases;
Expand Down Expand Up @@ -93,6 +95,7 @@ export interface SerializedHotPhase extends SerializedPhase {
forcemerge?: ForcemergeAction;
readonly?: {};
shrink?: ShrinkAction;
downsample?: DownsampleAction;

set_priority?: {
priority: number | null;
Expand All @@ -110,6 +113,7 @@ export interface SerializedWarmPhase extends SerializedPhase {
shrink?: ShrinkAction;
forcemerge?: ForcemergeAction;
readonly?: {};
downsample?: DownsampleAction;
set_priority?: {
priority: number | null;
};
Expand All @@ -121,6 +125,7 @@ export interface SerializedColdPhase extends SerializedPhase {
actions: {
freeze?: {};
readonly?: {};
downsample?: DownsampleAction;
allocate?: AllocateAction;
set_priority?: {
priority: number | null;
Expand Down Expand Up @@ -178,6 +183,10 @@ export interface ForcemergeAction {
index_codec?: 'best_compression';
}

export interface DownsampleAction {
fixed_interval: string;
}

export interface LegacyPolicy {
name: string;
phases: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
IndexPriorityField,
ReplicasField,
ReadonlyField,
DownsampleField,
} from '../shared_fields';

import { Phase } from '../phase';
Expand All @@ -38,6 +39,8 @@ export const ColdPhase: FunctionComponent = () => {
{/* Readonly section */}
{!isUsingSearchableSnapshotInHotPhase && <ReadonlyField phase="cold" />}

{!isUsingSearchableSnapshotInHotPhase && <DownsampleField phase="cold" />}

{/* Data tier allocation section */}
<DataTierAllocationField
description={i18nTexts.dataTierAllocation.description}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
SearchableSnapshotField,
ReadonlyField,
ShrinkField,
DownsampleField,
} from '../shared_fields';
import { Phase } from '../phase';

Expand Down Expand Up @@ -176,6 +177,7 @@ export const HotPhase: FunctionComponent = () => {
<ShrinkField phase={'hot'} />
{license.canUseSearchableSnapshot() && <SearchableSnapshotField phase="hot" />}
<ReadonlyField phase={'hot'} />
<DownsampleField phase="hot" />
</>
)}
<IndexPriorityField phase={'hot'} />
Expand Down
Loading