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

[SR] Support capitalized date formats in snapshot names #53751

Merged
merged 23 commits into from
Jan 13, 2020

Conversation

jkelastic
Copy link
Contributor

@jkelastic jkelastic commented Dec 22, 2019

Release note

Snapshot names that contain date math may require capital letters, e.g. "<snapshot-{now/d{yyyy.MM.dd|+09:00}}>". This change fixes a bug in which the UI rejected snapshot names containing capital letters by scoping this validation to only the name part of this pattern, ignoring the date math part.

Summary

Fixed 51857

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@jkelastic jkelastic added release_note:fix v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more Feature:Snapshot and Restore Elasticsearch snapshots and repositories UI v7.6.0 labels Dec 22, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

@jkelastic
Copy link
Contributor Author

It looks the top three commits with X are from another feature fix and included in this branch, was I suppose to clear the git log or previous commits?

Screen Shot 2019-12-21 at 5 38 58 PM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jkelastic jkelastic force-pushed the bugfix/Snapshot_restore branch from dce230c to 0fa149b Compare December 27, 2019 22:23
@jkelastic
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@@ -347,7 +347,7 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
onChange={e => {
updatePolicy(
{
snapshotName: e.target.value.toLowerCase(),
snapshotName: e.target.value,
Copy link
Contributor

Choose a reason for hiding this comment

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

@jkelastic I think we are on the right track with the proposed changes, I would just like to know what the reason was that we .toLowerCase()ed originally? Did we just never need to take this extra step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jloleysens yes, we never need to take this step as .toLowerCase() on date format will negate MM to mm. The uppercase matters as MM is month and mm is minutes.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jkelastic see @alisonelizabeth 's comment below, it looks like we need to keep the names lowercase :)

@jkelastic
Copy link
Contributor Author

@elasticmachine merge upstream

@jkelastic
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@alisonelizabeth alisonelizabeth left a comment

Choose a reason for hiding this comment

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

@jkelastic nice job with this! Tested locally and verified fix.

In addition to this change, I think it would be great if we could be a little more robust with the client validation. A snapshot name must be lowercase, however, the date math expression should be able to accept upper and lowercase letters.

For example, with your current change, I can create a snapshot name in the UI like so: MY_SNAPSHOT or <SNAPSHOT-{now/d{yyyy.MM.dd|+09:00}}>, but I get an error back from ES indicating that the name must be lowercase. I think it would be ideal if we could check for this on the client, before the user tries to submit the form.

@cjcenizal
Copy link
Contributor

@elasticmachine merge upstream

@jkelastic
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

It looks like changes from #53757 snuck in here :(

This is the offending commit: 3c5ffaa

One thing we can do is to re-target this PR to your watcher PR and merge watcher first then this (once both are approved). Alternatively you can checkout one commit before ☝️ and cherry-pick the changes intended for SR. Up to you!

Actually, I'd recommend we just wait until #53757 is merged first.

const isSnapshotNameLowerCase = (str: string): boolean => {
const strExcludeDate =
str.substring(0, str.search('{')) + str.substring(str.search('}}') + 2, str.length);
return strExcludeDate !== strExcludeDate.toLowerCase() ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be simplified to:

Suggested change
return strExcludeDate !== strExcludeDate.toLowerCase() ? true : false;
return strExcludeDate !== strExcludeDate.toLowerCase();

Copy link
Contributor

@jloleysens jloleysens Jan 10, 2020

Choose a reason for hiding this comment

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

Additionally, given the boolean check this function name (isSnapshotNameLowerCase) is misleading. Either the name should be isSnapshotNameNotLowerCase or we should change !== to === and update the if logic on L70.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Additionally, given the boolean check this function name (isSnapshotNameLowerCase) is misleading. Either the name should be isSnapshotNameNotLowerCase or we should change !== to === and update the if logic on L70.

Thanks Jean for the advice. I've changed the name to isSnapshotNameNotLowerCase and simplified the return strExcludeDate condition

@@ -15,6 +15,12 @@ const isStringEmpty = (str: string | null): boolean => {
return str ? !Boolean(str.trim()) : true;
};

const isSnapshotNameLowerCase = (str: string): boolean => {
const strExcludeDate =
str.substring(0, str.search('{')) + str.substring(str.search('}}') + 2, str.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the double }} intended? At the moment the validation only passes when I add a trailing }. Resulting in:

Screenshot 2020-01-10 at 15 54 58

Copy link
Contributor

@jloleysens jloleysens Jan 10, 2020

Choose a reason for hiding this comment

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

A comment explaining this logic would also be great :) - something about the what the string may contain or is expected to look like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the double }} intended? At the moment the validation only passes when I add a trailing }. Resulting in:

Screenshot 2020-01-10 at 15 54 58

The }} was intended. However, I think I've over analyzed date format syntax and should just check for } because all date format will have one { and } and not all have }}

A comment explaining this logic would also be great :) - something about the what the string may contain or is expected to look like.

Will do, I will put it in the code

@jkelastic
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

I'm happy for this to be merged if you've tested that with the current validation we can create snapshot policies 👍.

@alisonelizabeth
Copy link
Contributor

@elasticmachine merge upstream

@cjcenizal cjcenizal changed the title [SR] Snapshot name forced to lowercase [SR] Support capitalized date formats in snapshot names Jan 13, 2020
@cjcenizal cjcenizal merged commit 79ee978 into elastic:master Jan 13, 2020
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cjcenizal added a commit that referenced this pull request Jan 13, 2020
)

Snapshot names that contain date math may require capital letters, e.g. "<snapshot-{now/d{yyyy.MM.dd|+09:00}}>". This change fixes a bug which complained that capital letters are not allowed in snapshot names, by scoping this validation to only the name part of this pattern, ignoring the date math part.

Co-authored-by: Jimmy Kuang <[email protected]>
@cjcenizal cjcenizal added v7.5.2 and removed v7.5.2 labels Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Snapshot and Restore Elasticsearch snapshots and repositories UI release_note:fix Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SR] Snapshot name forced to lowercase
6 participants