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

Report parser name and location in XContent deprecation warnings #53752

Merged
merged 5 commits into from Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -107,4 +107,5 @@ public void usedDeprecatedField(String parserName, Supplier<XContentLocation> lo
* @param usedName the provided field name
*/
void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName);

}
Expand Up @@ -98,7 +98,7 @@ public void testInlineBackcompat() throws Exception {
configMap.put("inline", "code");

factory.create(null, randomAlphaOfLength(10), configMap);
assertWarnings("Deprecated field [inline] used, expected [source] instead");
assertWarnings("[script][1:11] Deprecated field [inline] used, expected [source] instead");
}

public void testFactoryInvalidateWithInvalidCompiledScript() throws Exception {
Expand Down
Expand Up @@ -52,30 +52,24 @@ private LoggingDeprecationHandler() {

@Override
public void usedDeprecatedName(String parserName, Supplier<XContentLocation> location, String usedName, String modernName) {
if (parserName != null) {
deprecationLogger.deprecated("[{}][{}] Deprecated field [{}] used, expected [{}] instead",
parserName, location.get(), usedName, modernName);
} else {
deprecationLogger.deprecated("Deprecated field [{}] used, expected [{}] instead", usedName, modernName);
}
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
deprecationLogger.deprecated("{}Deprecated field [{}] used, expected [{}] instead",
prefix, usedName, modernName);
}

@Override
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName, String replacedWith) {
if (parserName != null) {
deprecationLogger.deprecated("[{}][{}] Deprecated field [{}] used, replaced by [{}]",
parserName, location.get(), usedName, replacedWith);
}
else {
deprecationLogger.deprecated("Deprecated field [{}] used, replaced by [{}]", usedName, replacedWith);
}
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
deprecationLogger.deprecated("{} Deprecated field [{}] used, replaced by [{}]",
prefix, usedName, replacedWith);
}

@Override
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName) {
if (parserName != null) {
deprecationLogger.deprecated("[{}][{}] Deprecated field [{}] used, this field is unused and will be removed entirely",
parserName, location.get(), usedName);
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
if (true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't look right 🤔

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 wasn't!

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, out-of-date diff 😅

deprecationLogger.deprecated("{}Deprecated field [{}] used, this field is unused and will be removed entirely",
prefix, usedName);
} else {
deprecationLogger.deprecated("Deprecated field [{}] used, this field is unused and will be removed entirely", usedName);
}
Expand Down
Expand Up @@ -30,37 +30,25 @@ public class LoggingDeprecationAccumulationHandler implements DeprecationHandler
@Override
public void usedDeprecatedName(String parserName, Supplier<XContentLocation> location, String usedName, String modernName) {
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(parserName, location, usedName, modernName);
if (parserName != null) {
deprecations.add(LoggerMessageFormat.format("[{}][{}] Deprecated field [{}] used, expected [{}] instead",
new Object[]{parserName, location.get(), usedName, modernName}));
} else {
deprecations.add(LoggerMessageFormat.format("Deprecated field [{}] used, expected [{}] instead",
new Object[]{usedName, modernName}));
}
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
deprecations.add(LoggerMessageFormat.format("{}Deprecated field [{}] used, expected [{}] instead",
new Object[]{prefix, usedName, modernName}));
}

@Override
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName, String replacedWith) {
LoggingDeprecationHandler.INSTANCE.usedDeprecatedField(parserName, location, usedName, replacedWith);
if (parserName != null) {
deprecations.add(LoggerMessageFormat.format("[{}][{}] Deprecated field [{}] used, replaced by [{}]",
new Object[]{parserName, location.get(), usedName, replacedWith}));
} else {
deprecations.add(LoggerMessageFormat.format("Deprecated field [{}] used, replaced by [{}]",
new Object[]{usedName, replacedWith}));
}
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
deprecations.add(LoggerMessageFormat.format("{}Deprecated field [{}] used, replaced by [{}]",
new Object[]{prefix, usedName, replacedWith}));
}

@Override
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName) {
LoggingDeprecationHandler.INSTANCE.usedDeprecatedField(parserName, location, usedName);
if (parserName != null) {
deprecations.add(LoggerMessageFormat.format("[{}][{}] Deprecated field [{}] used, unused and will be removed entirely",
new Object[]{parserName, location.get(), usedName}));
} else {
deprecations.add(LoggerMessageFormat.format("Deprecated field [{}] used, unused and will be removed entirely",
new Object[]{usedName}));
}
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
deprecations.add(LoggerMessageFormat.format("{}Deprecated field [{}] used, unused and will be removed entirely",
new Object[]{prefix, usedName}));
}

/**
Expand Down
Expand Up @@ -620,37 +620,24 @@ private ApiKeyLoggingDeprecationHandler(DeprecationLogger logger, String apiKeyI

@Override
public void usedDeprecatedName(String parserName, Supplier<XContentLocation> location, String usedName, String modernName) {
if (parserName != null) {
deprecationLogger.deprecated("[{}][{}] Deprecated field [{}] used in api key [{}], expected [{}] instead",
parserName, location.get(), usedName, apiKeyId, modernName);
} else {
deprecationLogger.deprecated("Deprecated field [{}] used in api key [{}], expected [{}] instead",
usedName, apiKeyId, modernName);
}
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
deprecationLogger.deprecated("{}Deprecated field [{}] used in api key [{}], expected [{}] instead",
prefix, usedName, apiKeyId, modernName);
}

@Override
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName, String replacedWith) {
if (parserName != null) {
deprecationLogger.deprecated("[{}][{}] Deprecated field [{}] used in api key [{}], replaced by [{}]",
parserName, location.get(), usedName, apiKeyId, replacedWith);
} else {
deprecationLogger.deprecated("Deprecated field [{}] used in api key [{}], replaced by [{}]",
usedName, apiKeyId, replacedWith);
}
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
deprecationLogger.deprecated("{}Deprecated field [{}] used in api key [{}], replaced by [{}]",
prefix, usedName, apiKeyId, replacedWith);
}

@Override
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName) {
if (parserName != null) {
deprecationLogger.deprecated(
"[{}][{}] Deprecated field [{}] used in api key [{}], which is unused and will be removed entirely",
parserName, location.get(), usedName);
} else {
deprecationLogger.deprecated(
"[{}][{}] Deprecated field [{}] used in api key [{}], which is unused and will be removed entirely",
usedName);
}
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
deprecationLogger.deprecated(
"{}Deprecated field [{}] used in api key [{}], which is unused and will be removed entirely",
prefix, usedName);
}
}

Expand Down