Skip to content

Commit

Permalink
Deprecation info for joda-java migration (#41956)
Browse files Browse the repository at this point in the history
Implement deprecation checks for joda-java.time incompatible patterns. The checks scan through indicies and pipelines looking for date fields in mappings and processors which might fail in 7.0 where java.time is used.

relates #42010
  • Loading branch information
pgomulka authored May 29, 2019
1 parent 37134e8 commit 728c5d1
Show file tree
Hide file tree
Showing 27 changed files with 1,067 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
import static org.hamcrest.core.IsEqual.equalTo;

public class DateFormatTests extends ESTestCase {
@Override
protected boolean enableJodaDeprecationWarningsCheck() {
return true;
}

public void testParseJoda() {
Function<String, DateTime> jodaFunction = DateFormat.Java.getFunction("MMM dd HH:mm:ss Z",
Expand All @@ -44,6 +48,8 @@ public void testParseJoda() {
.atZone(ZoneId.of("GMT-8"))
.format(DateTimeFormatter.ofPattern("MM dd HH:mm:ss", Locale.ENGLISH)),
equalTo("11 24 01:29:01"));
assertWarnings("'Z' time zone offset/id fails when parsing 'Z' for Zulu timezone. Consider using 'X'. " +
"Prefix your date format with '8' to use the new specifier.");
}

public void testParseJodaDefaultYear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
import static org.hamcrest.Matchers.is;

public class DateIndexNameProcessorTests extends ESTestCase {
@Override
protected boolean enableJodaDeprecationWarningsCheck() {
return true;
}

public void testJodaPattern() throws Exception {
Function<String, DateTime> function = DateFormat.Java.getFunction("yyyy-MM-dd'T'HH:mm:ss.SSSZ", DateTimeZone.UTC, Locale.ROOT);
Expand All @@ -43,6 +47,11 @@ public void testJodaPattern() throws Exception {
Collections.singletonMap("_field", "2016-04-25T12:24:20.101Z"));
processor.execute(document);
assertThat(document.getSourceAndMetadata().get("_index"), equalTo("<events-{20160425||/y{yyyyMMdd|UTC}}>"));
assertWarnings("'y' year should be replaced with 'u'. Use 'y' for year-of-era.; " +
"'Z' time zone offset/id fails when parsing 'Z' for Zulu timezone. Consider using 'X'. " +
"Prefix your date format with '8' to use the new specifier.",
"'y' year should be replaced with 'u'. Use 'y' for year-of-era. " +
"Prefix your date format with '8' to use the new specifier.");
}

public void testTAI64N()throws Exception {
Expand All @@ -53,6 +62,8 @@ public void testTAI64N()throws Exception {
Collections.singletonMap("_field", (randomBoolean() ? "@" : "") + "4000000050d506482dbdf024"));
dateProcessor.execute(document);
assertThat(document.getSourceAndMetadata().get("_index"), equalTo("<events-{20121222||/m{yyyyMMdd|UTC}}>"));
assertWarnings("'y' year should be replaced with 'u'. Use 'y' for year-of-era. " +
"Prefix your date format with '8' to use the new specifier.");
}

public void testUnixMs()throws Exception {
Expand All @@ -68,6 +79,8 @@ public void testUnixMs()throws Exception {
Collections.singletonMap("_field", 1000500L));
dateProcessor.execute(document);
assertThat(document.getSourceAndMetadata().get("_index"), equalTo("<events-{19700101||/m{yyyyMMdd|UTC}}>"));
assertWarnings("'y' year should be replaced with 'u'. Use 'y' for year-of-era. " +
"Prefix your date format with '8' to use the new specifier.");
}

public void testUnix()throws Exception {
Expand All @@ -78,6 +91,8 @@ public void testUnix()throws Exception {
Collections.singletonMap("_field", "1000.5"));
dateProcessor.execute(document);
assertThat(document.getSourceAndMetadata().get("_index"), equalTo("<events-{19700101||/m{yyyyMMdd|UTC}}>"));
assertWarnings("'y' year should be replaced with 'u'. Use 'y' for year-of-era. " +
"Prefix your date format with '8' to use the new specifier.");
}

public void testTemplatedFields() throws Exception {
Expand All @@ -98,6 +113,14 @@ public void testTemplatedFields() throws Exception {
assertThat(document.getSourceAndMetadata().get("_index"),
equalTo("<"+indexNamePrefix+"{"+DateTimeFormat.forPattern(indexNameFormat)
.print(dateTimeFunction.apply(date))+"||/"+dateRounding+"{"+indexNameFormat+"|UTC}}>"));
if (indexNameFormat.equals("yyyy-MM-dd'T'HH:mm:ss.SSSZ")) {
assertWarnings("'y' year should be replaced with 'u'. Use 'y' for year-of-era.; " +
"'Z' time zone offset/id fails when parsing 'Z' for Zulu timezone. Consider using 'X'. " +
"Prefix your date format with '8' to use the new specifier.");
} else {
assertWarnings("'y' year should be replaced with 'u'. Use 'y' for year-of-era. " +
"Prefix your date format with '8' to use the new specifier.");
}
}

public void testJodaTimeDeprecation() throws Exception {
Expand All @@ -112,10 +135,11 @@ public void testJodaTimeDeprecation() throws Exception {
Collections.singletonMap("_field", date));
dateProcessor.execute(document);

assertWarnings("Use of 'Y' (year-of-era) will change to 'y' in the next major version of Elasticsearch." +
" Prefix your date format with '8' to use the new specifier.");
assertThat(document.getSourceAndMetadata().get("_index"),
is("<foo-{2019-01-31T12:34:56.789+0000||/M{" + indexNameFormat + "|UTC}}>"));
assertWarnings("'Y' year-of-era should be replaced with 'y'. Use 'Y' for week-based-year.; " +
"'Z' time zone offset/id fails when parsing 'Z' for Zulu timezone. Consider using 'X'. " +
"Prefix your date format with '8' to use the new specifier.");
}

private DateIndexNameProcessor createProcessor(String field, List<Function<String, DateTime>> dateFormats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
import static org.hamcrest.CoreMatchers.equalTo;

public class DateProcessorTests extends ESTestCase {
@Override
protected boolean enableJodaDeprecationWarningsCheck() {
return true;
}

private TemplateScript.Factory templatize(Locale locale) {
return new TestTemplateService.MockTemplateScript.Factory(locale.getLanguage());
Expand All @@ -58,6 +62,8 @@ public void testJodaPattern() {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T11:05:15.000+02:00"));
assertWarnings("'y' year should be replaced with 'u'. Use 'y' for year-of-era. " +
"Prefix your date format with '8' to use the new specifier.");
}

public void testJodaPatternMultipleFormats() {
Expand Down Expand Up @@ -96,6 +102,8 @@ public void testJodaPatternMultipleFormats() {
} catch(IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("unable to parse date [2010]"));
}
assertWarnings("'y' year should be replaced with 'u'. Use 'y' for year-of-era. " +
"Prefix your date format with '8' to use the new specifier.");
}

public void testInvalidJodaPattern() {
Expand Down Expand Up @@ -124,6 +132,8 @@ public void testJodaPatternLocale() {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
assertWarnings("'y' year should be replaced with 'u'. Use 'y' for year-of-era. " +
"Prefix your date format with '8' to use the new specifier.");
}

public void testJodaPatternDefaultYear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

- do:
warnings:
- "Use of 'Y' (year-of-era) will change to 'y' in the next major version of Elasticsearch. Prefix your date format with '8' to use the new specifier."
- "'Y' year-of-era should be replaced with 'y'. Use 'Y' for week-based-year. Prefix your date format with '8' to use the new specifier."
index:
index: test
type: test
Expand Down
Loading

0 comments on commit 728c5d1

Please sign in to comment.