1
0
Эх сурвалжийг харах

ILM/SLM history policies forcemerge in hot and dsl configuration. (#103190)

This configures the ILM and SLM data streams to forcemerge
in the hot tier, to avoid a large number of segments.

This also bumps the version of the managed index templates and configures
lifecycle as the management system - this would have the effect of
having new data streams due to the version bump that are managed by
data stream lifecycle (i.e. ilm-history-6 and slm-history-6 will be
created on the next Elasticsearch version)
Andrei Dan 1 жил өмнө
parent
commit
1d127b0525

+ 5 - 0
docs/changelog/103190.yaml

@@ -0,0 +1,5 @@
+pr: 103190
+summary: ILM/SLM history policies forcemerge in hot and dsl configuration
+area: ILM+SLM
+type: enhancement
+issues: []

+ 2 - 2
modules/mapper-extras/src/internalClusterTest/java/org/elasticsearch/index/mapper/MatchOnlyTextMapperIT.java

@@ -55,7 +55,7 @@ public class MatchOnlyTextMapperIT extends ESIntegTestCase {
                             .startObject()
                             .field(
                                 "message",
-                                "[.ds-.slm-history-5-2023.09.20-"
+                                "[.ds-.slm-history-6-2023.09.20-"
                                     + randomInt()
                                     + "][0] marking and sending shard failed due to [failed recovery]"
                             )
@@ -104,7 +104,7 @@ public class MatchOnlyTextMapperIT extends ESIntegTestCase {
                             .startObject()
                             .field(
                                 "message",
-                                "[.ds-.slm-history-5-2023.09.20-"
+                                "[.ds-.slm-history-6-2023.09.20-"
                                     + randomInt()
                                     + "][0] marking and sending shard failed due to [failed recovery]"
                             )

+ 2 - 2
server/src/test/java/org/elasticsearch/common/logging/HeaderWarningTests.java

@@ -318,8 +318,8 @@ public class HeaderWarningTests extends ESTestCase {
                 + ".monitoring-beats-mb => [.monitoring-beats-8-*],.monitoring-ent-search-mb => [.monitoring-ent-search-8-*],"
                 + ".monitoring-es-mb => [.monitoring-es-8-*],.monitoring-kibana-mb => [.monitoring-kibana-8-*],"
                 + ".monitoring-logstash-mb => [.monitoring-logstash-8-*],.profiling-ilm-lock => [.profiling-ilm-lock*],"
-                + ".slm-history => [.slm-history-5*],.watch-history-16 => [.watcher-history-16*],"
-                + "behavioral_analytics-events-default => [behavioral_analytics-events-*],ilm-history => [ilm-history-5*],"
+                + ".slm-history => [.slm-history-6*],.watch-history-16 => [.watcher-history-16*],"
+                + "behavioral_analytics-events-default => [behavioral_analytics-events-*],ilm-history => [ilm-history-6*],"
                 + "logs => [logs-*-*],metrics => [metrics-*-*],profiling-events => [profiling-events*],profiling-executables => "
                 + "[profiling-executables*],profiling-metrics => [profiling-metrics*],profiling-returnpads-private => "
                 + "[.profiling-returnpads-private*],profiling-sq-executables => [.profiling-sq-executables*],"

+ 3 - 0
x-pack/plugin/core/template-resources/src/main/resources/ilm-history-ilm-policy.json

@@ -5,6 +5,9 @@
         "rollover": {
           "max_primary_shard_size": "50gb",
           "max_age": "30d"
+        },
+        "forcemerge": {
+          "max_num_segments": 1
         }
       }
     },

+ 4 - 2
x-pack/plugin/core/template-resources/src/main/resources/ilm-history.json

@@ -9,8 +9,10 @@
     "settings": {
       "index.number_of_shards": 1,
       "index.number_of_replicas": 0,
-      "index.auto_expand_replicas": "0-1",
-      "index.lifecycle.name": "ilm-history-ilm-policy"
+      "index.auto_expand_replicas": "0-1"
+    },
+    "lifecycle": {
+      "data_retention": "90d"
     },
     "mappings": {
         "dynamic": false,

+ 3 - 0
x-pack/plugin/core/template-resources/src/main/resources/slm-history-ilm-policy.json

@@ -5,6 +5,9 @@
         "rollover": {
           "max_primary_shard_size": "50gb",
           "max_age": "30d"
+        },
+        "forcemerge": {
+          "max_num_segments": 1
         }
       }
     },

+ 4 - 2
x-pack/plugin/core/template-resources/src/main/resources/slm-history.json

@@ -10,8 +10,10 @@
     "settings": {
       "index.number_of_shards": 1,
       "index.number_of_replicas": 0,
-      "index.auto_expand_replicas": "0-1",
-      "index.lifecycle.name": "slm-history-ilm-policy"
+      "index.auto_expand_replicas": "0-1"
+    },
+    "lifecycle": {
+      "data_retention": "90d"
     },
     "mappings": {
       "dynamic": false,

+ 14 - 4
x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java

@@ -77,6 +77,7 @@ import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
 import static org.hamcrest.Matchers.nullValue;
 
 public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
@@ -1220,10 +1221,19 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
         }
 
         // Finally, check that the history index is in a good state
-        Step.StepKey stepKey = getStepKeyForIndex(client(), DataStream.getDefaultBackingIndexName("ilm-history-5", 1));
-        assertEquals("hot", stepKey.phase());
-        assertEquals(RolloverAction.NAME, stepKey.action());
-        assertEquals(WaitForRolloverReadyStep.NAME, stepKey.name());
+        String historyIndexName = DataStream.getDefaultBackingIndexName("ilm-history-6", 1);
+        Response explainHistoryIndex = client().performRequest(new Request("GET", historyIndexName + "/_lifecycle/explain"));
+        Map<String, Object> responseMap;
+        try (InputStream is = explainHistoryIndex.getEntity().getContent()) {
+            responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
+        }
+
+        @SuppressWarnings("unchecked")
+        Map<String, Map<String, Object>> indexResponse = ((Map<String, Map<String, Object>>) responseMap.get("indices"));
+        Map<String, Object> historyIndexDSLExplain = indexResponse.get(historyIndexName);
+        assertThat(historyIndexDSLExplain, is(notNullValue()));
+        assertThat(historyIndexDSLExplain.get("managed_by_lifecycle"), is(true));
+        assertThat(historyIndexDSLExplain.get("index_creation_date_millis"), is(notNullValue()));
     }
 
     private void createSlmPolicy(String smlPolicy, String repo) throws IOException {

+ 2 - 1
x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryTemplateRegistry.java

@@ -34,7 +34,8 @@ public class ILMHistoryTemplateRegistry extends IndexTemplateRegistry {
     // version 3: templates moved to composable templates
     // version 4: add `allow_auto_create` setting
     // version 5: convert to data stream
-    public static final int INDEX_TEMPLATE_VERSION = 5;
+    // version 6: manage by data stream lifecycle
+    public static final int INDEX_TEMPLATE_VERSION = 6;
 
     public static final String ILM_TEMPLATE_VERSION_VARIABLE = "xpack.ilm_history.template.version";
     public static final String ILM_TEMPLATE_NAME = "ilm-history";

+ 2 - 1
x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotLifecycleTemplateRegistry.java

@@ -41,7 +41,8 @@ public class SnapshotLifecycleTemplateRegistry extends IndexTemplateRegistry {
     // version 3: templates moved to composable templates
     // version 4:converted data stream
     // version 5: add `allow_auto_create` setting
-    public static final int INDEX_TEMPLATE_VERSION = 5;
+    // version 6: manage by data stream lifecycle
+    public static final int INDEX_TEMPLATE_VERSION = 6;
 
     public static final String SLM_TEMPLATE_VERSION_VARIABLE = "xpack.slm.template.version";
     public static final String SLM_TEMPLATE_NAME = ".slm-history";

+ 0 - 1
x-pack/plugin/slm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotLifecycleTemplateRegistryTests.java

@@ -365,7 +365,6 @@ public class SnapshotLifecycleTemplateRegistryTests extends ESTestCase {
             assertThat(request, instanceOf(PutComposableIndexTemplateAction.Request.class));
             final PutComposableIndexTemplateAction.Request putRequest = (PutComposableIndexTemplateAction.Request) request;
             assertThat(putRequest.name(), equalTo(SLM_TEMPLATE_NAME));
-            assertThat(putRequest.indexTemplate().template().settings().get("index.lifecycle.name"), equalTo(SLM_POLICY_NAME));
             assertThat(putRequest.indexTemplate().version(), equalTo((long) INDEX_TEMPLATE_VERSION));
             assertNotNull(listener);
             return new TestPutIndexTemplateResponse(true);