-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Core: Migrating from joda to java.time. ML package #35949
Conversation
1dddced
to
68faca6
Compare
Pinging @elastic/es-core-infra |
Pinging @elastic/ml-core |
0864968
to
fce5c46
Compare
@@ -66,7 +68,7 @@ | |||
public ExpiredForecastsRemover(Client client, ThreadPool threadPool) { | |||
this.client = Objects.requireNonNull(client); | |||
this.threadPool = Objects.requireNonNull(threadPool); | |||
this.cutoffEpochMs = DateTime.now(ISOChronology.getInstance()).getMillis(); | |||
this.cutoffEpochMs = Instant.now().toEpochMilli(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as per discussion in original review, chronology does not matter when calculating milliseconds from epoch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it is a default timezone..
.atStartOfDay(now.getZone()) | ||
.plusMinutes(30) | ||
.plusMinutes(minutesOffset); | ||
return TimeValue.timeValueMillis(next.toInstant().toEpochMilli() - now.toInstant().toEpochMilli()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we did discuss to use just Instant.now(), but here I think it is better to use ZonedDateTime
since it allows to use convenient DSL for calculating next
variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
part of the migrating joda time work. The goal is to find usages of joda time and refactor to use java.time. closes: elastic#35490
fce5c46
to
502f230
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one major ask regarding specifying timezones when using ZonedDateTime
, otherwise I think we are pretty much there
@@ -266,7 +267,7 @@ public void testHRDSplit() throws Exception { | |||
"\"time\": { \"type\": \"date\" } } }"); | |||
|
|||
// Index some data | |||
DateTime baseTime = new DateTime().minusYears(1); | |||
ZonedDateTime baseTime = ZonedDateTime.now().minusYears(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ZonedDateTime.now(ZoneOffset.UTC)
should be used, as IIRC the system timezone will be used otherwise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right, the system default timezone will be used. But wouldn't this be change of behaviour if we use the UTC here? it was using new DateTime() previously - meaning system default time zone was used as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this particular test the timezone shouldn't matter provided the text representation of the timestamps includes the timezone and the test doesn't cross the start/end of daylight saving time. (I think the bit about not spanning daylight saving is a bug in the current version of the test.)
So I don't think it would be a problem to always do the test in UTC. This is not primarily testing date/time functionality so there's no need to get coverage of different timezones. It's testing completely different functionality but just needs to generate incrementing timestamps because anomaly detection deals with time series data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a ton for the clarification Dave, much appreciated!
I'd like to add all methods not specifying a timezone to the forbidden apis over time, thus my request.
DateTime next = now.plusDays(1).withTimeAtStartOfDay().plusMinutes(30).plusMinutes(minutesOffset); | ||
return TimeValue.timeValueMillis(next.getMillis() - now.getMillis()); | ||
|
||
ZonedDateTime now = ZonedDateTime.now(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UTC tz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here again originally no time zone was specified.
DateTime.now(ISOChronology.getInstance());
is an equivalent of DateTime.now()
ISOChronology is a default and system default time zone will be defaulted too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@droberts195 would you be able to comment on these? Do you think it is safe if we refactor this to use UTC timezones, given it wasn't previously specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one really is intended to be in the system timezone. The reason is that the daily maintenance is supposed to happen during the night on the assumption that the night is when other load is lowest. (Of course, it's possible that assumption is wrong for some clusters.)
If the intention is to ban now()
with no arguments then I guess this would achieve the same but specifying an argument:
ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault());
.atStartOfDay(now.getZone()) | ||
.plusMinutes(30) | ||
.plusMinutes(minutesOffset); | ||
return TimeValue.timeValueMillis(next.toInstant().toEpochMilli() - now.toInstant().toEpochMilli()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -98,13 +96,6 @@ public void testNewTimeFieldGivenSource() { | |||
expectThrows(IllegalArgumentException.class, () -> ExtractedField.newTimeField("time", ExtractedField.ExtractionMethod.SOURCE)); | |||
} | |||
|
|||
public void testValueGivenTimeField() { | |||
final long millis = randomLong(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this intentionally removed and not updated to ZonedDateTime
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only values expected to be returned from searchHit are of types Long and String.
there is a separate testValueGivenStringTimeField but I think it wouldn't do any harm to add another testcase for testing Long.
The one for ZonedDateTime/DateTime is not needed
@@ -70,7 +69,7 @@ private void removeData(Iterator<Job> jobIterator, ActionListener<Boolean> liste | |||
} | |||
|
|||
private long calcCutoffEpochMs(long retentionDays) { | |||
long nowEpochMs = DateTime.now(ISOChronology.getInstance()).getMillis(); | |||
long nowEpochMs = Instant.now().toEpochMilli(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This place is worthy to having a look too in regards to our comments about defaulted timezone
merging against java-time branch to be able to test with elasticsearch already using java.time classes.
part of the migrating joda time work. The goal is to find usages of joda
time and refactor to use java.time.
closes: #35490
previous branch against master (on top of java-time)
relates: #35493