Core: Migrating from joda to java.time. Monitoring plugin#36297
Core: Migrating from joda to java.time. Monitoring plugin#36297pgomulka merged 17 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/es-core-infra |
09de1e0 to
13846f5
Compare
ee5a5d8 to
96109e1
Compare
96109e1 to
b1f2cc6
Compare
b1f2cc6 to
93541a7
Compare
| * @return a string representing the timestamp | ||
| */ | ||
| public static String toUTC(final long timestamp) { | ||
| return new DateTime(timestamp, DateTimeZone.UTC).toString(); |
There was a problem hiding this comment.
joda toString:
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).
when java-time
{@code 2007-12-03T10:15:30+01:00[Europe/Paris]}.
but it also says: The output is compatible with ISO-8601 if the offset and ID are the same.
The quick test for sample long shows that the format is the same
Instant.ofEpochMilli(123).atZone(ZoneOffset.UTC).toString()
new DateTime(123, DateTimeZone.UTC).toString();
1970-01-01T00:00:00.123Z
There was a problem hiding this comment.
can we make this more explicit and not rely on the toString() method of classes we dont have control over (even though I assume this does not get changed) Using a strict_date_time formatter might just work as expected?
There was a problem hiding this comment.
it should work fine - the pattern is the same
...src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java
Show resolved
Hide resolved
...src/test/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporterIntegTests.java
Show resolved
Hide resolved
danielmitterdorfer
left a comment
There was a problem hiding this comment.
Looks fine overall but I think I spotted one unrelate change.
...re/src/main/java/org/elasticsearch/xpack/core/security/action/user/AuthenticateResponse.java
Outdated
Show resolved
Hide resolved
...re/src/main/java/org/elasticsearch/xpack/core/security/action/user/AuthenticateResponse.java
Outdated
Show resolved
Hide resolved
|
@elasticmachine run elasticsearch-ci/1 |
|
@elasticmachine run elasticsearch-ci/default-distro |
|
ok to test |
spinscale
left a comment
There was a problem hiding this comment.
left a few comments, mostly about week year based format that should be replaced
| * @return a string representing the timestamp | ||
| */ | ||
| public static String toUTC(final long timestamp) { | ||
| return new DateTime(timestamp, DateTimeZone.UTC).toString(); |
There was a problem hiding this comment.
can we make this more explicit and not rely on the toString() method of classes we dont have control over (even though I assume this does not get changed) Using a strict_date_time formatter might just work as expected?
| protected void doStart() { | ||
| logger.debug("starting cleaning service"); | ||
| threadPool.schedule(executionScheduler.nextExecutionDelay(new DateTime(ISOChronology.getInstance())), executorName(), runnable); | ||
| threadPool.schedule(executionScheduler.nextExecutionDelay(ZonedDateTime.now(Clock.systemDefaultZone())), |
There was a problem hiding this comment.
can we use Clock.systemUTC() here? I see that we did not do this properly before though... see the DateTime() ctor
| @Override | ||
| protected void onAfterInLifecycle() { | ||
| DateTime start = new DateTime(ISOChronology.getInstance()); | ||
| ZonedDateTime start = ZonedDateTime.now(Clock.systemDefaultZone()); |
| final DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC(); | ||
| final String index = ".watcher-history-" + version + "-" + formatter.print(creationDate.getMillis()); | ||
| protected void createWatcherHistoryIndex(final ZonedDateTime creationDate, final String version) { | ||
| DateFormatter formatter = DateFormatter.forPattern("YYYY.MM.dd").withZone(ZoneOffset.UTC); |
There was a problem hiding this comment.
YYYY in java time means week based year, where is in joda time it means year of era - this is lower case yyyy in java time
see https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
see https://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html
| final DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC(); | ||
| final String index = ".watcher-history-" + version + "-" + formatter.print(creationDate.getMillis()); | ||
| protected void createWatcherHistoryIndex(final ZonedDateTime creationDate, final String version) { | ||
| DateFormatter formatter = DateFormatter.forPattern("YYYY.MM.dd").withZone(ZoneOffset.UTC); |
There was a problem hiding this comment.
does it make sense to make the formatter static?
| final DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC(); | ||
| final String index = ".watcher-history-" + version + "-" + formatter.print(creationDate.getMillis()); | ||
| protected void createWatcherHistoryIndex(final ZonedDateTime creationDate, final String version) { | ||
| DateFormatter formatter = DateFormatter.forPattern("YYYY.MM.dd").withZone(ZoneOffset.UTC); |
There was a problem hiding this comment.
does it make sense to add a test for this corner case in order to catch it?
There was a problem hiding this comment.
hmm this is a test class, what do you suggest to catch?
| 0, ZoneOffset.UTC).toInstant().toEpochMilli(); | ||
|
|
||
| DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC(); | ||
| DateFormatter formatter = DateFormatter.forPattern("YYYY.MM.dd").withZone(ZoneOffset.UTC); |
| equalTo(".monitoring-beats-" + TEMPLATE_VERSION + "-2017.08.03")); | ||
|
|
||
| formatter = DateTimeFormat.forPattern("YYYY-dd-MM-HH.mm.ss").withZoneUTC(); | ||
| formatter = DateFormatter.forPattern("YYYY-dd-MM-HH.mm.ss").withZone(ZoneOffset.UTC); |
| MockRequest recordedRequest = assertBulk(webServer); | ||
|
|
||
| String indexName = indexName(DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC(), doc.getSystem(), doc.getTimestamp()); | ||
| DateFormatter formatter = DateFormatter.forPattern("YYYY.MM.dd").withZone(ZoneOffset.UTC); |
| assertThat(index, equalTo(MonitoringTemplateUtils.indexName(DateTimeFormat.forPattern("YYYY.MM.dd").withZoneUTC(), | ||
| expectedSystem, | ||
| ISODateTimeFormat.dateTime().parseMillis(timestamp)))); | ||
| DateFormatter formatter = DateFormatter.forPattern("YYYY.MM.dd"); |
|
I think the most important date was not changed in the PR and this can suffer from the weekyear issue: the formatter string of the exporter that sends the data to the local cluster or a remote one. I put this test in I think we need to fix |
| next = next.plusDays(1); | ||
| } | ||
| return TimeValue.timeValueMillis(next.getMillis() - now.getMillis()); | ||
| return TimeValue.timeValueMillis(next.toInstant().toEpochMilli() - now.toInstant().toEpochMilli()); |
There was a problem hiding this comment.
minor nit: you could simplify this to Duration.between(now, next).toMillis() (pay attention that you have to switch the order in that case)
| String format = setting.exists(config.settings()) ? setting.get(config.settings()) : INDEX_FORMAT; | ||
| try { | ||
| return DateTimeFormat.forPattern(format).withZoneUTC(); | ||
| return DateFormatter.forPattern(format).withZone(ZoneOffset.UTC); |
There was a problem hiding this comment.
this also requires a change in 6.7, otherwise users using outdated formats will not be warned if they do so, as this uses the joda time API directly
|
FYI: I created #38309 for the required 6.7 change |
monitoring plugin migration from joda to java.time
refers #27330