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

Add built-in ILM policies for common user use cases #76791

Merged
merged 8 commits into from
Sep 23, 2021
36 changes: 36 additions & 0 deletions x-pack/plugin/core/src/main/resources/180-days-hot-warm-cold.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"phases": {
"hot": {
"actions": {
"rollover": {
"max_primary_shard_size": "50gb",
"max_age": "30d"
}
}
},
"warm": {
"actions": {
"shrink": {
"number_of_shards": 1
},
"forcemerge": {
"max_num_segments": 1
}
}
},
"cold": {
"min_age": "30d",
"actions": {}
},
"delete": {
"min_age": "180d",
"actions":{
"delete": {}
}
}
},
"_meta": {
"description": "built-in ILM policy using the hot, warm, and cold phases with a retention of 180 days",
"managed": true
}
}
32 changes: 32 additions & 0 deletions x-pack/plugin/core/src/main/resources/30-days-hot-warm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"phases": {
"hot": {
"actions": {
"rollover": {
"max_primary_shard_size": "50gb",
"max_age": "30d"
}
}
},
"warm": {
"actions": {
"shrink": {
"number_of_shards": 1
},
"forcemerge": {
"max_num_segments": 1
}
}
},
"delete": {
"min_age": "30d",
"actions":{
"delete": {}
}
}
},
"_meta": {
"description": "built-in ILM policy using the hot and warm phases with a retention of 30 days",
"managed": true
}
}
36 changes: 36 additions & 0 deletions x-pack/plugin/core/src/main/resources/365-days-hot-warm-cold.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"phases": {
"hot": {
"actions": {
"rollover": {
"max_primary_shard_size": "50gb",
"max_age": "30d"
}
}
},
"warm": {
"actions": {
"shrink": {
"number_of_shards": 1
},
"forcemerge": {
"max_num_segments": 1
}
}
},
"cold": {
"min_age": "30d",
"actions": {}
},
"delete": {
"min_age": "365d",
"actions":{
"delete": {}
}
}
},
"_meta": {
"description": "built-in ILM policy using the hot, warm, and cold phases with a retention of 365 days",
"managed": true
}
}
32 changes: 32 additions & 0 deletions x-pack/plugin/core/src/main/resources/7-days-hot-warm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"phases": {
"hot": {
"actions": {
"rollover": {
"max_primary_shard_size": "50gb",
"max_age": "7d"
}
}
},
"warm": {
"actions": {
"shrink": {
"number_of_shards": 1
},
"forcemerge": {
"max_num_segments": 1
}
}
},
"delete": {
"min_age": "7d",
"actions":{
"delete": {}
}
}
},
"_meta": {
"description": "built-in ILM policy using the hot and warm phases with a retention of 7 days",
"managed": true
}
}
36 changes: 36 additions & 0 deletions x-pack/plugin/core/src/main/resources/90-days-hot-warm-cold.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"phases": {
"hot": {
"actions": {
"rollover": {
"max_primary_shard_size": "50gb",
"max_age": "30d"
}
}
},
"warm": {
"actions": {
"shrink": {
"number_of_shards": 1
},
"forcemerge": {
"max_num_segments": 1
}
}
},
"cold": {
"min_age": "30d",
"actions": {}
},
"delete": {
"min_age": "90d",
"actions":{
"delete": {}
}
}
},
"_meta": {
"description": "built-in ILM policy using the hot, warm, and cold phases with a retention of 90 days",
"managed": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ public class StackTemplateRegistry extends IndexTemplateRegistry {
TEMPLATE_VERSION_VARIABLE
);

//////////////////////////////////////////////////////////
// Built in ILM policies for users to use
//////////////////////////////////////////////////////////
public static final String ILM_7_DAYS_POLICY_NAME = "7-days-hot-warm";
public static final String ILM_30_DAYS_POLICY_NAME = "30-days-hot-warm";
public static final String ILM_90_DAYS_POLICY_NAME = "90-days-hot-warm-cold";
public static final String ILM_180_DAYS_POLICY_NAME = "180-days-hot-warm-cold";
public static final String ILM_365_DAYS_POLICY_NAME = "365-days-hot-warm-cold";
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to avoid spelling out which phases we are using in the name of the policy, so that we could later change this, e.g. if we later realize that it would make sense to use frozen when users keep data for 365 days?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it'd be nice to avoid those names, but currently we don't have a concept of a "title" of a policy from within ILM or the UI, so if we made those less general, it would be much harder for a user to determine what the policy does (especially since these are intended for users not that familiar with ILM) if we named it even more generic like "365-days".

Do you think the lack of specification for upgrades is better, or would it be better to be more specific so a user can tell what it is doing?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather like to be less specific so that we can more easily change our mind on what we think are good defaults. Maybe the name could be something like 180-days-default instead of 180-days to make it clearer that there are multiple ways to retain data for 180 days and that this is just one way of doing it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, I've renamed the policies.


public static final LifecyclePolicyConfig ILM_7_DAYS_POLICY = new LifecyclePolicyConfig(
ILM_7_DAYS_POLICY_NAME,
"/" + ILM_7_DAYS_POLICY_NAME + ".json"
);
public static final LifecyclePolicyConfig ILM_30_DAYS_POLICY = new LifecyclePolicyConfig(
ILM_30_DAYS_POLICY_NAME,
"/" + ILM_30_DAYS_POLICY_NAME + ".json"
);
public static final LifecyclePolicyConfig ILM_90_DAYS_POLICY = new LifecyclePolicyConfig(
ILM_90_DAYS_POLICY_NAME,
"/" + ILM_90_DAYS_POLICY_NAME + ".json"
);
public static final LifecyclePolicyConfig ILM_180_DAYS_POLICY = new LifecyclePolicyConfig(
ILM_180_DAYS_POLICY_NAME,
"/" + ILM_180_DAYS_POLICY_NAME + ".json"
);
public static final LifecyclePolicyConfig ILM_365_DAYS_POLICY = new LifecyclePolicyConfig(
ILM_365_DAYS_POLICY_NAME,
"/" + ILM_365_DAYS_POLICY_NAME + ".json"
);

//////////////////////////////////////////////////////////
// Logs components (for matching logs-*-* indices)
//////////////////////////////////////////////////////////
Expand Down Expand Up @@ -177,7 +207,16 @@ private void updateEnabledSetting(boolean newValue) {
@Override
protected List<LifecyclePolicyConfig> getPolicyConfigs() {
if (stackTemplateEnabled) {
return Arrays.asList(LOGS_ILM_POLICY, METRICS_ILM_POLICY, SYNTHETICS_ILM_POLICY);
return Arrays.asList(
LOGS_ILM_POLICY,
METRICS_ILM_POLICY,
SYNTHETICS_ILM_POLICY,
ILM_7_DAYS_POLICY,
ILM_30_DAYS_POLICY,
ILM_90_DAYS_POLICY,
ILM_180_DAYS_POLICY,
ILM_365_DAYS_POLICY
);
} else {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
import org.elasticsearch.threadpool.TestThreadPool;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ilm.DeleteAction;
import org.elasticsearch.xpack.core.ilm.ForceMergeAction;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata;
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata;
import org.elasticsearch.xpack.core.ilm.LifecycleType;
import org.elasticsearch.xpack.core.ilm.OperationMode;
import org.elasticsearch.xpack.core.ilm.RolloverAction;
import org.elasticsearch.xpack.core.ilm.ShrinkAction;
import org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType;
import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction;
import org.junit.After;
Expand Down Expand Up @@ -91,6 +93,8 @@ public void createRegistryAndClient() {
(p) -> TimeseriesLifecycleType.INSTANCE
),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ForceMergeAction.NAME), ForceMergeAction::parse),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse)
)
);
Expand Down Expand Up @@ -154,7 +158,12 @@ public void testThatNonExistingPoliciesAreAddedImmediately() throws Exception {
anyOf(
equalTo(StackTemplateRegistry.LOGS_ILM_POLICY_NAME),
equalTo(StackTemplateRegistry.METRICS_ILM_POLICY_NAME),
equalTo(StackTemplateRegistry.SYNTHETICS_ILM_POLICY_NAME)
equalTo(StackTemplateRegistry.SYNTHETICS_ILM_POLICY_NAME),
equalTo(StackTemplateRegistry.ILM_7_DAYS_POLICY_NAME),
equalTo(StackTemplateRegistry.ILM_30_DAYS_POLICY_NAME),
equalTo(StackTemplateRegistry.ILM_90_DAYS_POLICY_NAME),
equalTo(StackTemplateRegistry.ILM_180_DAYS_POLICY_NAME),
equalTo(StackTemplateRegistry.ILM_365_DAYS_POLICY_NAME)
)
);
assertNotNull(listener);
Expand All @@ -173,7 +182,7 @@ public void testThatNonExistingPoliciesAreAddedImmediately() throws Exception {

ClusterChangedEvent event = createClusterChangedEvent(Collections.emptyMap(), nodes);
registry.clusterChanged(event);
assertBusy(() -> assertThat(calledTimes.get(), equalTo(3)));
assertBusy(() -> assertThat(calledTimes.get(), equalTo(8)));
}

public void testPolicyAlreadyExists() {
Expand All @@ -185,7 +194,7 @@ public void testPolicyAlreadyExists() {
.stream()
.map(policyConfig -> policyConfig.load(xContentRegistry))
.collect(Collectors.toList());
assertThat(policies, hasSize(3));
assertThat(policies, hasSize(8));
policies.forEach(p -> policyMap.put(p.getName(), p));

client.setVerifier((action, request, listener) -> {
Expand Down Expand Up @@ -214,7 +223,7 @@ public void testPolicyAlreadyExistsButDiffers() throws IOException {
.stream()
.map(policyConfig -> policyConfig.load(xContentRegistry))
.collect(Collectors.toList());
assertThat(policies, hasSize(3));
assertThat(policies, hasSize(8));
policies.forEach(p -> policyMap.put(p.getName(), p));

client.setVerifier((action, request, listener) -> {
Expand Down