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

Deprecate camel case date format #58909

Closed
wants to merge 11 commits into from

Conversation

pgomulka
Copy link
Contributor

@pgomulka pgomulka commented Jul 2, 2020

Camel case date formats are deprecated and snake case should be used instead.

@pgomulka pgomulka added :Core/Infra/Core Core issues without another label >deprecation v7.9.0 labels Jul 2, 2020
@pgomulka pgomulka self-assigned this Jul 2, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Core)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Jul 2, 2020
@pgomulka pgomulka marked this pull request as draft July 2, 2020 13:22
@pgomulka pgomulka marked this pull request as ready for review July 6, 2020 13:29
@pgomulka pgomulka marked this pull request as draft July 6, 2020 13:42
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.

I know this is in draft, but thought I'd mention a few things I noticed.

@@ -6,6 +6,10 @@
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
<option name="AUTO_RESTART" value="true" />
<RunnerSettings RunnerId="Debug">
Copy link
Member

Choose a reason for hiding this comment

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

This should not be changing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, that file should not be modified.

}

private void deprecate(String format) {
if (DEPRECATED_CAMEL_CASE_NAMES.contains(format)) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't all camelCase names be deprecated, in which case we can only log the deprecated message if the first condition matches above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, all camel case should be deprecated. It is just for some like iso8601, hour, year etc snake case and camel case is the same. We do not need to log the deprecation for these

Copy link
Member

Choose a reason for hiding this comment

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

In that case perhaps we could not fill in the camelCaseName and condition on that being non null? It seems like we are doing extra work to analyze the casing of the name when we have already separated the ok (snake case) from the deprecated (camelCase).

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 see what you mean now. That's the smart way to do it - will fix!

public class FormatNamesTests extends TestCase {

public void testDeprecation(){

Copy link
Member

Choose a reason for hiding this comment

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

missing test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pgomulka pgomulka marked this pull request as ready for review July 13, 2020 09:03
@pgomulka pgomulka requested a review from rjernst July 13, 2020 09:03
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.util.LazyInitializable;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public enum FormatNames {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for the record. this class was already used by Joda class. By mistake it was not used by DateFormatters

// it results in errors sent to status logger and startup to fail.
// Hence a lazy initialization.
private static final LazyInitializable<DeprecationLogger, RuntimeException> deprecationLogger
= new LazyInitializable(() -> new DeprecationLogger(LogManager.getLogger(FormatNames.class)));
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 per comment. Some classes - which are used before loading log4j config - are using DateFormat.forPattern to get a date format. see XContentElasticsearchExtension
This is fine, but if I try to create a logger, before logging config is loaded I will get an exception (no config, writing to status logger) this is later checked and startup will fail.
I am not sure we can move loading log4j config as early on startup.
At the same time, this logging is a temporary. We will remove it in 8 (unless we want some more detailed exception)
@rjernst WDYT?

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.

One general comment: I think this PR needs to be against master, and backported to 7.x. Otherwise we lose the history that we first deprecated, and the the camelCase names still exist in master.

@pgomulka
Copy link
Contributor Author

One general comment: I think this PR needs to be against master, and backported to 7.x. Otherwise we lose the history that we first deprecated, and the the camelCase names still exist in master.

@rjernst we already have a PR that forbids using camelCase names #59417 I can refactor that PR (#59417 against master) to deprecate, then cherry-pick to 7.x and finally remove it in master in another PR.
There will be some conflicts though, FormatNames did not exist in master before. It was meant for deprecation of joda formats in 7.x initially.
What do you mean by loosing history? We can always link these two PRs with relates 1

@rjernst
Copy link
Member

rjernst commented Jul 14, 2020

A large reason why we try to make all PRs go through the master branch, even deprecations for features that will be removed in followups, is that the master history then contains the deprecation. If we make isolated changes directly to 7.x, those changes will never show up in the history within master. For example, let's say 2 major versions later, I am looking at the history of DateFormatters, trying to find when we deprecated camelCase format names. If I go look at master or 9.x, at the DateFormatters class, I would not find the deprecation, since it was only applied to 7.x. If instead the deprecation first goes to master, all future N.x branches will contain that history in DateFormatters, as well as master itself, so we regain the history. It's not that it disappears completely. The change still exists in git history, but if it doesn't exist within master's linear history, it is much more difficult to find.

@pgomulka
Copy link
Contributor Author

that totally makes sens to me now. thanks for clarifying. I will follow up with possible a different PR/force push on this one

@pgomulka
Copy link
Contributor Author

closing in favour of #59555 against master
will backport to v7

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 >deprecation Team:Core/Infra Meta label for core/infra team v7.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants