-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
Pinging @elastic/es-ui (Team:Elasticsearch UI) |
💚 Build Succeeded
To update your PR or re-run it, just comment with: |
dce230c
to
0fa149b
Compare
@elasticmachine merge upstream |
💚 Build SucceededTo update your PR or re-run it, just comment with: |
@@ -347,7 +347,7 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({ | |||
onChange={e => { | |||
updatePolicy( | |||
{ | |||
snapshotName: e.target.value.toLowerCase(), | |||
snapshotName: e.target.value, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
@elasticmachine merge upstream |
@elasticmachine merge upstream |
There was a problem hiding this 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.
…into bugfix/Snapshot_restore
@elasticmachine merge upstream |
@elasticmachine merge upstream |
There was a problem hiding this 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified to:
return strExcludeDate !== strExcludeDate.toLowerCase() ? true : false; | |
return strExcludeDate !== strExcludeDate.toLowerCase(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 beisSnapshotNameNotLowerCase
or we should change!==
to===
and update theif
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
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
@elasticmachine merge upstream |
There was a problem hiding this 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 👍.
@elasticmachine merge upstream |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
) 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]>
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
strikethroughsto remove checklist items you don't feel are applicable to this PR.For maintainers