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
[Transform] add method to collect deprecations from a transform configuration #77565
Merged
hendrikmuhs
merged 9 commits into
elastic:master
from
hendrikmuhs:transform-deprecations
Sep 14, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c0afb21
move DeprecationIssue into x-pack core and
77ac20a
implement deprecations check for transforms
a5a6149
fix tests
ae17864
add tests
9fd933c
deprecate beta transform configs
2593b48
fix tests
b0876d7
change the warning to critical for 8.x, shall be warning for 7.x
ce93652
fix test
6b9f757
apply review comments
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformDeprecations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.transform; | ||
|
||
public class TransformDeprecations { | ||
public static final String BREAKING_CHANGES_BASE_URL = | ||
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html"; | ||
|
||
public static final String QUERY_BREAKING_CHANGES_URL = BREAKING_CHANGES_BASE_URL + "#breaking_80_search_changes"; | ||
|
||
public static final String AGGS_BREAKING_CHANGES_URL = BREAKING_CHANGES_BASE_URL + "#breaking_80_aggregations_changes"; | ||
|
||
private TransformDeprecations() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.xcontent.DeprecationHandler; | ||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
|
@@ -25,12 +26,17 @@ | |
import org.elasticsearch.index.query.AbstractQueryBuilder; | ||
import org.elasticsearch.index.query.MatchAllQueryBuilder; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; | ||
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level; | ||
import org.elasticsearch.xpack.core.deprecation.LoggingDeprecationAccumulationHandler; | ||
import org.elasticsearch.xpack.core.transform.TransformDeprecations; | ||
import org.elasticsearch.xpack.core.transform.TransformMessages; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.function.Consumer; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
|
||
|
@@ -83,10 +89,8 @@ public static QueryConfig fromXContent(final XContentParser parser, boolean leni | |
Map<String, Object> source = parser.mapOrdered(); | ||
QueryBuilder query = null; | ||
|
||
try (XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().map(source); | ||
XContentParser sourceParser = XContentType.JSON.xContent().createParser(registry, LoggingDeprecationHandler.INSTANCE, | ||
BytesReference.bytes(xContentBuilder).streamInput())) { | ||
query = AbstractQueryBuilder.parseInnerQueryBuilder(sourceParser); | ||
try { | ||
query = queryFromXContent(source, registry, LoggingDeprecationHandler.INSTANCE); | ||
} catch (Exception e) { | ||
if (lenient) { | ||
logger.warn(TransformMessages.LOG_TRANSFORM_CONFIGURATION_BAD_QUERY, e); | ||
|
@@ -98,6 +102,20 @@ public static QueryConfig fromXContent(final XContentParser parser, boolean leni | |
return new QueryConfig(source, query); | ||
} | ||
|
||
private static QueryBuilder queryFromXContent( | ||
Map<String, Object> source, | ||
NamedXContentRegistry namedXContentRegistry, | ||
DeprecationHandler deprecationHandler | ||
) throws IOException { | ||
QueryBuilder query = null; | ||
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().map(source); | ||
XContentParser sourceParser = XContentType.JSON.xContent() | ||
.createParser(namedXContentRegistry, deprecationHandler, BytesReference.bytes(xContentBuilder).streamInput()); | ||
query = AbstractQueryBuilder.parseInnerQueryBuilder(sourceParser); | ||
|
||
return query; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(source, query); | ||
|
@@ -124,4 +142,37 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio | |
} | ||
return validationException; | ||
} | ||
|
||
public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer<DeprecationIssue> onDeprecation) { | ||
LoggingDeprecationAccumulationHandler deprecationLogger = new LoggingDeprecationAccumulationHandler(); | ||
|
||
try { | ||
queryFromXContent(source, namedXContentRegistry, deprecationLogger); | ||
} catch (IOException e) { | ||
onDeprecation.accept( | ||
new DeprecationIssue( | ||
Level.CRITICAL, | ||
"Transform [" + id + "]: " + TransformMessages.LOG_TRANSFORM_CONFIGURATION_BAD_QUERY, | ||
TransformDeprecations.QUERY_BREAKING_CHANGES_URL, | ||
e.getMessage(), | ||
false, | ||
null | ||
) | ||
); | ||
} | ||
|
||
deprecationLogger.getDeprecations().forEach(deprecationMessage -> { | ||
onDeprecation.accept( | ||
new DeprecationIssue( | ||
Level.CRITICAL, | ||
"Transform [" + id + "] uses deprecated query options", | ||
TransformDeprecations.QUERY_BREAKING_CHANGES_URL, | ||
deprecationMessage, | ||
false, | ||
null | ||
) | ||
); | ||
}); | ||
Comment on lines
+164
to
+175
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I like this way better than the way ML is doing it (these list of strings, etc.). Good refactoring I think++ |
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this local variable needed at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, for lenient parsing we only log the exception and query remains
null
. I could also have 2 return's, but I think 1 exit is better than 2.