From 21f0263f5aa6f46c43a51cf4c17fdd87537be1c3 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 31 Jul 2018 10:43:25 -0700 Subject: [PATCH 1/6] Cat apis: Fix index creation time to use strict date format With the move to java time, the default formatter used by toString on ZonedDateTime uses optional components for least significant portions of the date. This commit changes the cat indices api to use a strict date time format, which will always output milliseconds, even if they are zero. closes #32466 --- .../elasticsearch/rest/action/cat/RestIndicesAction.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index 3a76c7ca0c952..2156795f8e210 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -39,6 +39,8 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.time.CompoundDateTimeFormatter; +import org.elasticsearch.common.time.DateFormatters; import org.elasticsearch.index.Index; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -49,6 +51,7 @@ import java.time.Instant; import java.time.ZoneOffset; import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -380,7 +383,8 @@ Table buildTable(RestRequest request, Index[] indices, ClusterHealthResponse res table.addCell(primaryStats.getDocs() == null ? null : primaryStats.getDocs().getDeleted()); table.addCell(indexMetaData.getCreationDate()); - table.addCell(ZonedDateTime.ofInstant(Instant.ofEpochMilli(indexMetaData.getCreationDate()), ZoneOffset.UTC)); + ZonedDateTime creationTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(indexMetaData.getCreationDate()), ZoneOffset.UTC); + table.addCell(DateFormatters.forPattern("strict_date_time").format(creationTime)); table.addCell(totalStats.getStore() == null ? null : totalStats.getStore().size()); table.addCell(primaryStats.getStore() == null ? null : primaryStats.getStore().size()); From 6f70b0562594f1e4176eee86fad2f544c4c104d0 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 31 Jul 2018 11:13:02 -0700 Subject: [PATCH 2/6] remove unused import --- .../org/elasticsearch/rest/action/cat/RestIndicesAction.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index 2156795f8e210..1a859933ad3fe 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -39,7 +39,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.time.CompoundDateTimeFormatter; import org.elasticsearch.common.time.DateFormatters; import org.elasticsearch.index.Index; import org.elasticsearch.rest.RestController; @@ -51,7 +50,6 @@ import java.time.Instant; import java.time.ZoneOffset; import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; From 832472608906475b7e7dd25afa6fc96d9c38942a Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 31 Jul 2018 16:37:22 -0700 Subject: [PATCH 3/6] use builtin datetimeformatter --- .../org/elasticsearch/rest/action/cat/RestIndicesAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index 1a859933ad3fe..ee84832b2bdcc 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -50,6 +50,7 @@ import java.time.Instant; import java.time.ZoneOffset; import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -382,7 +383,7 @@ Table buildTable(RestRequest request, Index[] indices, ClusterHealthResponse res table.addCell(indexMetaData.getCreationDate()); ZonedDateTime creationTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(indexMetaData.getCreationDate()), ZoneOffset.UTC); - table.addCell(DateFormatters.forPattern("strict_date_time").format(creationTime)); + table.addCell(DateTimeFormatter.ISO_INSTANT.format(creationTime)); table.addCell(totalStats.getStore() == null ? null : totalStats.getStore().size()); table.addCell(primaryStats.getStore() == null ? null : primaryStats.getStore().size()); From bd1fe4fb56a3b55c04527f803023d337ada322ad Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 31 Jul 2018 17:19:28 -0700 Subject: [PATCH 4/6] remove unused import --- .../org/elasticsearch/rest/action/cat/RestIndicesAction.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index ee84832b2bdcc..3d751e3a391d7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -39,7 +39,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.time.DateFormatters; import org.elasticsearch.index.Index; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; From 4ae70f5555fba81d2c12308be9f9a5594cb933b8 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 9 Aug 2018 12:27:19 -0700 Subject: [PATCH 5/6] Revert "use builtin datetimeformatter" This reverts commit 832472608906475b7e7dd25afa6fc96d9c38942a. --- .../org/elasticsearch/rest/action/cat/RestIndicesAction.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index 3d751e3a391d7..65814ad861588 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -49,7 +49,6 @@ import java.time.Instant; import java.time.ZoneOffset; import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -382,7 +381,7 @@ Table buildTable(RestRequest request, Index[] indices, ClusterHealthResponse res table.addCell(indexMetaData.getCreationDate()); ZonedDateTime creationTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(indexMetaData.getCreationDate()), ZoneOffset.UTC); - table.addCell(DateTimeFormatter.ISO_INSTANT.format(creationTime)); + table.addCell(DateFormatters.forPattern("strict_date_time").format(creationTime)); table.addCell(totalStats.getStore() == null ? null : totalStats.getStore().size()); table.addCell(primaryStats.getStore() == null ? null : primaryStats.getStore().size()); From 79e5cf91b06e46b76cae87e7f3d608278bee8b8f Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 9 Aug 2018 12:28:16 -0700 Subject: [PATCH 6/6] move back to using DateFormatters --- .../org/elasticsearch/rest/action/cat/RestIndicesAction.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index 65814ad861588..1a859933ad3fe 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -39,6 +39,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.time.DateFormatters; import org.elasticsearch.index.Index; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest;