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

Kibana should allow a min_age setting of 0ms in ILM policy phases #53719

Merged
merged 14 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -131,7 +131,7 @@ export const MinAgeInput = props => {
onChange={async e => {
setPhaseData(PHASE_ROLLOVER_MINIMUM_AGE, e.target.value);
}}
min={1}
min={0}
/>
</ErrableFormRow>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export const positiveNumbersAboveZeroErrorMessage = i18n.translate(
}
);

export const positiveNumbersEqualAboveZeroErrorMessage =
i18n.translate('xpack.indexLifecycleMgmt.editPolicy.positiveNumberAboveZeroRequiredError', {
defaultMessage: 'Only numbers equal to or above 0 are allowed.'
});

export const validatePhase = (type, phase, errors) => {
const phaseErrors = {};

Expand Down Expand Up @@ -123,11 +128,12 @@ export const validatePhase = (type, phase, errors) => {
} else if (
Copy link
Contributor

Choose a reason for hiding this comment

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

I was looking through the code again, and I'm wondering if this block of code is necessary. I don't think it will ever reach this point, as we're already checking for negative numbers on L121.

} else if (phase[numberedAttribute] < 0) {
  phaseErrors[numberedAttribute] = [positiveNumberRequiredMessage];
}

Can you confirm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will reach this point. Initially I thought the negative numbers on L121 would have caught it too, but it didn't.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you share how you were testing it to reach this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, no problem. Initially I set <=0

} else if (phase[numberedAttribute] <= 0) {
  phaseErrors[numberedAttribute] = [positiveNumberRequiredMessage];
}

This will generate an error when I enter 0 through the Index Lifecycle Policy cold phase page. It was still not permitting 0. When I set < 0

} else if (phase[numberedAttribute] < 0) {
  phaseErrors[numberedAttribute] = [positiveNumberRequiredMessage];
}

I will not get an error when I enter 0 on the ILP page on the cold phase. Then when I run the jest test I will get a received error of 0 as 0 is now a valid value, but I will get anexpected error of 1.

expect(received).toBe(expected) // Object.is equality
    Expected: 1
    Received: 0
      74 | const expectedErrorMessages = (rendered, expectedErrorMessages) => {
      75 |   const errorMessages = rendered.find('.euiFormErrorText');
    > 76 |   expect(errorMessages.length).toBe(expectedErrorMessages.length);
         |                                ^
      77 |   expectedErrorMessages.forEach(expectedErrorMessage => {
      78 |     let foundErrorMessage;
      79 |     for (let i = 0; i < errorMessages.length; i++) {

Therefore, I edited the jest test case to allow no error to be returned by setting as the value 0 is permitted now

expectedErrorMessages(rendered, [])

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I wasn't very clear in my comment. I was referring to your statement:

Initially I thought the negative numbers on L121 would have caught it too, but it didn't.

I was wondering what steps you were taking in the UI to reach this point. I am not able to reproduce.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, my misunderstanding. Fixed the issue now.

(numberedAttribute === PHASE_ROLLOVER_MINIMUM_AGE ||
numberedAttribute === PHASE_PRIMARY_SHARD_COUNT) &&
phase[numberedAttribute] < 1
phase[numberedAttribute] < 0
) {
phaseErrors[numberedAttribute] = [positiveNumbersAboveZeroErrorMessage];
phaseErrors[numberedAttribute] = [positiveNumbersEqualAboveZeroErrorMessage];
}
}

}
if (phase[PHASE_ROLLOVER_ENABLED]) {
if (
Expand Down Expand Up @@ -161,6 +167,7 @@ export const validatePhase = (type, phase, errors) => {
}

if (phase[PHASE_FORCE_MERGE_ENABLED]) {

if (!isNumber(phase[PHASE_FORCE_MERGE_SEGMENTS])) {
phaseErrors[PHASE_FORCE_MERGE_SEGMENTS] = [numberRequiredMessage];
} else if (phase[PHASE_FORCE_MERGE_SEGMENTS] < 1) {
Expand Down