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

[Transforms] fix bug when unsetting retention policy #87711

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/87711.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 87711
summary: "[Transforms] fix bug when unsetting retention policy"
area: Transform
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
import org.elasticsearch.xpack.core.transform.action.PutTransformAction;
import org.elasticsearch.xpack.core.transform.action.StartTransformAction;
import org.elasticsearch.xpack.core.transform.action.StopTransformAction;
import org.elasticsearch.xpack.core.transform.transforms.NullRetentionPolicyConfig;
import org.elasticsearch.xpack.core.transform.transforms.RetentionPolicyConfig;
import org.elasticsearch.xpack.core.transform.transforms.SyncConfig;
import org.elasticsearch.xpack.core.transform.transforms.TimeRetentionPolicyConfig;
Expand Down Expand Up @@ -534,6 +535,11 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
TransformField.TIME.getPreferredName(),
TimeRetentionPolicyConfig::new
),
new NamedWriteableRegistry.Entry(
Copy link
Member

Choose a reason for hiding this comment

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

TransformNamedXContentProvider is also missing the NullRetentionPolicyConfig named writable

Copy link
Member Author

Choose a reason for hiding this comment

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

@davidkyle it isn't required. This thing is never written to XContent. But I can add it for completeness.

Copy link
Member

Choose a reason for hiding this comment

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

Please do I think it is worth having to avoid a similar problem in future

RetentionPolicyConfig.class,
NullRetentionPolicyConfig.NAME.getPreferredName(),
i -> NullRetentionPolicyConfig.INSTANCE
),
// Voting Only Node
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VOTING_ONLY, VotingOnlyNodeFeatureSetUsage::new),
// Frozen indices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.elasticsearch.plugins.spi.NamedXContentProvider;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xpack.core.transform.transforms.NullRetentionPolicyConfig;
import org.elasticsearch.xpack.core.transform.transforms.RetentionPolicyConfig;
import org.elasticsearch.xpack.core.transform.transforms.SyncConfig;
import org.elasticsearch.xpack.core.transform.transforms.TimeRetentionPolicyConfig;
Expand All @@ -23,7 +24,12 @@ public class TransformNamedXContentProvider implements NamedXContentProvider {
public List<NamedXContentRegistry.Entry> getNamedXContentParsers() {
return Arrays.asList(
new NamedXContentRegistry.Entry(SyncConfig.class, TransformField.TIME, TimeSyncConfig::parse),
new NamedXContentRegistry.Entry(RetentionPolicyConfig.class, TransformField.TIME, TimeRetentionPolicyConfig::parse)
new NamedXContentRegistry.Entry(RetentionPolicyConfig.class, TransformField.TIME, TimeRetentionPolicyConfig::parse),
new NamedXContentRegistry.Entry(
RetentionPolicyConfig.class,
NullRetentionPolicyConfig.NAME,
(p, c) -> NullRetentionPolicyConfig.INSTANCE
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private NullRetentionPolicyConfig() {}

@Override
public ActionRequestValidationException validate(ActionRequestValidationException validationException) {
throw new UnsupportedOperationException();
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.transform.transforms.QueryConfig;
import org.elasticsearch.xpack.core.transform.transforms.SettingsConfig;
import org.elasticsearch.xpack.core.transform.transforms.TimeRetentionPolicyConfig;
import org.elasticsearch.xpack.core.transform.transforms.TimeSyncConfig;
import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;
import org.elasticsearch.xpack.core.transform.transforms.pivot.SingleGroupSource;
Expand All @@ -38,7 +39,9 @@
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.oneOf;

@SuppressWarnings("removal")
Expand Down Expand Up @@ -263,6 +266,35 @@ public void testContinuousTransformUpdate() throws Exception {
deleteTransform(config.getId());
}

public void testRetentionPolicyDelete() throws Exception {
String indexName = "retention-index";
String transformId = "transform-retention-update";
String dest = "retention-policy-dest";
createReviewsIndex(indexName, 10, NUM_USERS, TransformIT::getUserIdForRow, TransformIT::getDateStringForRow);

Map<String, SingleGroupSource> groups = new HashMap<>();
groups.put("by-user", new TermsGroupSource("user_id", null, false));

AggregatorFactories.Builder aggs = AggregatorFactories.builder()
.addAggregator(AggregationBuilders.max("timestamp").field("timestamp"));

TransformConfig config = createTransformConfigBuilder(transformId, dest, QueryConfig.matchAll(), indexName).setPivotConfig(
createPivotConfig(groups, aggs)
)
.setSyncConfig(new TimeSyncConfig("timestamp", TimeValue.timeValueSeconds(1)))
.setRetentionPolicyConfig(new TimeRetentionPolicyConfig("timestamp", TimeValue.timeValueDays(1)))
.build();
putTransform(transformId, Strings.toString(config), RequestOptions.DEFAULT);
assertThat(getTransform(transformId), hasKey("retention_policy"));
String update = """
{
"retention_policy": null
}
""";
updateConfig(transformId, update);
assertThat(getTransform(transformId), not(hasKey("retention_policy")));
}

public void testStopWaitForCheckpoint() throws Exception {
String indexName = "wait-for-checkpoint-reviews";
String transformId = "transform-wait-for-checkpoint";
Expand Down