-
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. Monitoring plugin #36297
Changes from 7 commits
93541a7
83c024c
438ce82
4cdcbf8
40b47a6
19aff93
7130b85
0850175
41da102
dac6924
2e7f180
1c2d553
88f56bc
9272269
33cd6dd
1e1198f
ab9032a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,9 @@ | |
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.xpack.core.monitoring.MonitoringField; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.chrono.ISOChronology; | ||
|
||
import java.time.Clock; | ||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.concurrent.ScheduledFuture; | ||
|
@@ -57,7 +57,9 @@ public CleanerService(Settings settings, ClusterSettings clusterSettings, Thread | |
@Override | ||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use |
||
executorName(), | ||
runnable); | ||
logger.debug("cleaning service started"); | ||
} | ||
|
||
|
@@ -191,7 +193,7 @@ protected void doRunInLifecycle() throws Exception { | |
*/ | ||
@Override | ||
protected void onAfterInLifecycle() { | ||
DateTime start = new DateTime(ISOChronology.getInstance()); | ||
ZonedDateTime start = ZonedDateTime.now(Clock.systemDefaultZone()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
TimeValue delay = executionScheduler.nextExecutionDelay(start); | ||
|
||
logger.debug("scheduling next execution in [{}] seconds", delay.seconds()); | ||
|
@@ -234,7 +236,7 @@ interface ExecutionScheduler { | |
* @param now the current time | ||
* @return the delay in millis | ||
*/ | ||
TimeValue nextExecutionDelay(DateTime now); | ||
TimeValue nextExecutionDelay(ZonedDateTime now); | ||
} | ||
|
||
/** | ||
|
@@ -243,14 +245,16 @@ interface ExecutionScheduler { | |
static class DefaultExecutionScheduler implements ExecutionScheduler { | ||
|
||
@Override | ||
public TimeValue nextExecutionDelay(DateTime now) { | ||
public TimeValue nextExecutionDelay(ZonedDateTime now) { | ||
// Runs at 01:00 AM today or the next day if it's too late | ||
DateTime next = now.withTimeAtStartOfDay().plusHours(1); | ||
ZonedDateTime next = now.toLocalDate() | ||
.atStartOfDay(now.getZone()) | ||
.plusHours(1); | ||
// if it's not after now, then it needs to be the next day! | ||
if (next.isAfter(now) == false) { | ||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit: you could simplify this to |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,10 @@ | |
import org.elasticsearch.common.settings.Setting.Property; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.settings.SettingsException; | ||
import org.elasticsearch.common.time.DateFormatter; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.joda.time.format.DateTimeFormat; | ||
import org.joda.time.format.DateTimeFormatter; | ||
|
||
import java.time.ZoneOffset; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
@@ -113,11 +113,11 @@ public void close() { | |
|
||
protected abstract void doClose(); | ||
|
||
protected static DateTimeFormatter dateTimeFormatter(final Config config) { | ||
protected static DateFormatter dateTimeFormatter(final Config config) { | ||
Setting<String> setting = INDEX_NAME_TIME_FORMAT_SETTING.getConcreteSettingForNamespace(config.name); | ||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
} catch (IllegalArgumentException e) { | ||
throw new SettingsException("[" + INDEX_NAME_TIME_FORMAT_SETTING.getKey() + "] invalid index name time format: [" | ||
+ format + "]", e); | ||
|
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 astrict_date_time
formatter might just work as expected?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.
it should work fine - the pattern is the same