Browse Source

Remove `cluster.logsdb.enabled` from `StackPlugin` (#113616) (#114664)

After introducing #113505 we need to remove `cluster.logsdb.enabled` from
`StackPlugin` and `StackTemplateRegistry`.

(cherry picked from commit 487c5562aa2e4c81c3c0ee136ef1a96b977de6dd)

Co-authored-by: Salvatore Campagna <93581129+salvatore-campagna@users.noreply.github.com>
Oleksandr Kolomiiets 1 year ago
parent
commit
006c274824

+ 25 - 3
modules/data-streams/src/javaRestTest/java/org/elasticsearch/datastreams/logsdb/LogsIndexModeCustomSettingsIT.java

@@ -97,10 +97,15 @@ public class LogsIndexModeCustomSettingsIT extends LogsIndexModeRestTestIT {
         assertThat(type, equalTo("date"));
     }
 
-    public void testConfigureStoredSource() throws IOException {
+    public void testConfigureStoredSourceBeforeIndexCreation() throws IOException {
         var storedSourceMapping = """
             {
               "template": {
+                "settings": {
+                  "index": {
+                    "mode": "logsdb"
+                  }
+                },
                 "mappings": {
                   "_source": {
                     "mode": "stored"
@@ -112,9 +117,9 @@ public class LogsIndexModeCustomSettingsIT extends LogsIndexModeRestTestIT {
         Exception e = assertThrows(ResponseException.class, () -> putComponentTemplate(client, "logs@custom", storedSourceMapping));
         assertThat(
             e.getMessage(),
-            containsString("updating component template [logs@custom] results in invalid composable template [logs]")
+            containsString("Failed to parse mapping: Indices with with index mode [logsdb] only support synthetic source")
         );
-        assertThat(e.getMessage(), containsString("Indices with with index mode [logsdb] only support synthetic source"));
+        assertThat(e.getMessage(), containsString("mapper_parsing_exception"));
 
         assertOK(createDataStream(client, "logs-custom-dev"));
 
@@ -123,6 +128,23 @@ public class LogsIndexModeCustomSettingsIT extends LogsIndexModeRestTestIT {
         assertThat(sourceMode, equalTo("synthetic"));
     }
 
+    public void testConfigureStoredSourceWhenIndexIsCreated() throws IOException {
+        var storedSourceMapping = """
+            {
+              "template": {
+                "mappings": {
+                  "_source": {
+                    "mode": "stored"
+                  }
+                }
+              }
+            }""";
+
+        assertOK(putComponentTemplate(client, "logs@custom", storedSourceMapping));
+        ResponseException e = expectThrows(ResponseException.class, () -> createDataStream(client, "logs-custom-dev"));
+        assertThat(e.getMessage(), containsString("Indices with with index mode [logsdb] only support synthetic source"));
+    }
+
     public void testOverrideIndexCodec() throws IOException {
         var indexCodecOverrideTemplate = """
             {

+ 0 - 1
x-pack/plugin/core/src/main/java/module-info.java

@@ -228,7 +228,6 @@ module org.elasticsearch.xcore {
     exports org.elasticsearch.xpack.core.watcher.trigger;
     exports org.elasticsearch.xpack.core.watcher.watch;
     exports org.elasticsearch.xpack.core.watcher;
-    exports org.elasticsearch.xpack.cluster.settings;
 
     provides org.elasticsearch.action.admin.cluster.node.info.ComponentVersionNumber
         with

+ 0 - 19
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/settings/ClusterSettings.java

@@ -1,19 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-
-package org.elasticsearch.xpack.cluster.settings;
-
-import org.elasticsearch.common.settings.Setting;
-
-public class ClusterSettings {
-    public static final Setting<Boolean> CLUSTER_LOGSDB_ENABLED = Setting.boolSetting(
-        "cluster.logsdb.enabled",
-        false,
-        Setting.Property.Dynamic,
-        Setting.Property.NodeScope
-    );
-}

+ 0 - 26
x-pack/plugin/core/template-resources/src/main/resources/logs@settings-logsdb.json

@@ -1,26 +0,0 @@
-{
-  "template": {
-    "settings": {
-      "index": {
-        "lifecycle": {
-          "name": "logs"
-        },
-        "mode": "logsdb",
-        "codec": "best_compression",
-        "mapping": {
-          "ignore_malformed": true,
-          "total_fields": {
-            "ignore_dynamic_beyond_limit": true
-          }
-        },
-        "default_pipeline": "logs@default-pipeline"
-      }
-    }
-  },
-  "_meta": {
-    "description": "default settings for the logs index template installed by x-pack",
-    "managed": true
-  },
-  "version": ${xpack.stack.template.version},
-  "deprecated": ${xpack.stack.template.deprecated}
-}

+ 1 - 1
x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBPlugin.java

@@ -17,7 +17,7 @@ import org.elasticsearch.xpack.core.XPackPlugin;
 import java.util.Collection;
 import java.util.List;
 
-import static org.elasticsearch.xpack.cluster.settings.ClusterSettings.CLUSTER_LOGSDB_ENABLED;
+import static org.elasticsearch.xpack.logsdb.LogsdbIndexModeSettingsProvider.CLUSTER_LOGSDB_ENABLED;
 import static org.elasticsearch.xpack.logsdb.SyntheticSourceLicenseService.FALLBACK_SETTING;
 
 public class LogsDBPlugin extends Plugin {

+ 7 - 2
x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsdbIndexModeSettingsProvider.java

@@ -10,6 +10,7 @@ package org.elasticsearch.xpack.logsdb;
 import org.elasticsearch.cluster.metadata.Metadata;
 import org.elasticsearch.common.compress.CompressedXContent;
 import org.elasticsearch.common.regex.Regex;
+import org.elasticsearch.common.settings.Setting;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.index.IndexMode;
 import org.elasticsearch.index.IndexSettingProvider;
@@ -19,9 +20,13 @@ import java.time.Instant;
 import java.util.List;
 import java.util.Locale;
 
-import static org.elasticsearch.xpack.cluster.settings.ClusterSettings.CLUSTER_LOGSDB_ENABLED;
-
 final class LogsdbIndexModeSettingsProvider implements IndexSettingProvider {
+    static final Setting<Boolean> CLUSTER_LOGSDB_ENABLED = Setting.boolSetting(
+        "cluster.logsdb.enabled",
+        false,
+        Setting.Property.Dynamic,
+        Setting.Property.NodeScope
+    );
     private static final String LOGS_PATTERN = "logs-*-*";
     private volatile boolean isLogsdbEnabled;
 

+ 3 - 5
x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackTemplateRegistry.java

@@ -35,8 +35,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import static org.elasticsearch.xpack.cluster.settings.ClusterSettings.CLUSTER_LOGSDB_ENABLED;
-
 public class StackTemplateRegistry extends IndexTemplateRegistry {
     private static final Logger logger = LogManager.getLogger(StackTemplateRegistry.class);
 
@@ -130,10 +128,10 @@ public class StackTemplateRegistry extends IndexTemplateRegistry {
         this.clusterService = clusterService;
         this.featureService = featureService;
         this.stackTemplateEnabled = STACK_TEMPLATES_ENABLED.get(nodeSettings);
-        this.componentTemplateConfigs = loadComponentTemplateConfigs(CLUSTER_LOGSDB_ENABLED.get(nodeSettings));
+        this.componentTemplateConfigs = loadComponentTemplateConfigs();
     }
 
-    private Map<String, ComponentTemplate> loadComponentTemplateConfigs(boolean logsDbEnabled) {
+    private Map<String, ComponentTemplate> loadComponentTemplateConfigs() {
         final Map<String, ComponentTemplate> componentTemplates = new HashMap<>();
         for (IndexTemplateConfig config : List.of(
             new IndexTemplateConfig(
@@ -159,7 +157,7 @@ public class StackTemplateRegistry extends IndexTemplateRegistry {
             ),
             new IndexTemplateConfig(
                 LOGS_SETTINGS_COMPONENT_TEMPLATE_NAME,
-                logsDbEnabled ? "/logs@settings-logsdb.json" : "/logs@settings.json",
+                "/logs@settings.json",
                 REGISTRY_VERSION,
                 TEMPLATE_VERSION_VARIABLE,
                 Map.of("xpack.stack.template.deprecated", "false")