-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Validate index name time format setting at parse time #47911
Validate index name time format setting at parse time #47911
Conversation
Pinging @elastic/es-core-features (:Core/Features/Monitoring) |
Test fixed. |
public void validate(String value) { | ||
try { | ||
DateFormatter.forPattern(value).withZone(ZoneOffset.UTC); | ||
} catch (IllegalArgumentException e) { |
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 would suggest to open this up to catch RuntimeException so that validation (not cluster state application) catches the error.
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.
request to be more aggressive in what the validation catches.
@elasticmachine run elasticsearch-ci/2 |
@jakelandis, I think this one is ready for another look. |
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.
LGTM
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.
One question
public void validate(String value) { | ||
try { | ||
if (value != null) { | ||
DateFormatter.forPattern(value).withZone(ZoneOffset.UTC); |
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 generic type for this AffixSetting wrong? It seems like if we are going to parse into a DateFormatter, we should be doing that once, not duplicating here and in Exporter.dateTimeFormatter (where it also looks like we have default value logic?).
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.
@rjernst, it is true that a DateFormatter
instance is ultimately what is produced for this setting. I could change INDEX_NAME_TIME_FORMAT_SETTING
from its original AffixSetting<String>
to a AffixSetting<DateFormatter>
if that would be preferable.
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 think that makes the most sense. In general, a major goal of the settings infrastructure is to do type parsing and validation for the intended type. In this case it seems we are adding checking, but the parsing isn't actually happening within the Setting instance.
@elasticmachine update branch |
@rjernst, I've updated this to be an |
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.
LGTM
Provides parse-time validation for
INDEX_NAME_TIME_FORMAT_SETTING
as described in #47711.