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

Improve error handling for epoch format parser with time zone (#22621) #23689

Merged
merged 4 commits into from
Mar 28, 2017
Merged

Improve error handling for epoch format parser with time zone (#22621) #23689

merged 4 commits into from
Mar 28, 2017

Conversation

sneivandt
Copy link
Contributor

@sneivandt sneivandt commented Mar 22, 2017

Change the error response when using a non UTC timezone for range queries with epoch_millis or epoch_second formats to an illegal argument exception. The goal is to provide a better explanation of why the query has failed. The current behavior is to respond with a parse exception.

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@cbuescher
Copy link
Member

Thanks for the PR, after a first quick glance this already looks good, but can you add some unit tests that trigger those exceptions?

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@sneivandt thanks, this looks good and will only need a bit of reformatting to pass our checkstyle rules before I start a CI run.

if (bucket.getZone() != DateTimeZone.UTC) {
String format = hasMilliSecondPrecision ? "epoch_millis" : "epoch_second";
throw new IllegalArgumentException("time_zone must be UTC for format [" + format + "]");
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: can you move up the else block to this line?

FormatDateTimeFormatter formatter = new FormatDateTimeFormatter("epoch_seconds", new DateTimeFormatterBuilder().append(new Joda.EpochTimeParser(false)).toFormatter().withZone(zone), Locale.ROOT);
try {
formatter.parser().parseDateTime("1433144433655");
fail("Expected IllegalArgumentException");
Copy link
Member

Choose a reason for hiding this comment

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

Just as a note, LuceneTestCase (which we inherit from) offers a nice helper to shorten these try/catch constructs, it goes something like this:

IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ...do Something...);
assertThat(... some assertions about e...);

I see that the rest of this test also still uses try/catch for most exception tests. This is okay as it is, I just wanted to mention it.

@@ -314,6 +314,28 @@ public void testForInvalidDatesInEpochMillis() {
}
}

public void testForInvalidTimeZoneWithEpochSeconds() {
DateTimeZone zone = DateTimeZone.forOffsetHours(1);
FormatDateTimeFormatter formatter = new FormatDateTimeFormatter("epoch_seconds", new DateTimeFormatterBuilder().append(new Joda.EpochTimeParser(false)).toFormatter().withZone(zone), Locale.ROOT);
Copy link
Member

Choose a reason for hiding this comment

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

The length of this line will trigger our checkstyle rules once we run the tests, we were at 140 characters (still applies to this test class) and recently moved to 100. Can you shorten this before I kick of the first CI run?

@cbuescher
Copy link
Member

@elasticmachine test this please

@cbuescher cbuescher changed the title Error handeling for epoch format range queries (#22621) Improve error handling for epoch format parser with time zone (#22621) Mar 28, 2017
@cbuescher
Copy link
Member

thanks a lot, I changed the title slightly and will merge this.

@cbuescher cbuescher merged commit 3caf887 into elastic:master Mar 28, 2017
cbuescher pushed a commit that referenced this pull request Mar 28, 2017
Change the error response when using a non UTF timezone for range queries with epoch_millis
or epoch_second formats to an illegal argument exception. The goal is to provide a better 
explanation of why the query has failed. The current behavior is to respond with a parse exception.

Closes #22621
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Mar 28, 2017
* master: (2923 commits)
  Add 5.3.0 version for packaging tests
  Require explicit query in _delete_by_query API (elastic#23632)
  Adds boolean similarity to Elasticsearch (elastic#23637)
  Revert "Skip 5.4 bwc test for new name for now"
  Improve error handling for epoch format parser with time zone (elastic#23689)
  Docs: fix health response test
  Docs: Clean up response test in getting_started
  Validate top-level keys when parsing mget requests
  Reflect cross-cluster search in "dedicated" terminology (elastic#23771)
  Fix serialization for plugin info
  Update contributing docs for line-length change
  Remove line-length violations in SmokeTestClientIT
  Reenable smoke test client tests on JDK 9
  Build: Use GradleBuild task for invoking 5.x checkout build (elastic#23770)
  Introduce translog generation rolling
  Modify permissions dialog for plugins
  FuzzyQueryBuilder should error when parsing array of values (elastic#23762)
  Remove obsolete index setting `index.version.minimum_compatible`. (elastic#23593)
  Upgrade to Lucene 6.5.0 (elastic#23750)
  Fix docs for plugin install via proxy on Windows
  ...
@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@clintongormley clintongormley added :Search Foundations/Mapping Index mappings, including merging and defining field types and removed :Dates labels Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types v5.4.0 v6.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants