Skip to content

Conversation

@pgomulka
Copy link
Contributor

@pgomulka pgomulka commented May 8, 2019

Implement deprecation checks for joda incompatible patterns

relates #42010

@pgomulka pgomulka added the :Core/Infra/Core Core issues without another label label May 8, 2019
@pgomulka pgomulka self-assigned this May 8, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

A few comments


static Map<String, String> JODA_PATTERNS_DEPRECATIONS = new LinkedHashMap<>();
static {
JODA_PATTERNS_DEPRECATIONS.put("Y", "'Y' year-of-era becomes 'y'. 'Y' means week-based-year.");
Copy link
Member

Choose a reason for hiding this comment

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

We already have these deprecation messages in Joda, which are logged when the patterns are parsed. This seems to be doubling them? Additionally, I think some of these are too broad, like the check for y, which users wouldn't need to do anything about. Any deprecation messages should be actionable.

Copy link
Contributor Author

@pgomulka pgomulka May 9, 2019

Choose a reason for hiding this comment

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

Yes - that was just a draft, but next step is to have those messages in one place and use in both Joda & Deprecation API.
for y pattern check I think it would be fair to notify users about this as it changes to u (I missed this on previous commit). I suppose some users would just ignore this check specifically as a difference is very subtle, but we should at least let them know.

Some of the patterns are not actionable though - like C century is no longer present in java.time. Again users should be aware about this, as their pattern will probably no longer work. Action would be to change your business logic?

@pgomulka pgomulka added the WIP label May 8, 2019
@gwbrown
Copy link
Contributor

gwbrown commented May 8, 2019

This approach seems reasonable to me, the warning it generates is a little verbose but otherwise should be fine (and it's not like we don't already have some very verbose warnings).

As others have noted, there's a fair bit of commented out code, etc. left, but I assume that's why this PR is still marked as a draft/WIP.

@pgomulka
Copy link
Contributor Author

pgomulka commented May 9, 2019

there are a lot of test failing as the deprecation now includes y and Z (and that adds deprecation to headers). I understand @rjernst and @gwbrown concerns that this might be a bit too verbose.
At the same time, since y has a slightly different meaning now in java.time and Z behaves a little bit different I think it would make sens to warn users about this.
@spinscale what is your view on this?

@pgomulka pgomulka force-pushed the feature/deprecation_info_joda branch from 9152886 to c94bbe7 Compare May 10, 2019 20:25
--------------------------------------------------
// CONSOLE
// TESTSETUP
// TEST[setup:name]
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 figure out how to fix Docs tests. At the moment they fail because of warnings

Copy link
Member

Choose a reason for hiding this comment

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

Normally we would update the docs to not use deprecated functionality. Is that possible here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it would - actually it would be much easier if I just use a new pattern with 8 prefix. But should this be done across all the docs?
That change is to fix the DocsClientYamlTestSuiteIT. The options is to prefix with8, assert about warnings, disable warning checks alltogether?

Copy link
Contributor

@gwbrown gwbrown 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 comments, mostly minor.

You mentioned wanting to have more Javadoc and tests, which I agree with as well, plus the commented-out code and TODOs left which I didn't address as this is still marked WIP. Otherwise I still don't see any major problems, and it's already much improved from the last time I looked at this. Thanks for doing this!

public class JavaJodaTimeDuellingTests extends ESTestCase {
@Override
protected boolean enableWarningsCheck() {
// disable warning checks as deprecated patterns are used to compare Joda vs Java results (y - year and Z zone offset)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would update this note to say that these warnings as tested in JodaWarningTests already, so that's why we don't test them here.

Pretend I copy/pasted this onto every iteration of this comment, but I'm not going to because there's a lot of them.

public class RootObjectMapperTests extends ESSingleNodeTestCase {
@Override
protected boolean enableWarningsCheck() {
// disable warning checks as deprecated patterns are used to compare Joda vs Java results (y - year and Z zone offset)
Copy link
Contributor

Choose a reason for hiding this comment

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

I get doing this for date-specific tests, but there's a lot of classes that have the warnings check disabled here, including some very broad ones. We should be careful about doing this so widely, although I could see an argument that this is okay if it would be a lot of work to use assertWarnings everywhere given these will only be going into 6.8, which should pretty much only be getting bugfixes at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

where possible I used explicitly assertWarnings about these patterns, but often it was just not feasible and would require adding lot of them.
and agree, that is only going to be in 6.8 so hopefully would not reduce confidence in these tests

private static Map<String, String> JODA_PATTERNS_DEPRECATIONS = new LinkedHashMap<>();

static {
JODA_PATTERNS_DEPRECATIONS.put("Y", "'Y' year-of-era becomes 'y'. Use 'Y' for week-based-year.");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should make this a bit clearer as to what we're recommending be done. Something like this:

Suggested change
JODA_PATTERNS_DEPRECATIONS.put("Y", "'Y' year-of-era becomes 'y'. Use 'Y' for week-based-year.");
JODA_PATTERNS_DEPRECATIONS.put("Y", "'Y' year-of-era should be replaced with 'y'. Use 'Y' for week-based-year.");

And similar for the rest of these.

}
}
String combinedWarning = warnings.stream()
.collect(Collectors.joining(";"));

Choose a reason for hiding this comment

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

Since this is building a message for the end user it would be nice to put a space after the semi-colon.

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 point, this would be more readable with a space

"https://www.elastic.co/guide/en/elasticsearch/reference/7.0/breaking-changes-7.0.html#breaking_70_java_time_changes",
"This index has date fields with deprecated formats: ["+
"[type: _doc, field: date_time_field_Y, format: dd-CC||MM-YYYY, " +
"suggestion: 'C' century of era is no longer supported.;"+

Choose a reason for hiding this comment

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

The line break disguises the fact that there's no space after the semi-colon here. At the moment the message is ...supported.;'Y' year-of-era.... If you accept my other suggestion you'll need to add a space here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, will add a space after a semi-colon. Should be more readable

@pgomulka
Copy link
Contributor Author

This PR has grown significantly which is sad as I only expected this to be a quick fix.
There are a lot of tests that I had to change, where possible I explicitly asserted about new warnings in a headers, but sometimes I had to turn that check off as it would make this PR just massive.

I have added some more tests to cover the message formatting and different scenarios of the pattern.

@gwbrown @rjernst @droberts195 would you be able to re-review this again?

Copy link
Contributor

@gwbrown gwbrown left a comment

Choose a reason for hiding this comment

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

The deprecation check LGTM, though I left a couple comments. Others may want to weigh in on the rest.

@pgomulka
Copy link
Contributor Author

added support for deprecation info on pipelines with date and date_index_name processors
Also I disabled only joda deprecation checks by default only. This was spreading far too much and was not really giving much more confidence as assertions we usually about the same pattern.

Copy link
Contributor

@gwbrown gwbrown 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 couple minor comments but otherwise LGTM. No need for another round of review after addressing these unless you make other substantial changes.


//in joda 'Z' was able to parse 'Z' zulu but in java it fails. You have to use 'X' to do that.
//Caused by: java.time.format.DateTimeParseException: Text '2019-01-01T01:01:01.001Z' could not be parsed at index 23
//assertSameMillis("2019-01-01T01:01:01.001Z","YYYY-MM-dd'T'HH:mm:ss.SSSZ","8yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these lines might be left over from something? Otherwise I'm not sure why they're here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This whole test case testIncompatiblePatterns was meant to use examples of patterns that are incompatible between joda-java and show how to fix them.
For 'Z' we should go for 'X' so I will just remove this comment.

@pgomulka pgomulka merged commit 728c5d1 into elastic:6.8 May 29, 2019
@mark-vieira
Copy link
Contributor

FYI, this change is breaking some tests in BWC compatible branches. We'll need to update org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT in 7.1, 7.2 and 7.x.

https://scans.gradle.com/s/z2xy2pasutgty/tests/z3ejz3hl3i73s-wptfavgv7zdvi

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 v6.8.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants