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

[Transform] Improve transform upgrader #79601

Merged
merged 13 commits into from
Oct 25, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,9 @@ private static UpgradeTransformsResponse createTestInstance() {

private static void toXContent(UpgradeTransformsResponse response, XContentBuilder builder) throws IOException {
builder.startObject();
if (response.getUpdated() != 0) {
builder.field("updated", response.getUpdated());
}
if (response.getNoAction() != 0) {
builder.field("no_action", response.getNoAction());
}
if (response.getNeedsUpdate() != 0) {
builder.field("needs_update", response.getNeedsUpdate());
}
builder.field("updated", response.getUpdated());
builder.field("no_action", response.getNoAction());
builder.field("needs_update", response.getNeedsUpdate());
builder.endObject();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@
package org.elasticsearch.xpack.core.transform;

public class TransformDeprecations {

// base url for the _current_ release
private static final String REFERENCE_BASE_URL = "https://www.elastic.co/guide/en/elasticsearch/reference/master/";

public static final String UPGRADE_TRANSFFORM_URL = REFERENCE_BASE_URL + "upgrade-transforms.html";
hendrikmuhs marked this conversation as resolved.
Show resolved Hide resolved
hendrikmuhs marked this conversation as resolved.
Show resolved Hide resolved

// breaking changes base url for the _next_ major release
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";

public static final String ACTION_UPGRADE_TRANSFORMS_API = "Use the upgrade transforms API to fix your transforms.";

public static final String ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED =
"[max_page_search_size] is deprecated inside pivot. Use settings instead.";

private TransformDeprecations() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,9 @@ public void writeTo(StreamOutput out) throws IOException {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
if (updated != 0L) {
builder.field("updated", updated);
}
if (noAction != 0L) {
builder.field("no_action", noAction);
}
if (needsUpdate != 0L) {
builder.field("needs_update", needsUpdate);
}
builder.field("updated", updated);
builder.field("no_action", noAction);
builder.field("needs_update", needsUpdate);
builder.endObject();
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xpack.core.common.time.TimeUtils;
import org.elasticsearch.xpack.core.common.validation.SourceDestValidator;
import org.elasticsearch.xpack.core.common.validation.SourceDestValidator.SourceDestValidation;
Expand Down Expand Up @@ -398,8 +398,8 @@ public List<DeprecationIssue> checkForDeprecations(NamedXContentRegistry namedXC
new DeprecationIssue(
Level.CRITICAL,
"Transform [" + id + "] is too old",
TransformDeprecations.BREAKING_CHANGES_BASE_URL,
"The configuration uses an old format, you can use [_update] or [_upgrade] to update",
TransformDeprecations.UPGRADE_TRANSFFORM_URL,
hendrikmuhs marked this conversation as resolved.
Show resolved Hide resolved
TransformDeprecations.ACTION_UPGRADE_TRANSFORMS_API,
false,
null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.search.aggregations.MultiBucketConsumerService;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.search.aggregations.MultiBucketConsumerService;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level;
import org.elasticsearch.xpack.core.transform.TransformDeprecations;
Expand Down Expand Up @@ -91,7 +91,7 @@ public PivotConfig(final GroupConfig groups, final AggregationConfig aggregation
deprecationLogger.critical(
DeprecationCategory.API,
TransformField.MAX_PAGE_SEARCH_SIZE.getPreferredName(),
"[max_page_search_size] is deprecated inside pivot please use settings instead"
TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED
);
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public void checkForDeprecations(String id, NamedXContentRegistry namedXContentR
Level.WARNING,
"Transform [" + id + "] uses deprecated max_page_search_size",
TransformDeprecations.BREAKING_CHANGES_BASE_URL,
"[max_page_search_size] is deprecated inside pivot please use settings instead",
TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED,
false,
null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level;
import org.elasticsearch.xpack.core.transform.AbstractSerializingTransformTestCase;
import org.elasticsearch.xpack.core.transform.TransformDeprecations;
import org.elasticsearch.xpack.core.transform.transforms.latest.LatestConfig;
import org.elasticsearch.xpack.core.transform.transforms.latest.LatestConfigTests;
import org.elasticsearch.xpack.core.transform.transforms.pivot.PivotConfig;
Expand Down Expand Up @@ -510,7 +511,7 @@ public void testRewriteForUpdate() throws IOException {
assertTrue(transformConfigRewritten.getSettings().getDatesAsEpochMillis());
assertFalse(transformConfigRewritten.getSettings().getAlignCheckpoints());

assertWarnings("[max_page_search_size] is deprecated inside pivot please use settings instead");
assertWarnings(TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED);
assertEquals(Version.CURRENT, transformConfigRewritten.getVersion());
}

Expand Down Expand Up @@ -583,7 +584,7 @@ public void testRewriteForUpdateMaxPageSizeSearchConflicting() throws IOExceptio
assertNotNull(transformConfigRewritten.getSettings().getMaxPageSearchSize());
assertEquals(555L, transformConfigRewritten.getSettings().getMaxPageSearchSize().longValue());
assertEquals(Version.CURRENT, transformConfigRewritten.getVersion());
assertWarnings("[max_page_search_size] is deprecated inside pivot please use settings instead");
assertWarnings(TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED);
}

public void testRewriteForBWCOfDateNormalization() throws IOException {
Expand Down Expand Up @@ -739,7 +740,7 @@ public void testCheckForDeprecations() {
TransformConfig deprecatedConfig = randomTransformConfigWithDeprecatedFields(id, Version.CURRENT);

// check _and_ clear warnings
assertWarnings("[max_page_search_size] is deprecated inside pivot please use settings instead");
assertWarnings(TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED);

// important: checkForDeprecations does _not_ create new deprecation warnings
assertThat(
Expand All @@ -749,8 +750,8 @@ public void testCheckForDeprecations() {
new DeprecationIssue(
Level.WARNING,
"Transform [" + id + "] uses deprecated max_page_search_size",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html",
"[max_page_search_size] is deprecated inside pivot please use settings instead",
TransformDeprecations.BREAKING_CHANGES_BASE_URL,
TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED,
false,
null
)
Expand All @@ -761,7 +762,7 @@ public void testCheckForDeprecations() {
deprecatedConfig = randomTransformConfigWithDeprecatedFields(id, Version.V_7_10_0);

// check _and_ clear warnings
assertWarnings("[max_page_search_size] is deprecated inside pivot please use settings instead");
assertWarnings(TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED);

// important: checkForDeprecations does _not_ create new deprecation warnings
assertThat(
Expand All @@ -771,8 +772,8 @@ public void testCheckForDeprecations() {
new DeprecationIssue(
Level.WARNING,
"Transform [" + id + "] uses deprecated max_page_search_size",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html",
"[max_page_search_size] is deprecated inside pivot please use settings instead",
TransformDeprecations.BREAKING_CHANGES_BASE_URL,
TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED,
false,
null
)
Expand All @@ -783,7 +784,7 @@ public void testCheckForDeprecations() {
deprecatedConfig = randomTransformConfigWithDeprecatedFields(id, Version.V_7_4_0);

// check _and_ clear warnings
assertWarnings("[max_page_search_size] is deprecated inside pivot please use settings instead");
assertWarnings(TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED);

// important: checkForDeprecations does _not_ create new deprecation warnings
assertThat(
Expand All @@ -793,16 +794,16 @@ public void testCheckForDeprecations() {
new DeprecationIssue(
Level.CRITICAL,
"Transform [" + id + "] is too old",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html",
"The configuration uses an old format, you can use [_update] or [_upgrade] to update",
TransformDeprecations.UPGRADE_TRANSFFORM_URL,
hendrikmuhs marked this conversation as resolved.
Show resolved Hide resolved
TransformDeprecations.ACTION_UPGRADE_TRANSFORMS_API,
false,
null
),
new DeprecationIssue(
Level.WARNING,
"Transform [" + id + "] uses deprecated max_page_search_size",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html",
"[max_page_search_size] is deprecated inside pivot please use settings instead",
TransformDeprecations.BREAKING_CHANGES_BASE_URL,
TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED,
false,
null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xpack.core.transform.AbstractSerializingTransformTestCase;
import org.elasticsearch.xpack.core.transform.TransformDeprecations;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -437,7 +438,7 @@ public void testAggNameValidationsWithInvalidFieldnames() {

public void testDeprecation() {
PivotConfig pivotConfig = randomPivotConfigWithDeprecatedFields();
assertWarnings("[max_page_search_size] is deprecated inside pivot please use settings instead");
assertWarnings(TransformDeprecations.ACTION_MAX_PAGE_SEARCH_SIZE_IS_DEPRECATED);
}

private static String dotJoin(String... fields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.index.store.StoreStats;
import org.elasticsearch.index.warmer.WarmerStats;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.search.suggest.completion.CompletionStats;
import org.elasticsearch.test.client.NoOpClient;
import org.elasticsearch.xpack.core.transform.transforms.TransformCheckpoint;
Expand Down Expand Up @@ -138,8 +139,13 @@ public void createComponents() {
if (mockClientForCheckpointing == null) {
mockClientForCheckpointing = new MockClientForCheckpointing("TransformCheckpointServiceNodeTests");
}

transformsConfigManager = new IndexBasedTransformConfigManager(client(), xContentRegistry());
ClusterService clusterService = mock(ClusterService.class);
transformsConfigManager = new IndexBasedTransformConfigManager(
clusterService,
TestIndexNameExpressionResolver.newInstance(),
client(),
xContentRegistry()
);

// use a mock for the checkpoint service
TransformAuditor mockAuditor = mock(TransformAuditor.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
Expand Down Expand Up @@ -49,14 +51,21 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.mockito.Mockito.mock;

public class TransformConfigManagerTests extends TransformSingleNodeTestCase {

private IndexBasedTransformConfigManager transformConfigManager;

@Before
public void createComponents() {
transformConfigManager = new IndexBasedTransformConfigManager(client(), xContentRegistry());
ClusterService clusterService = mock(ClusterService.class);
transformConfigManager = new IndexBasedTransformConfigManager(
clusterService,
TestIndexNameExpressionResolver.newInstance(),
client(),
xContentRegistry()
);
}

public void testGetMissingTransform() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ public Collection<Object> createComponents(
IndexNameExpressionResolver expressionResolver,
Supplier<RepositoriesService> repositoriesServiceSupplier
) {
TransformConfigManager configManager = new IndexBasedTransformConfigManager(client, xContentRegistry);
TransformConfigManager configManager = new IndexBasedTransformConfigManager(
clusterService,
expressionResolver,
client,
xContentRegistry
);
TransformAuditor auditor = new TransformAuditor(client, clusterService.getNodeName(), clusterService);
TransformCheckpointService checkpointService = new TransformCheckpointService(
Clock.systemUTC(),
Expand Down
Loading