Skip to content

Commit a246cc9

Browse files
author
Hendrik Muhs
authored
[Transform] add method to collect deprecations from a transform configuration (#77565) (#77752)
add checkForDeprecations to TransformConfig and implement deprecation checks
1 parent cfa1a34 commit a246cc9

36 files changed

+415
-59
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
package org.elasticsearch.xpack.deprecation;
7+
package org.elasticsearch.xpack.core.deprecation;
88

99
import org.elasticsearch.Version;
1010
import org.elasticsearch.core.Nullable;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
package org.elasticsearch.xpack.core.ml.utils;
7+
package org.elasticsearch.xpack.core.deprecation;
88

99
import org.elasticsearch.common.logging.LoggerMessageFormat;
1010
import org.elasticsearch.common.xcontent.DeprecationHandler;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/XContentObjectTransformer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.index.query.AbstractQueryBuilder;
2020
import org.elasticsearch.index.query.QueryBuilder;
2121
import org.elasticsearch.search.aggregations.AggregatorFactories;
22+
import org.elasticsearch.xpack.core.deprecation.LoggingDeprecationAccumulationHandler;
2223

2324
import java.io.IOException;
2425
import java.util.ArrayList;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.core.transform;
9+
10+
public class TransformDeprecations {
11+
public static final String BREAKING_CHANGES_BASE_URL =
12+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html";
13+
14+
public static final String QUERY_BREAKING_CHANGES_URL = BREAKING_CHANGES_BASE_URL + "#breaking_80_search_changes";
15+
16+
public static final String AGGS_BREAKING_CHANGES_URL = BREAKING_CHANGES_BASE_URL + "#breaking_80_aggregations_changes";
17+
18+
private TransformDeprecations() {}
19+
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/DestConfig.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@
99

1010
import org.elasticsearch.Version;
1111
import org.elasticsearch.action.ActionRequestValidationException;
12-
import org.elasticsearch.common.xcontent.ParseField;
1312
import org.elasticsearch.common.io.stream.StreamInput;
1413
import org.elasticsearch.common.io.stream.StreamOutput;
1514
import org.elasticsearch.common.io.stream.Writeable;
1615
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
16+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
17+
import org.elasticsearch.common.xcontent.ParseField;
1718
import org.elasticsearch.common.xcontent.ToXContentObject;
1819
import org.elasticsearch.common.xcontent.XContentBuilder;
1920
import org.elasticsearch.common.xcontent.XContentParser;
21+
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
2022
import org.elasticsearch.xpack.core.transform.utils.ExceptionsHelper;
2123

2224
import java.io.IOException;
2325
import java.util.Objects;
26+
import java.util.function.Consumer;
2427

2528
import static org.elasticsearch.action.ValidateActions.addValidationError;
2629
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
@@ -75,6 +78,9 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio
7578
return validationException;
7679
}
7780

81+
public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer<DeprecationIssue> onDeprecation) {
82+
}
83+
7884
@Override
7985
public void writeTo(StreamOutput out) throws IOException {
8086
out.writeString(index);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/QueryConfig.java

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.common.io.stream.StreamInput;
1616
import org.elasticsearch.common.io.stream.StreamOutput;
1717
import org.elasticsearch.common.io.stream.Writeable;
18+
import org.elasticsearch.common.xcontent.DeprecationHandler;
1819
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1920
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
2021
import org.elasticsearch.common.xcontent.ToXContentObject;
@@ -25,12 +26,17 @@
2526
import org.elasticsearch.index.query.AbstractQueryBuilder;
2627
import org.elasticsearch.index.query.MatchAllQueryBuilder;
2728
import org.elasticsearch.index.query.QueryBuilder;
29+
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
30+
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level;
31+
import org.elasticsearch.xpack.core.deprecation.LoggingDeprecationAccumulationHandler;
32+
import org.elasticsearch.xpack.core.transform.TransformDeprecations;
2833
import org.elasticsearch.xpack.core.transform.TransformMessages;
2934

3035
import java.io.IOException;
3136
import java.util.Collections;
3237
import java.util.Map;
3338
import java.util.Objects;
39+
import java.util.function.Consumer;
3440

3541
import static org.elasticsearch.action.ValidateActions.addValidationError;
3642

@@ -83,10 +89,8 @@ public static QueryConfig fromXContent(final XContentParser parser, boolean leni
8389
Map<String, Object> source = parser.mapOrdered();
8490
QueryBuilder query = null;
8591

86-
try (XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().map(source);
87-
XContentParser sourceParser = XContentType.JSON.xContent().createParser(registry, LoggingDeprecationHandler.INSTANCE,
88-
BytesReference.bytes(xContentBuilder).streamInput())) {
89-
query = AbstractQueryBuilder.parseInnerQueryBuilder(sourceParser);
92+
try {
93+
query = queryFromXContent(source, registry, LoggingDeprecationHandler.INSTANCE);
9094
} catch (Exception e) {
9195
if (lenient) {
9296
logger.warn(TransformMessages.LOG_TRANSFORM_CONFIGURATION_BAD_QUERY, e);
@@ -98,6 +102,20 @@ public static QueryConfig fromXContent(final XContentParser parser, boolean leni
98102
return new QueryConfig(source, query);
99103
}
100104

105+
private static QueryBuilder queryFromXContent(
106+
Map<String, Object> source,
107+
NamedXContentRegistry namedXContentRegistry,
108+
DeprecationHandler deprecationHandler
109+
) throws IOException {
110+
QueryBuilder query = null;
111+
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().map(source);
112+
XContentParser sourceParser = XContentType.JSON.xContent()
113+
.createParser(namedXContentRegistry, deprecationHandler, BytesReference.bytes(xContentBuilder).streamInput());
114+
query = AbstractQueryBuilder.parseInnerQueryBuilder(sourceParser);
115+
116+
return query;
117+
}
118+
101119
@Override
102120
public int hashCode() {
103121
return Objects.hash(source, query);
@@ -124,4 +142,37 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio
124142
}
125143
return validationException;
126144
}
145+
146+
public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer<DeprecationIssue> onDeprecation) {
147+
LoggingDeprecationAccumulationHandler deprecationLogger = new LoggingDeprecationAccumulationHandler();
148+
149+
try {
150+
queryFromXContent(source, namedXContentRegistry, deprecationLogger);
151+
} catch (IOException e) {
152+
onDeprecation.accept(
153+
new DeprecationIssue(
154+
Level.CRITICAL,
155+
"Transform [" + id + "]: " + TransformMessages.LOG_TRANSFORM_CONFIGURATION_BAD_QUERY,
156+
TransformDeprecations.QUERY_BREAKING_CHANGES_URL,
157+
e.getMessage(),
158+
false,
159+
null
160+
)
161+
);
162+
}
163+
164+
deprecationLogger.getDeprecations().forEach(deprecationMessage -> {
165+
onDeprecation.accept(
166+
new DeprecationIssue(
167+
Level.CRITICAL,
168+
"Transform [" + id + "] uses deprecated query options",
169+
TransformDeprecations.QUERY_BREAKING_CHANGES_URL,
170+
deprecationMessage,
171+
false,
172+
null
173+
)
174+
);
175+
});
176+
177+
}
127178
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/RetentionPolicyConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99

1010
import org.elasticsearch.action.ActionRequestValidationException;
1111
import org.elasticsearch.common.io.stream.NamedWriteable;
12+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
1213
import org.elasticsearch.common.xcontent.ToXContentObject;
14+
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
15+
16+
import java.util.function.Consumer;
1317

1418
public interface RetentionPolicyConfig extends ToXContentObject, NamedWriteable {
1519
ActionRequestValidationException validate(ActionRequestValidationException validationException);
20+
21+
void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer<DeprecationIssue> onDeprecation);
1622
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/SettingsConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414
import org.elasticsearch.common.io.stream.StreamOutput;
1515
import org.elasticsearch.common.io.stream.Writeable;
1616
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
17+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
1718
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
1819
import org.elasticsearch.common.xcontent.ToXContentObject;
1920
import org.elasticsearch.common.xcontent.XContentBuilder;
2021
import org.elasticsearch.common.xcontent.XContentParser;
2122
import org.elasticsearch.search.aggregations.MultiBucketConsumerService;
23+
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
2224
import org.elasticsearch.xpack.core.transform.TransformField;
2325

2426
import java.io.IOException;
2527
import java.util.Objects;
28+
import java.util.function.Consumer;
2629

2730
import static org.elasticsearch.action.ValidateActions.addValidationError;
2831
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
@@ -139,6 +142,9 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio
139142
return validationException;
140143
}
141144

145+
public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer<DeprecationIssue> onDeprecation) {
146+
}
147+
142148
@Override
143149
public void writeTo(StreamOutput out) throws IOException {
144150
out.writeOptionalInt(maxPageSearchSize);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/SourceConfig.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@
99

1010
import org.elasticsearch.Version;
1111
import org.elasticsearch.action.ActionRequestValidationException;
12-
import org.elasticsearch.common.xcontent.ParseField;
1312
import org.elasticsearch.common.Strings;
1413
import org.elasticsearch.common.io.stream.StreamInput;
1514
import org.elasticsearch.common.io.stream.StreamOutput;
1615
import org.elasticsearch.common.io.stream.Writeable;
1716
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
17+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
18+
import org.elasticsearch.common.xcontent.ParseField;
1819
import org.elasticsearch.common.xcontent.ToXContentObject;
1920
import org.elasticsearch.common.xcontent.XContentBuilder;
2021
import org.elasticsearch.common.xcontent.XContentParser;
2122
import org.elasticsearch.license.RemoteClusterLicenseChecker;
2223
import org.elasticsearch.search.builder.SearchSourceBuilder;
24+
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
2325
import org.elasticsearch.xpack.core.transform.TransformField;
2426
import org.elasticsearch.xpack.core.transform.utils.ExceptionsHelper;
2527

@@ -29,6 +31,7 @@
2931
import java.util.List;
3032
import java.util.Map;
3133
import java.util.Objects;
34+
import java.util.function.Consumer;
3235

3336
import static java.util.stream.Collectors.toMap;
3437
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
@@ -129,6 +132,10 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio
129132
return queryConfig.validate(validationException);
130133
}
131134

135+
public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer<DeprecationIssue> onDeprecation) {
136+
queryConfig.checkForDeprecations(id, namedXContentRegistry, onDeprecation);
137+
}
138+
132139
public boolean requiresRemoteCluster() {
133140
return Arrays.stream(index).anyMatch(RemoteClusterLicenseChecker::isRemoteIndex);
134141
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TimeRetentionPolicyConfig.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@
1111
import org.elasticsearch.common.Strings;
1212
import org.elasticsearch.common.io.stream.StreamInput;
1313
import org.elasticsearch.common.io.stream.StreamOutput;
14-
import org.elasticsearch.core.TimeValue;
1514
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
15+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
1616
import org.elasticsearch.common.xcontent.ObjectParser;
1717
import org.elasticsearch.common.xcontent.XContentBuilder;
1818
import org.elasticsearch.common.xcontent.XContentParser;
19+
import org.elasticsearch.core.TimeValue;
20+
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
1921
import org.elasticsearch.xpack.core.transform.TransformField;
2022
import org.elasticsearch.xpack.core.transform.utils.ExceptionsHelper;
2123

2224
import java.io.IOException;
2325
import java.util.Objects;
26+
import java.util.function.Consumer;
2427

2528
import static org.elasticsearch.action.ValidateActions.addValidationError;
2629
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
@@ -90,6 +93,10 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio
9093
return validationException;
9194
}
9295

96+
@Override
97+
public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer<DeprecationIssue> onDeprecation) {
98+
}
99+
93100
@Override
94101
public void writeTo(final StreamOutput out) throws IOException {
95102
out.writeString(field);

0 commit comments

Comments
 (0)