Skip to content

Scripting: Switch watcher to use joda bwc time objects #35966

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

Merged
merged 17 commits into from
Dec 11, 2018

Conversation

rjernst
Copy link
Member

@rjernst rjernst commented Nov 27, 2018

This commit converts the watcher execution context to use the joda
compat java time objects. It also again removes the joda methods from
the painless whitelist.

This commit converts the watcher execution context to use the joda
compat java time objects. It also again removes the joda methods from
the painless whitelist.
This commit converts the watcher execution context to use the joda
compat java time objects. It also again removes the joda methods from
the painless whitelist.
This commit actually loads the joda whitelist, which was missed in
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@rjernst rjernst requested a review from spinscale November 27, 2018 19:57
Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

Makes sense to me but I'm not a watcher expert.

assertThat(ObjectPath.eval("ctx", model), instanceOf(Map.class));
assertThat(ObjectPath.eval("ctx.id", model), is(wid.value()));
assertThat(ObjectPath.eval("ctx.execution_time", model), is(executionTime));
// NOTE: we use toString() here because two ZonedDateTime are *not* equal, we need to check with isEqual
// for date/time equality, but not hamcrest matcher exists
Copy link
Member

Choose a reason for hiding this comment

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

but the hamcrest matcher doesn't exist

Copy link
Contributor

Choose a reason for hiding this comment

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

Judging from a quick peek into JodaCompatibleZonedDateTime, it seems that its equals methods is the culprit not the ZonedDateTime? I think this snippet would fail

JodaCompatibleZonedDateTime d = new JodaCompatibleZonedDateTime(Instant.now(), ZoneOffset.UTC);
assertThat(d.equals(d), is(true));

not sure this is intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is semi-intentional, in that it just compares the underlying ZonedDateTime instances. To compare times, apparently isEqual is the thing to use...

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.

I left one question regarding the equals methods, I think this is also the reason for some of the test failures.

assertThat(ObjectPath.eval("ctx", model), instanceOf(Map.class));
assertThat(ObjectPath.eval("ctx.id", model), is(wid.value()));
assertThat(ObjectPath.eval("ctx.execution_time", model), is(executionTime));
// NOTE: we use toString() here because two ZonedDateTime are *not* equal, we need to check with isEqual
// for date/time equality, but not hamcrest matcher exists
Copy link
Contributor

Choose a reason for hiding this comment

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

Judging from a quick peek into JodaCompatibleZonedDateTime, it seems that its equals methods is the culprit not the ZonedDateTime? I think this snippet would fail

JodaCompatibleZonedDateTime d = new JodaCompatibleZonedDateTime(Instant.now(), ZoneOffset.UTC);
assertThat(d.equals(d), is(true));

not sure this is intentional?

@spinscale
Copy link
Contributor

this commit fixes the ScriptConditionTests spinscale@3af5140

@rjernst
Copy link
Member Author

rjernst commented Nov 29, 2018

@elasticmachine test this please

@rjernst
Copy link
Member Author

rjernst commented Nov 29, 2018

@elasticmachine test this please

@spinscale
Copy link
Contributor

the remaining tests fail because of a different default formatting of the toString() method in mustache of ZonedDateTime, which is used in JodaCompatibleZonedDateTime.toString(). One could fix this like

new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(scheduledTime.getMillis()), ZoneOffset.UTC){
                @Override
                public String toString() {
                    return DateFormatters.forPattern("strict_date_time").format(getZonedDateTime());
                }
            });

on a per case base. But I think it makes sense to just put this into the toString() method of JodaCompatibleZonedDateTime or allow to pass a date formatter?

@rjernst
Copy link
Member Author

rjernst commented Nov 30, 2018

This is an interesting problem. I had not thought about the toString() behavior. I had thought they were the same between joda/java. I guess in this case the upgrade to 7.0 will have to be hard break? Most of the time it is the same?

@spinscale
Copy link
Contributor

AbstractDateTime.toString() used by DateTime uses Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ). according to its java docs. So I think it is fine to go with that format for the JodaCompatibleZonedDateTime. The java time formatting is more lenient by default by omitting some zero based values (and interestingly not all of them, I have not understood the intentation behind that to be honest).

@spinscale
Copy link
Contributor

I tried what I mentioned above and added a formatter to the toString() method. looks good during my test runs

@rjernst
Copy link
Member Author

rjernst commented Dec 7, 2018

Thanks @spinscale. I modified it as you suggested, but I do want to note the behavior would still change in 7.0 since the joda compatible object would disappear in favor of ZonedDateTime. It's probably fine, as anyone relying on whether nano seconds exist in a tostring inside a script are asking for trouble, but we should probably note this in migration docs when removing the compat object in master.

@spinscale
Copy link
Contributor

mentioning in the logs sounds good to me!

@rjernst rjernst merged commit a0da390 into elastic:master Dec 11, 2018
@rjernst rjernst deleted the timeapi12 branch December 11, 2018 01:29
rjernst added a commit to rjernst/elasticsearch that referenced this pull request Dec 11, 2018
This commit converts the watcher execution context to use the joda
compat java time objects. It also again removes the joda methods from
the painless whitelist.
rjernst added a commit that referenced this pull request Dec 11, 2018
This commit converts the watcher execution context to use the joda
compat java time objects. It also again removes the joda methods from
the painless whitelist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants