From b214f1983a925a7c9144eda8c45697d8062101e1 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Tue, 3 Mar 2020 10:28:37 -0800 Subject: [PATCH 1/3] Remove xpack actions for the flattened field. The current consensus is that we don't need info actions for smaller items like field mappers. We can also remove the usage action since the cluster stats API now tracks information about mappings, like what field types are defined. --- .../xpack/core/XPackClientPlugin.java | 2 - .../elasticsearch/xpack/core/XPackField.java | 1 - .../core/action/XPackInfoFeatureAction.java | 3 +- .../core/action/XPackUsageFeatureAction.java | 3 +- .../flattened/FlattenedFeatureSetUsage.java | 62 --------------- .../FlattenedFeatureSetUsageTests.java | 47 ----------- .../FlattenedInfoTransportAction.java | 47 ----------- .../flattened/FlattenedMapperPlugin.java | 16 +--- .../FlattenedUsageTransportAction.java | 79 ------------------- 9 files changed, 3 insertions(+), 257 deletions(-) delete mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/flattened/FlattenedFeatureSetUsage.java delete mode 100644 x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/flattened/FlattenedFeatureSetUsageTests.java delete mode 100644 x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedInfoTransportAction.java delete mode 100644 x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedUsageTransportAction.java diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java index abad8feba7d42..16a3ce6d5bcb6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java @@ -38,7 +38,6 @@ import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata; import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction; import org.elasticsearch.xpack.core.eql.EqlFeatureSetUsage; -import org.elasticsearch.xpack.core.flattened.FlattenedFeatureSetUsage; import org.elasticsearch.xpack.core.frozen.FrozenIndicesFeatureSetUsage; import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction; import org.elasticsearch.xpack.core.graph.GraphFeatureSetUsage; @@ -556,7 +555,6 @@ public List getNamedWriteables() { new NamedWriteableRegistry.Entry(Task.Status.class, TransformField.TASK_NAME, TransformState::new), new NamedWriteableRegistry.Entry(PersistentTaskState.class, TransformField.TASK_NAME, TransformState::new), new NamedWriteableRegistry.Entry(SyncConfig.class, TransformField.TIME_BASED_SYNC.getPreferredName(), TimeSyncConfig::new), - new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.FLATTENED, FlattenedFeatureSetUsage::new), // Vectors new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VECTORS, VectorsFeatureSetUsage::new), // Voting Only Node diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackField.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackField.java index c18cd6cb2850d..6060e728ee9dc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackField.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackField.java @@ -42,7 +42,6 @@ public final class XPackField { /** Name constant for the transform feature. */ public static final String TRANSFORM = "transform"; /** Name constant for flattened fields. */ - public static final String FLATTENED = "flattened"; /** Name constant for the vectors feature. */ public static final String VECTORS = "vectors"; /** Name constant for the voting-only-node feature. */ diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoFeatureAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoFeatureAction.java index 9dac2212534b1..656260b55e074 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoFeatureAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoFeatureAction.java @@ -35,7 +35,6 @@ public class XPackInfoFeatureAction extends ActionType public static final XPackInfoFeatureAction SNAPSHOT_LIFECYCLE = new XPackInfoFeatureAction(XPackField.SNAPSHOT_LIFECYCLE); public static final XPackInfoFeatureAction CCR = new XPackInfoFeatureAction(XPackField.CCR); public static final XPackInfoFeatureAction TRANSFORM = new XPackInfoFeatureAction(XPackField.TRANSFORM); - public static final XPackInfoFeatureAction FLATTENED = new XPackInfoFeatureAction(XPackField.FLATTENED); public static final XPackInfoFeatureAction VECTORS = new XPackInfoFeatureAction(XPackField.VECTORS); public static final XPackInfoFeatureAction VOTING_ONLY = new XPackInfoFeatureAction(XPackField.VOTING_ONLY); public static final XPackInfoFeatureAction FROZEN_INDICES = new XPackInfoFeatureAction(XPackField.FROZEN_INDICES); @@ -46,7 +45,7 @@ public class XPackInfoFeatureAction extends ActionType public static final List ALL = Arrays.asList( SECURITY, MONITORING, WATCHER, GRAPH, MACHINE_LEARNING, LOGSTASH, EQL, SQL, ROLLUP, INDEX_LIFECYCLE, SNAPSHOT_LIFECYCLE, CCR, - TRANSFORM, FLATTENED, VECTORS, VOTING_ONLY, FROZEN_INDICES, SPATIAL, ANALYTICS, ENRICH, CONSTANT_KEYWORD + TRANSFORM, VECTORS, VOTING_ONLY, FROZEN_INDICES, SPATIAL, ANALYTICS, ENRICH, CONSTANT_KEYWORD ); private XPackInfoFeatureAction(String name) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageFeatureAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageFeatureAction.java index ffc1651ab74ef..c696fdeaa3e29 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageFeatureAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageFeatureAction.java @@ -35,7 +35,6 @@ public class XPackUsageFeatureAction extends ActionType ALL = Arrays.asList( SECURITY, MONITORING, WATCHER, GRAPH, MACHINE_LEARNING, LOGSTASH, EQL, SQL, ROLLUP, INDEX_LIFECYCLE, SNAPSHOT_LIFECYCLE, CCR, - TRANSFORM, FLATTENED, VECTORS, VOTING_ONLY, FROZEN_INDICES, SPATIAL, ANALYTICS + TRANSFORM, VECTORS, VOTING_ONLY, FROZEN_INDICES, SPATIAL, ANALYTICS ); private XPackUsageFeatureAction(String name) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/flattened/FlattenedFeatureSetUsage.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/flattened/FlattenedFeatureSetUsage.java deleted file mode 100644 index 08cfa6f9a7f15..0000000000000 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/flattened/FlattenedFeatureSetUsage.java +++ /dev/null @@ -1,62 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -package org.elasticsearch.xpack.core.flattened; - -import org.elasticsearch.Version; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.xpack.core.XPackFeatureSet; -import org.elasticsearch.xpack.core.XPackField; - -import java.io.IOException; -import java.util.Objects; - -public class FlattenedFeatureSetUsage extends XPackFeatureSet.Usage { - private final int fieldCount; - - public FlattenedFeatureSetUsage(StreamInput input) throws IOException { - super(input); - this.fieldCount = input.getVersion().onOrAfter(Version.V_7_6_0) ? input.readInt() : 0; - } - - public FlattenedFeatureSetUsage(boolean available, boolean enabled, int fieldCount) { - super(XPackField.FLATTENED, available, enabled); - this.fieldCount = fieldCount; - } - - int fieldCount() { - return fieldCount; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - if (out.getVersion().onOrAfter(Version.V_7_6_0)) { - out.writeInt(fieldCount); - } - } - - @Override - protected void innerXContent(XContentBuilder builder, Params params) throws IOException { - super.innerXContent(builder, params); - builder.field("field_count", fieldCount); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - FlattenedFeatureSetUsage that = (FlattenedFeatureSetUsage) o; - return available == that.available && enabled == that.enabled && fieldCount == that.fieldCount; - } - - @Override - public int hashCode() { - return Objects.hash(available, enabled, fieldCount); - } -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/flattened/FlattenedFeatureSetUsageTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/flattened/FlattenedFeatureSetUsageTests.java deleted file mode 100644 index e5e1a6342dea5..0000000000000 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/flattened/FlattenedFeatureSetUsageTests.java +++ /dev/null @@ -1,47 +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; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.core.flattened; - -import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.test.AbstractWireSerializingTestCase; - -import java.io.IOException; - -public class FlattenedFeatureSetUsageTests extends AbstractWireSerializingTestCase { - - @Override - protected FlattenedFeatureSetUsage createTestInstance() { - return new FlattenedFeatureSetUsage(randomBoolean(), randomBoolean(), randomIntBetween(0, 1000)); - } - - @Override - protected FlattenedFeatureSetUsage mutateInstance(FlattenedFeatureSetUsage instance) throws IOException { - - boolean available = instance.available(); - boolean enabled = instance.enabled(); - int fieldCount = instance.fieldCount(); - - switch (between(0, 2)) { - case 0: - available = !available; - break; - case 1: - enabled = !enabled; - break; - case 2: - fieldCount = randomValueOtherThan(instance.fieldCount(), () -> randomIntBetween(0, 1000)); - break; - } - - return new FlattenedFeatureSetUsage(available, enabled, fieldCount); - } - - @Override - protected Writeable.Reader instanceReader() { - return FlattenedFeatureSetUsage::new; - } - -} diff --git a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedInfoTransportAction.java b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedInfoTransportAction.java deleted file mode 100644 index abdfd8c4b85c9..0000000000000 --- a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedInfoTransportAction.java +++ /dev/null @@ -1,47 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -package org.elasticsearch.xpack.flattened; - -import org.elasticsearch.action.support.ActionFilters; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.XPackField; -import org.elasticsearch.xpack.core.XPackSettings; -import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction; -import org.elasticsearch.xpack.core.action.XPackInfoFeatureTransportAction; - -public class FlattenedInfoTransportAction extends XPackInfoFeatureTransportAction { - - private final boolean enabled; - private final XPackLicenseState licenseState; - - @Inject - public FlattenedInfoTransportAction(TransportService transportService, ActionFilters actionFilters, - Settings settings, XPackLicenseState licenseState) { - super(XPackInfoFeatureAction.FLATTENED.name(), transportService, actionFilters); - this.enabled = XPackSettings.FLATTENED_ENABLED.get(settings); - this.licenseState = licenseState; - } - - @Override - public String name() { - return XPackField.FLATTENED; - } - - @Override - public boolean available() { - return licenseState.isFlattenedAllowed(); - } - - @Override - public boolean enabled() { - return enabled; - } - -} diff --git a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedMapperPlugin.java b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedMapperPlugin.java index 1dd407f70d3a2..a74f7c5a87799 100644 --- a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedMapperPlugin.java +++ b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedMapperPlugin.java @@ -6,26 +6,19 @@ package org.elasticsearch.xpack.flattened; -import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.mapper.Mapper; -import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.MapperPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.xpack.core.XPackSettings; -import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction; -import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction; import org.elasticsearch.xpack.flattened.mapper.FlatObjectFieldMapper; -import java.util.Arrays; -import java.util.List; import java.util.Map; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; -public class FlattenedMapperPlugin extends Plugin implements MapperPlugin, ActionPlugin { +public class FlattenedMapperPlugin extends Plugin implements MapperPlugin { protected final boolean enabled; @@ -40,11 +33,4 @@ public Map getMappers() { } return singletonMap(FlatObjectFieldMapper.CONTENT_TYPE, new FlatObjectFieldMapper.TypeParser()); } - - @Override - public List> getActions() { - return Arrays.asList( - new ActionHandler<>(XPackUsageFeatureAction.FLATTENED, FlattenedUsageTransportAction.class), - new ActionHandler<>(XPackInfoFeatureAction.FLATTENED, FlattenedInfoTransportAction.class)); - } } diff --git a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedUsageTransportAction.java b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedUsageTransportAction.java deleted file mode 100644 index 450cf711fe18d..0000000000000 --- a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/FlattenedUsageTransportAction.java +++ /dev/null @@ -1,79 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -package org.elasticsearch.xpack.flattened; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.support.ActionFilters; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.protocol.xpack.XPackUsageRequest; -import org.elasticsearch.tasks.Task; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.XPackSettings; -import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction; -import org.elasticsearch.xpack.core.action.XPackUsageFeatureResponse; -import org.elasticsearch.xpack.core.action.XPackUsageFeatureTransportAction; -import org.elasticsearch.xpack.core.flattened.FlattenedFeatureSetUsage; -import org.elasticsearch.xpack.flattened.mapper.FlatObjectFieldMapper; - -import java.util.Map; - -public class FlattenedUsageTransportAction extends XPackUsageFeatureTransportAction { - - private final Settings settings; - private final XPackLicenseState licenseState; - - @Inject - public FlattenedUsageTransportAction(TransportService transportService, ClusterService clusterService, ThreadPool threadPool, - ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, - Settings settings, XPackLicenseState licenseState) { - super(XPackUsageFeatureAction.FLATTENED.name(), transportService, clusterService, - threadPool, actionFilters, indexNameExpressionResolver); - this.settings = settings; - this.licenseState = licenseState; - } - - @Override - protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, - ActionListener listener) { - boolean allowed = licenseState.isFlattenedAllowed(); - boolean enabled = XPackSettings.FLATTENED_ENABLED.get(settings); - int fieldCount = 0; - - if (allowed && enabled && state != null) { - for (IndexMetaData indexMetaData : state.metaData()) { - MappingMetaData mappingMetaData = indexMetaData.mapping(); - - if (mappingMetaData != null) { - Map mappings = mappingMetaData.getSourceAsMap(); - - if (mappings.containsKey("properties")) { - @SuppressWarnings("unchecked") - Map> fieldMappings = (Map>) mappings.get("properties"); - - for (Map fieldMapping : fieldMappings.values()) { - String fieldType = (String) fieldMapping.get("type"); - if (fieldType != null && fieldType.equals(FlatObjectFieldMapper.CONTENT_TYPE)) { - fieldCount++; - } - } - } - } - } - } - - FlattenedFeatureSetUsage usage = new FlattenedFeatureSetUsage(allowed, enabled, fieldCount); - listener.onResponse(new XPackUsageFeatureResponse(usage)); - } -} From b4091cbee3150b7b7d5dccb6d57f06b26300834b Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Tue, 3 Mar 2020 12:22:54 -0800 Subject: [PATCH 2/3] Remove a yml test for flattened usage stats. --- .../test/flattened/20_flattened_stats.yml | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/test/flattened/20_flattened_stats.yml diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/flattened/20_flattened_stats.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/flattened/20_flattened_stats.yml deleted file mode 100644 index 88c32d76b0b7b..0000000000000 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/flattened/20_flattened_stats.yml +++ /dev/null @@ -1,41 +0,0 @@ -setup: - - skip: - version: " - 7.5.99" - reason: "telemetry for flattened fields was added in 7.6.0" - ---- -"Usage stats for flattened fields": - - do: - xpack.usage: {} - - - match: { flattened.available: true } - - match: { flattened.enabled: true } - - match: { flattened.field_count: 0 } - - - do: - indices.create: - index: test-index1 - body: - mappings: - properties: - flattened_1: - type: flattened - - - do: - indices.create: - index: test-index2 - body: - mappings: - properties: - flattened_2: - type: flattened - flattened_3: - type: flattened - ignore_above: 10 - - - do: - xpack.usage: {} - - - match: { flattened.available: true } - - match: { flattened.enabled: true } - - match: { flattened.field_count: 3 } From bdabfb645a5a5f40c3c5ca30820f64526d6b73f4 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Tue, 3 Mar 2020 12:23:28 -0800 Subject: [PATCH 3/3] In docs tests, remove flattened from the responses. --- docs/reference/rest-api/info.asciidoc | 4 ---- docs/reference/rest-api/usage.asciidoc | 7 +------ 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/docs/reference/rest-api/info.asciidoc b/docs/reference/rest-api/info.asciidoc index 441dc8f3478a5..3944bbf17ae8e 100644 --- a/docs/reference/rest-api/info.asciidoc +++ b/docs/reference/rest-api/info.asciidoc @@ -79,10 +79,6 @@ Example response: "available" : true, "enabled" : true }, - "flattened" : { - "available" : true, - "enabled" : true - }, "frozen_indices" : { "available" : true, "enabled" : true diff --git a/docs/reference/rest-api/usage.asciidoc b/docs/reference/rest-api/usage.asciidoc index 342e626d7c061..9d6bc57a771a5 100644 --- a/docs/reference/rest-api/usage.asciidoc +++ b/docs/reference/rest-api/usage.asciidoc @@ -242,11 +242,6 @@ GET /_xpack/usage "available" : true, "enabled" : true }, - "flattened" : { - "available" : true, - "enabled" : true, - "field_count" : 0 - }, "vectors" : { "available" : true, "enabled" : true, @@ -289,4 +284,4 @@ GET /_xpack/usage // 3. Ignore the contents of the `slm` object because it might contain policies // 4. All of the numbers and strings on the right hand side of *every* field in // the response are ignored. So we're really only asserting things about the -// the shape of this response, not the values in it. \ No newline at end of file +// the shape of this response, not the values in it.