diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index c4847a57751a3..d7da35c1f5f07 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -1298,8 +1298,6 @@ protected static boolean isXPackTemplate(String name) { } switch (name) { case ".watches": - case "logstash-index-template": - case ".logstash-management": case "security_audit_log": case ".slm-history": case ".async-search": diff --git a/x-pack/plugin/core/src/main/resources/logstash-management.json b/x-pack/plugin/core/src/main/resources/logstash-management.json deleted file mode 100644 index 00b0826a02574..0000000000000 --- a/x-pack/plugin/core/src/main/resources/logstash-management.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "index_patterns" : [ ".logstash" ], - "settings": { - "index": { - "number_of_shards": 1, - "auto_expand_replicas": "0-1", - "codec": "best_compression" - } - }, - "allow_auto_create": true, - "mappings" : { - "_doc" : { - "_meta": { - "logstash-version": "${logstash.template.version}" - }, - "dynamic": "strict", - "properties":{ - "description":{ - "type":"text" - }, - "last_modified":{ - "type":"date" - }, - "pipeline_metadata":{ - "properties":{ - "version":{ - "type":"short" - }, - "type":{ - "type":"keyword" - } - } - }, - "pipeline":{ - "type":"text" - }, - "pipeline_settings": { - "dynamic": false, - "type": "object" - }, - "username":{ - "type":"keyword" - }, - "metadata":{ - "type":"object", - "dynamic":false - } - } - } - } -} diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java index 1491fff3313a2..9bd2871dc3607 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java @@ -5,17 +5,18 @@ */ package org.elasticsearch.xpack.logstash; -import org.apache.logging.log4j.LogManager; import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.SystemIndexPlugin; @@ -23,7 +24,6 @@ import org.elasticsearch.rest.RestHandler; import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction; import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction; -import org.elasticsearch.xpack.core.template.TemplateUtils; import org.elasticsearch.xpack.logstash.action.DeletePipelineAction; import org.elasticsearch.xpack.logstash.action.GetPipelineAction; import org.elasticsearch.xpack.logstash.action.PutPipelineAction; @@ -34,12 +34,16 @@ import org.elasticsearch.xpack.logstash.rest.RestGetPipelineAction; import org.elasticsearch.xpack.logstash.rest.RestPutPipelineAction; +import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Collection; -import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.function.Supplier; -import java.util.function.UnaryOperator; + +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.index.engine.EngineConfig.INDEX_CODEC_SETTING; +import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME; +import static org.elasticsearch.xpack.core.ClientHelper.LOGSTASH_MANAGEMENT_ORIGIN; /** * This class supplies the logstash featureset and templates @@ -47,10 +51,6 @@ public class Logstash extends Plugin implements SystemIndexPlugin { public static final String LOGSTASH_CONCRETE_INDEX_NAME = ".logstash"; - private static final String LOGSTASH_TEMPLATE_FILE_NAME = "logstash-management"; - private static final String LOGSTASH_INDEX_TEMPLATE_NAME = ".logstash-management"; - private static final String OLD_LOGSTASH_INDEX_NAME = "logstash-index-template"; - private static final String TEMPLATE_VERSION_VARIABLE = "logstash.template.version"; public Logstash() {} @@ -78,26 +78,101 @@ public List getRestHandlers( return List.of(new RestPutPipelineAction(), new RestGetPipelineAction(), new RestDeletePipelineAction()); } - public UnaryOperator> getIndexTemplateMetadataUpgrader() { - return templates -> { - templates.keySet().removeIf(OLD_LOGSTASH_INDEX_NAME::equals); - TemplateUtils.loadTemplateIntoMap( - "/" + LOGSTASH_TEMPLATE_FILE_NAME + ".json", - templates, - LOGSTASH_INDEX_TEMPLATE_NAME, - Version.CURRENT.toString(), - TEMPLATE_VERSION_VARIABLE, - LogManager.getLogger(Logstash.class) - ); - assert templates.get(LOGSTASH_INDEX_TEMPLATE_NAME).mappings() != null; - return templates; - }; - } - @Override public Collection getSystemIndexDescriptors(Settings settings) { - return Collections.singletonList( - new SystemIndexDescriptor(LOGSTASH_CONCRETE_INDEX_NAME, "Contains data for Logstash Central Management") + return List.of( + SystemIndexDescriptor.builder() + .setIndexPattern(LOGSTASH_CONCRETE_INDEX_NAME) + .setPrimaryIndex(LOGSTASH_CONCRETE_INDEX_NAME) + .setDescription("Contains data for Logstash Central Management") + .setMappings(getIndexMappings()) + .setSettings(getIndexSettings()) + .setVersionMetaKey("logstash-version") + .setOrigin(LOGSTASH_MANAGEMENT_ORIGIN) + .build() ); } + + private Settings getIndexSettings() { + return Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1") + .put(INDEX_CODEC_SETTING.getKey(), CodecService.BEST_COMPRESSION_CODEC) + .build(); + } + + private XContentBuilder getIndexMappings() { + try { + final XContentBuilder builder = jsonBuilder(); + { + builder.startObject(); + { + builder.startObject(SINGLE_MAPPING_NAME); + builder.field("dynamic", "strict"); + { + builder.startObject("_meta"); + builder.field("logstash-version", Version.CURRENT); + builder.endObject(); + } + { + builder.startObject("properties"); + { + builder.startObject("description"); + builder.field("type", "text"); + builder.endObject(); + } + { + builder.startObject("last_modified"); + builder.field("type", "date"); + builder.endObject(); + } + { + builder.startObject("pipeline_metadata"); + { + builder.startObject("properties"); + { + builder.startObject("version"); + builder.field("type", "short"); + builder.endObject(); + builder.startObject("type"); + builder.field("type", "keyword"); + builder.endObject(); + } + builder.endObject(); + } + builder.endObject(); + } + { + builder.startObject("pipeline"); + builder.field("type", "text"); + builder.endObject(); + } + { + builder.startObject("pipeline_settings"); + builder.field("dynamic", false); + builder.field("type", "object"); + builder.endObject(); + } + { + builder.startObject("username"); + builder.field("type", "keyword"); + builder.endObject(); + } + { + builder.startObject("metadata"); + builder.field("dynamic", false); + builder.field("type", "object"); + builder.endObject(); + } + builder.endObject(); + } + builder.endObject(); + } + builder.endObject(); + } + return builder; + } catch (IOException e) { + throw new UncheckedIOException("Failed to build " + LOGSTASH_CONCRETE_INDEX_NAME + " index mappings", e); + } + } } diff --git a/x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java b/x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java index bd76b7039bc82..620078875bd81 100644 --- a/x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java +++ b/x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java @@ -41,15 +41,6 @@ protected Settings restClientSettings() { .build(); } - public void testTemplateIsPut() throws Exception { - assertBusy( - () -> assertThat( - client().performRequest(new Request("HEAD", "/_template/.logstash-management")).getStatusLine().getStatusCode(), - is(200) - ) - ); - } - public void testPipelineCRUD() throws Exception { // put pipeline final String pipelineJson = getPipelineJson();