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

Validate index name time format setting at parse time #47911

Merged
merged 9 commits into from
Nov 5, 2019

Conversation

danhermann
Copy link
Contributor

Provides parse-time validation for INDEX_NAME_TIME_FORMAT_SETTING as described in #47711.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (:Core/Features/Monitoring)

@danhermann
Copy link
Contributor Author

danhermann commented Oct 11, 2019

Test fixed. The failing test here (https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java#L73) explicitly sets the index name time format to null which seems like it should be disallowed.

public void validate(String value) {
try {
DateFormatter.forPattern(value).withZone(ZoneOffset.UTC);
} catch (IllegalArgumentException e) {
Copy link
Contributor

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.

Copy link
Contributor

@jakelandis jakelandis left a 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.

@danhermann
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/2

@danhermann
Copy link
Contributor Author

@jakelandis, I think this one is ready for another look.

Copy link
Contributor

@jakelandis jakelandis left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@rjernst rjernst left a 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);
Copy link
Member

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?).

Copy link
Contributor Author

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.

Copy link
Member

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.

@danhermann
Copy link
Contributor Author

@elasticmachine update branch

@danhermann
Copy link
Contributor Author

@rjernst, I've updated this to be an AffixSetting<DateFormatter> which had the effect of simplifying the validation, too.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants