Skip to content
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 #35493

Closed

Conversation

pgomulka
Copy link
Contributor

@pgomulka pgomulka commented Nov 13, 2018

part of the migrating joda time work. The goal is to find usages of joda
time and refactor to use java.time.

refers #27330

This commit moves the aggregation and mapping code from joda time to
java time.

This includes field mappers, root object mappers, aggregations with date
histograms, query builders and a lot of changes within tests.
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@pgomulka pgomulka force-pushed the feature/ML-java-time-ml-migration branch 4 times, most recently from 055ec8d to d3a6e85 Compare November 13, 2018 13:41
@rjernst rjernst requested a review from spinscale November 13, 2018 18:14
@@ -112,6 +112,7 @@ public static ExtractedField newField(String alias, String name, ExtractionMetho
}
if (value[0] instanceof String) { // doc_value field with the epoch_millis format
value[0] = Long.parseLong((String) value[0]);
//TODO confirm if can remove the script time field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I had a discussion with @jpountz and got to the bottom of this. BaseDateTime was the type returned for date fields in doc values prior to allowing configuring the doc value format. Thus, we still need this for mixed 6.x clusters. The comment below // script field is actually misleading. ML never supported scripted date fields.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think the only thing left is to remove this TODO and correct the comment below (// script field). A more accurate comment would be // for handling doc value type prior to 6.4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to investigate what will be the behaviour for a mix cluster like that.
Is there a test in any of the old branches that I can modify and see that place being hit? We could possibly then think of creating a similar one on the master branch with a mixed cluster?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we should be able to remove this from master. 7.x nodes should only talk to 6.latest which already have the doc value format specified. It's only in 6.x we need to keep this code for. Any datafeed test should be hitting this prior to 6.4.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that prior to 6.4 there was no if block in this method. It was directly casting to the joda time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #31463

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we discussed, that sounds really good. Will remove that line in master

@@ -179,7 +179,7 @@ private void processDateHistogram(Histogram agg) throws IOException {
* Histograms have either a Double or Long.
*/
private long toHistogramKeyToEpoch(Object key) {
if (key instanceof DateTime) {
if (key instanceof DateTime) {//TODO what do we use as key in aggregations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a question for the ML folk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimitris-athanasiou I thought initially to ask ML team, but from what I see now we are missing that migration in elasticsearch. This seems to be a planned work but not started yet.
Will have to switch to datetime histograms first before finishing ML package

Copy link
Contributor Author

@pgomulka pgomulka Nov 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is on the java-time branch at the moment and the ZonedDateTime will be returned


import java.time.Instant;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this import used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused indeed - will remove

@@ -180,10 +180,10 @@ private void processDateHistogram(Histogram agg) throws IOException {
*/
private long toHistogramKeyToEpoch(Object key) {
if (key instanceof ZonedDateTime) {
return ((ZonedDateTime)key).toInstant().toEpochMilli();
return ((ZonedDateTime)keEy).toInstant().toEpochMilli();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this introduced a typo: keEy instead of key

@pgomulka pgomulka force-pushed the feature/ML-java-time-ml-migration branch from 3d5696f to bb0d60b Compare November 21, 2018 14:07
@pgomulka pgomulka changed the base branch from master to java-time November 21, 2018 14:07
@pgomulka pgomulka changed the base branch from java-time to master November 21, 2018 14:51
@pgomulka pgomulka force-pushed the feature/ML-java-time-ml-migration branch from bb0d60b to d737fe5 Compare November 21, 2018 14:58
@pgomulka pgomulka added the WIP label Nov 21, 2018
@pgomulka pgomulka force-pushed the feature/ML-java-time-ml-migration branch from 41950c9 to 166be62 Compare November 22, 2018 09:24
@pgomulka pgomulka force-pushed the feature/ML-java-time-ml-migration branch from 166be62 to cef95b2 Compare November 26, 2018 11:16
Copy link
Contributor

@spinscale spinscale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a few minor comments on how to get the current time in milliseconds, but it seems this has to wait for the java-time branch first

@@ -66,7 +68,13 @@
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 = getNowEpochMs();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about Instant.now().toEpochMilli()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right, there is no point using ISOChronology when all we need here are milliseconds since epoch

long nowEpochMs = DateTime.now(ISOChronology.getInstance()).getMillis();
Instant instant = ZonedDateTime.now().toInstant();
long nowEpochMs = IsoChronology.INSTANCE.zonedDateTime(instant, ZoneId.systemDefault())
.toInstant().toEpochMilli();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about Instant.now().toEpochMilli()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

return TimeValue.timeValueMillis(next.getMillis() - now.getMillis());

Instant instant = ZonedDateTime.now().toInstant();
ZonedDateTime now = IsoChronology.INSTANCE.zonedDateTime(instant, ZoneId.systemDefault());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about Instant.now().toEpochMilli()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I ZonedDatetime, might better here - more on a new review https://github.com/elastic/elasticsearch/pull/35949/files#r236714576

@pgomulka
Copy link
Contributor Author

@spinscale I will rebase this branch on top of java-time branch. It will help me to integrate when java-time is merged into master

@pgomulka pgomulka force-pushed the feature/ML-java-time-ml-migration branch from cef95b2 to 06b44dc Compare November 27, 2018 10:47
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

confirmed histograms are returning zoneddatedate
 remove unused imports
 missing space
typos
removing the DateTime usage as it won't be hit
removing tests no longer valid as code has been removed
@pgomulka
Copy link
Contributor Author

closing, as the change was merged into java-time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label :ml Machine learning WIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants