From 49cab2394990d8ea3fd8697166163d3395fe2d9e Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Tue, 16 May 2023 12:52:29 -0500 Subject: [PATCH 01/13] Adding data_lifecycle to the _xpack/usage API --- .../org/elasticsearch/TransportVersion.java | 3 +- .../xpack/core/XPackClientPlugin.java | 2 + .../elasticsearch/xpack/core/XPackField.java | 2 + .../elasticsearch/xpack/core/XPackPlugin.java | 2 + .../DataLifecycleUsageTransportAction.java | 78 +++++++++ .../core/action/XPackUsageFeatureAction.java | 2 + .../DataLifecycleFeatureSetUsage.java | 152 ++++++++++++++++++ .../DataLifecycleFeatureSetUsageTests.java | 86 ++++++++++ x-pack/qa/usage/build.gradle | 25 +++ .../xpack/usage/XPackUsageIT.java | 137 ++++++++++++++++ .../elasticsearch/xpack/usage/UsageQA.java | 14 ++ 11 files changed, 502 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportAction.java create mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsage.java create mode 100644 x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsageTests.java create mode 100644 x-pack/qa/usage/build.gradle create mode 100644 x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java create mode 100644 x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java diff --git a/server/src/main/java/org/elasticsearch/TransportVersion.java b/server/src/main/java/org/elasticsearch/TransportVersion.java index d0bdced9def86..77ee4024a19e7 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersion.java +++ b/server/src/main/java/org/elasticsearch/TransportVersion.java @@ -122,12 +122,13 @@ private static TransportVersion registerTransportVersion(int id, String uniqueId */ public static final TransportVersion V_8_500_000 = registerTransportVersion(8_500_000, "dc3cbf06-3ed5-4e1b-9978-ee1d04d235bc"); public static final TransportVersion V_8_500_001 = registerTransportVersion(8_500_001, "c943cfe5-c89d-4eae-989f-f5f4537e84e0"); + public static final TransportVersion V_8_500_002 = registerTransportVersion(8_500_002, "7BB5621A-80AC-425F-BA88-75543C442F23"); /** * Reference to the most recent transport version. * This should be the transport version with the highest id. */ - public static final TransportVersion CURRENT = V_8_500_001; + public static final TransportVersion CURRENT = V_8_500_002; /** * Reference to the earliest compatible transport version to this version of the codebase. 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 f18eaa4675c02..3f0d8efce7805 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,6 +38,7 @@ import org.elasticsearch.xpack.core.archive.ArchiveFeatureSetUsage; import org.elasticsearch.xpack.core.async.DeleteAsyncResultAction; import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata; +import org.elasticsearch.xpack.core.datastreams.DataLifecycleFeatureSetUsage; import org.elasticsearch.xpack.core.datastreams.DataStreamFeatureSetUsage; import org.elasticsearch.xpack.core.downsample.DownsampleIndexerAction; import org.elasticsearch.xpack.core.enrich.EnrichFeatureSetUsage; @@ -545,6 +546,7 @@ public List getNamedWriteables() { ), // Data Streams new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.DATA_STREAMS, DataStreamFeatureSetUsage::new), + new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.DATA_LIFECYCLE, DataLifecycleFeatureSetUsage::new), // Data Tiers new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.DATA_TIERS, DataTiersFeatureSetUsage::new), // Archive 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 94e438fa77b2a..dd20ec3c9cd5b 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 @@ -65,6 +65,8 @@ public final class XPackField { public static final String SEARCHABLE_SNAPSHOTS = "searchable_snapshots"; /** Name constant for the data streams feature. */ public static final String DATA_STREAMS = "data_streams"; + /** Name constant for the data lifecycle feature. */ + public static final String DATA_LIFECYCLE = "data_lifecycle"; /** Name constant for the data tiers feature. */ public static final String DATA_TIERS = "data_tiers"; /** Name constant for the aggregate_metric plugin. */ diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index da2ae5afe129d..80fc9695e74d7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java @@ -74,6 +74,7 @@ import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; import org.elasticsearch.xpack.cluster.routing.allocation.mapper.DataTierFieldMapper; +import org.elasticsearch.xpack.core.action.DataLifecycleUsageTransportAction; import org.elasticsearch.xpack.core.action.DataStreamInfoTransportAction; import org.elasticsearch.xpack.core.action.DataStreamUsageTransportAction; import org.elasticsearch.xpack.core.action.ReloadAnalyzerAction; @@ -355,6 +356,7 @@ public Collection createComponents( actions.add(new ActionHandler<>(XPackUsageFeatureAction.DATA_TIERS, DataTiersUsageTransportAction.class)); actions.add(new ActionHandler<>(XPackUsageFeatureAction.DATA_STREAMS, DataStreamUsageTransportAction.class)); actions.add(new ActionHandler<>(XPackInfoFeatureAction.DATA_STREAMS, DataStreamInfoTransportAction.class)); + actions.add(new ActionHandler<>(XPackUsageFeatureAction.DATA_LIFECYCLE, DataLifecycleUsageTransportAction.class)); actions.add(new ActionHandler<>(XPackUsageFeatureAction.HEALTH, HealthApiUsageTransportAction.class)); actions.add(new ActionHandler<>(XPackUsageFeatureAction.REMOTE_CLUSTERS, RemoteClusterUsageTransportAction.class)); return actions; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportAction.java new file mode 100644 index 0000000000000..ca01f35653b33 --- /dev/null +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportAction.java @@ -0,0 +1,78 @@ +/* + * 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.core.action; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.indices.rollover.RolloverConfiguration; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.DataLifecycle; +import org.elasticsearch.cluster.metadata.DataStream; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.inject.Inject; +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.datastreams.DataLifecycleFeatureSetUsage; + +import java.util.Collection; +import java.util.LongSummaryStatistics; +import java.util.stream.Collectors; + +public class DataLifecycleUsageTransportAction extends XPackUsageFeatureTransportAction { + + @Inject + public DataLifecycleUsageTransportAction( + TransportService transportService, + ClusterService clusterService, + ThreadPool threadPool, + ActionFilters actionFilters, + IndexNameExpressionResolver indexNameExpressionResolver + ) { + super( + XPackUsageFeatureAction.DATA_LIFECYCLE.name(), + transportService, + clusterService, + threadPool, + actionFilters, + indexNameExpressionResolver + ); + } + + @Override + protected void masterOperation( + Task task, + XPackUsageRequest request, + ClusterState state, + ActionListener listener + ) { + final Collection dataStreams = state.metadata().dataStreams().values(); + LongSummaryStatistics retentionStats = dataStreams.stream() + .filter(ds -> ds.getLifecycle() != null) + .collect(Collectors.summarizingLong(ds -> ds.getLifecycle().getDataRetention().getMillis())); + long dataStreamsWithLifecycles = retentionStats.getCount(); + long minRetention = dataStreamsWithLifecycles == 0 ? 0 : retentionStats.getMin(); + long maxRetention = dataStreamsWithLifecycles == 0 ? 0 : retentionStats.getMax(); + double averageRetention = retentionStats.getAverage(); + RolloverConfiguration rolloverConfiguration = clusterService.getClusterSettings() + .get(DataLifecycle.CLUSTER_DLM_DEFAULT_ROLLOVER_SETTING); + String rolloverConfigString = rolloverConfiguration.toString(); + final DataLifecycleFeatureSetUsage.LifecycleStats stats = new DataLifecycleFeatureSetUsage.LifecycleStats( + dataStreamsWithLifecycles, + minRetention, + maxRetention, + averageRetention, + rolloverConfigString + ); + + final DataLifecycleFeatureSetUsage usage = new DataLifecycleFeatureSetUsage(stats); + listener.onResponse(new XPackUsageFeatureResponse(usage)); + } +} 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 bb9c25f5cb6f2..fda06bd491a37 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 @@ -45,6 +45,7 @@ public class XPackUsageFeatureAction extends ActionType { + + @Override + protected DataLifecycleFeatureSetUsage createTestInstance() { + return new DataLifecycleFeatureSetUsage( + new DataLifecycleFeatureSetUsage.LifecycleStats( + randomNonNegativeLong(), + randomNonNegativeLong(), + randomNonNegativeLong(), + randomDouble(), + randomAlphaOfLength(10) + ) + ); + } + + @Override + protected DataLifecycleFeatureSetUsage mutateInstance(DataLifecycleFeatureSetUsage instance) { + return switch (randomInt(4)) { + case 0 -> new DataLifecycleFeatureSetUsage( + new DataLifecycleFeatureSetUsage.LifecycleStats( + randomValueOtherThan(instance.lifecycleStats.dataStreamsWithLifecyclesCount, ESTestCase::randomLong), + instance.lifecycleStats.minRetentionMillis, + instance.lifecycleStats.maxRetentionMillis, + instance.lifecycleStats.averageRetentionMillis, + instance.lifecycleStats.rolloverConfigString + ) + ); + case 1 -> new DataLifecycleFeatureSetUsage( + new DataLifecycleFeatureSetUsage.LifecycleStats( + instance.lifecycleStats.dataStreamsWithLifecyclesCount, + randomValueOtherThan(instance.lifecycleStats.minRetentionMillis, ESTestCase::randomLong), + instance.lifecycleStats.maxRetentionMillis, + instance.lifecycleStats.averageRetentionMillis, + instance.lifecycleStats.rolloverConfigString + ) + ); + case 2 -> new DataLifecycleFeatureSetUsage( + new DataLifecycleFeatureSetUsage.LifecycleStats( + instance.lifecycleStats.dataStreamsWithLifecyclesCount, + instance.lifecycleStats.minRetentionMillis, + randomValueOtherThan(instance.lifecycleStats.maxRetentionMillis, ESTestCase::randomLong), + instance.lifecycleStats.averageRetentionMillis, + instance.lifecycleStats.rolloverConfigString + ) + ); + case 3 -> new DataLifecycleFeatureSetUsage( + new DataLifecycleFeatureSetUsage.LifecycleStats( + instance.lifecycleStats.dataStreamsWithLifecyclesCount, + instance.lifecycleStats.minRetentionMillis, + instance.lifecycleStats.maxRetentionMillis, + randomValueOtherThan(instance.lifecycleStats.averageRetentionMillis, ESTestCase::randomDouble), + instance.lifecycleStats.rolloverConfigString + ) + ); + case 4 -> new DataLifecycleFeatureSetUsage( + new DataLifecycleFeatureSetUsage.LifecycleStats( + instance.lifecycleStats.dataStreamsWithLifecyclesCount, + instance.lifecycleStats.minRetentionMillis, + instance.lifecycleStats.maxRetentionMillis, + instance.lifecycleStats.averageRetentionMillis, + randomValueOtherThan(instance.lifecycleStats.rolloverConfigString, () -> randomAlphaOfLength(20)) + ) + ); + default -> throw new RuntimeException("unreachable"); + }; + } + + @Override + protected Writeable.Reader instanceReader() { + return DataLifecycleFeatureSetUsage::new; + } + +} diff --git a/x-pack/qa/usage/build.gradle b/x-pack/qa/usage/build.gradle new file mode 100644 index 0000000000000..f4cd05fe11e05 --- /dev/null +++ b/x-pack/qa/usage/build.gradle @@ -0,0 +1,25 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +apply plugin: 'elasticsearch.base-internal-es-plugin' +apply plugin: 'elasticsearch.legacy-java-rest-test' + +esplugin { + name 'usage-qa' + description 'Plugin for performing QA of xpack usage' + classname 'org.elasticsearch.xpack.usage.UsageQA' + licenseFile rootProject.file('licenses/SSPL-1.0+ELASTIC-LICENSE-2.0.txt') + noticeFile rootProject.file('NOTICE.txt') +} + +testClusters.configureEach { + testDistribution = 'DEFAULT' + setting 'xpack.security.enabled', 'true' + setting 'xpack.security.autoconfiguration.enabled', 'false' + user username: 'rest_user', password: 'rest-user-password' +} diff --git a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java new file mode 100644 index 0000000000000..942cae0984778 --- /dev/null +++ b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java @@ -0,0 +1,137 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.xpack.usage; + +import org.apache.http.util.EntityUtils; +import org.elasticsearch.client.Request; +import org.elasticsearch.client.Response; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.SecureString; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.core.TimeValue; +import org.elasticsearch.test.rest.ESRestTestCase; +import org.elasticsearch.xcontent.json.JsonXContent; + +import java.io.IOException; +import java.util.Map; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +/* + * This class is meant to test the _xpack/usage API. That API pulls in code from various plugins so it cannot be integration tested + * within x-pack/plugin/core. + */ +public class XPackUsageIT extends ESRestTestCase { + static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("rest_user", new SecureString("rest-user-password".toCharArray())); + + @Override + protected Settings restClientSettings() { + return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", BASIC_AUTH_VALUE).build(); + } + + /* + * This method checks the data_lifecyle portion of the usage API response. + */ + public void testDataLifecycle() throws Exception { + // Make sure that everything is zero when there are no datastreams: + assertDataLifecycleUsageResults(0, 0, 0, 0.0); + createDataStream("ds1", TimeValue.timeValueMillis(10000)); + assertDataLifecycleUsageResults(1, 10000, 10000, 10000.0); + createDataStream("ds2", TimeValue.timeValueMillis(5000)); + assertDataLifecycleUsageResults(2, 5000, 10000, 7500.0); + // Make sure the counters don't change if we add a datastream that has no lifecycle: + createDataStreamNoLifecycle("ds3"); + assertDataLifecycleUsageResults(2, 5000, 10000, 7500.0); + // Make sure that deleting a datastream takes it out of the numbers: + deleteDataStream("ds1"); + assertDataLifecycleUsageResults(1, 5000, 5000, 5000.0); + } + + @SuppressWarnings("unchecked") + private void assertDataLifecycleUsageResults(int count, int minimumRetention, int maximumRetention, double averageRetention) + throws Exception { + Response response = client().performRequest(new Request("GET", "/_xpack/usage")); + assertThat(response.getStatusLine().getStatusCode(), is(200)); + Map responseMap = toMap(response); + Map dataLifecycleMap = (Map) responseMap.get("data_lifecycle"); + assertThat(dataLifecycleMap.get("available"), equalTo(true)); + assertThat(dataLifecycleMap.get("enabled"), equalTo(true)); + assertThat(dataLifecycleMap.get("count"), equalTo(count)); + assertThat(dataLifecycleMap.get("rollover_config"), notNullValue()); + Map retentionMap = (Map) dataLifecycleMap.get("retention"); + assertThat(retentionMap.size(), equalTo(3)); + assertThat(retentionMap.get("minimum_millis"), equalTo(minimumRetention)); + assertThat(retentionMap.get("maximum_millis"), equalTo(maximumRetention)); + assertThat(retentionMap.get("average_millis"), equalTo(averageRetention)); + } + + private void createDataStream(String name, TimeValue retention) throws Exception { + String lifecycle = Strings.format(""" + , + "lifecycle": { + "data_retention":"%s" + } + """, retention); + this.createDataStream(name, lifecycle); + } + + private void createDataStreamNoLifecycle(String name) throws Exception { + this.createDataStream(name, ""); + } + + private void createDataStream(String name, String lifecycle) throws Exception { + Request componentTemplateRequest = new Request("PUT", "_component_template/mappings_" + name); + componentTemplateRequest.setJsonEntity(Strings.format(""" + { + "template": { + "mappings": { + "properties": { + "@timestamp": { + "type": "date", + "format": "date_optional_time||epoch_millis" + }, + "message": { + "type": "wildcard" + } + } + }%s + } + } + """, lifecycle)); + client().performRequest(componentTemplateRequest); + Request indexTemplateRequest = new Request("PUT", "_index_template/index-template-" + name); + indexTemplateRequest.setJsonEntity(Strings.format(""" + { + "index_patterns": ["%s*"], + "data_stream": { }, + "composed_of": [ "mappings_%s" ] + }""", name, name)); + client().performRequest(indexTemplateRequest); + Request bulkRequest = new Request("PUT", name + "/_bulk"); + bulkRequest.setJsonEntity(""" + { "create":{ } } + { "@timestamp": "2099-05-06T16:21:15.000Z", "message": "192.0.2.42 - - [06/May/2099:16:21:15 +0000] message1" } + { "create":{ } } + { "@timestamp": "2099-05-06T16:25:42.000Z", "message": "192.0.2.255 - - [06/May/2099:16:25:42 +0000] message2" } + """); + client().performRequest(bulkRequest); + } + + private void deleteDataStream(String name) throws Exception { + client().performRequest(new Request("DELETE", "_data_stream/" + name)); + } + + protected static Map toMap(Response response) throws IOException { + return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false); + } +} diff --git a/x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java b/x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java new file mode 100644 index 0000000000000..36cad34403e4c --- /dev/null +++ b/x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java @@ -0,0 +1,14 @@ + +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.xpack.usage; + +import org.elasticsearch.plugins.Plugin; + +public class UsageQA extends Plugin {} From 9d7073582c2838bc946e5cc84ee81ed57cd42918 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Tue, 16 May 2023 12:53:44 -0500 Subject: [PATCH 02/13] Update docs/changelog/96177.yaml --- docs/changelog/96177.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/96177.yaml diff --git a/docs/changelog/96177.yaml b/docs/changelog/96177.yaml new file mode 100644 index 0000000000000..d832a99019fda --- /dev/null +++ b/docs/changelog/96177.yaml @@ -0,0 +1,5 @@ +pr: 96177 +summary: Adding `data_lifecycle` to the _xpack/usage API +area: DLM +type: enhancement +issues: [] From 7b9c4bffc7d838cd73e7a2a4e76206ee590769ad Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Tue, 16 May 2023 13:10:08 -0500 Subject: [PATCH 03/13] fixing license --- .../java/org/elasticsearch/xpack/usage/XPackUsageIT.java | 5 ++--- .../main/java/org/elasticsearch/xpack/usage/UsageQA.java | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java index 942cae0984778..9f4869d944465 100644 --- a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java +++ b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java @@ -1,9 +1,8 @@ /* * 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 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. */ package org.elasticsearch.xpack.usage; diff --git a/x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java b/x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java index 36cad34403e4c..b59a85a8ca4c8 100644 --- a/x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java +++ b/x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java @@ -1,10 +1,8 @@ - /* * 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 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. */ package org.elasticsearch.xpack.usage; From e040fba8d89cd1079a0519b9421f64ad2de5fe59 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Tue, 16 May 2023 16:11:17 -0500 Subject: [PATCH 04/13] adding an integration test for DataLifecycleUsageTransportAction --- .../DataLifecycleUsageTransportActionIT.java | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportActionIT.java diff --git a/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportActionIT.java b/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportActionIT.java new file mode 100644 index 0000000000000..b45596234ecad --- /dev/null +++ b/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportActionIT.java @@ -0,0 +1,189 @@ +/* + * 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.core.action; + +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.ClusterStateUpdateTask; +import org.elasticsearch.cluster.metadata.DataLifecycle; +import org.elasticsearch.cluster.metadata.DataStream; +import org.elasticsearch.cluster.metadata.DataStreamAlias; +import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexMode; +import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.protocol.xpack.XPackUsageRequest; +import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.xcontent.ToXContent; +import org.elasticsearch.xcontent.XContentBuilder; +import org.elasticsearch.xcontent.XContentFactory; +import org.elasticsearch.xcontent.XContentType; +import org.elasticsearch.xpack.core.XPackClientPlugin; +import org.junit.After; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Function; + +import static org.elasticsearch.xpack.core.action.XPackUsageFeatureAction.DATA_LIFECYCLE; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; + +public class DataLifecycleUsageTransportActionIT extends ESIntegTestCase { + /* + * The DataLifecycleUsageTransportAction is not exposed in the xpack core plugin, so we have a special test plugin to do this + */ + @Override + protected Collection> nodePlugins() { + return List.of(TestDateLifecycleUsagePlugin.class); + } + + @After + private void removeDataStreamsFromClusterState() throws Exception { + updateClusterState(clusterState -> { + ClusterState.Builder clusterStateBuilder = new ClusterState.Builder(clusterState); + Metadata.Builder metadataBuilder = Metadata.builder(clusterState.metadata()); + metadataBuilder.dataStreams(Map.of(), Map.of()); + clusterStateBuilder.metadata(metadataBuilder); + return clusterStateBuilder.build(); + }); + } + + @SuppressWarnings("unchecked") + public void testAction() throws Exception { + assertUsageResults(0, 0, 0, 0.0); + AtomicLong count = new AtomicLong(0); + AtomicLong totalRetentionTimes = new AtomicLong(0); + AtomicLong minRetention = new AtomicLong(Long.MAX_VALUE); + AtomicLong maxRetention = new AtomicLong(Long.MIN_VALUE); + /* + * We now add a number of simulated data streams to the cluster state. Some have lifecycles, some don't. The ones with lifecycles + * have varying retention periods. After adding them, we make sure the numbers add up. + */ + updateClusterState(clusterState -> { + Metadata.Builder metadataBuilder = Metadata.builder(clusterState.metadata()); + Map dataStreamMap = new HashMap<>(); + for (int dataStreamCount = 0; dataStreamCount < randomInt(200); dataStreamCount++) { + boolean hasLifecycle = randomBoolean(); + long retentionMillis; + if (hasLifecycle) { + retentionMillis = randomLongBetween(1000, 100000); + count.incrementAndGet(); + totalRetentionTimes.addAndGet(retentionMillis); + if (retentionMillis < minRetention.get()) { + minRetention.set(retentionMillis); + } + if (retentionMillis > maxRetention.get()) { + maxRetention.set(retentionMillis); + } + } else { + retentionMillis = 0; + } + List indices = new ArrayList<>(); + for (int indicesCount = 0; indicesCount < randomIntBetween(1, 10); indicesCount++) { + Index index = new Index(randomAlphaOfLength(60), randomAlphaOfLength(60)); + indices.add(index); + } + boolean systemDataStream = randomBoolean(); + DataStream dataStream = new DataStream( + randomAlphaOfLength(50), + indices, + randomLongBetween(0, 1000), + Map.of(), + systemDataStream || randomBoolean(), + randomBoolean(), + systemDataStream, + randomBoolean(), + IndexMode.STANDARD, + hasLifecycle ? new DataLifecycle(retentionMillis) : null + ); + dataStreamMap.put(dataStream.getName(), dataStream); + } + Map dataStreamAliasesMap = Map.of(); + metadataBuilder.dataStreams(dataStreamMap, dataStreamAliasesMap); + ClusterState.Builder clusterStateBuilder = new ClusterState.Builder(clusterState); + clusterStateBuilder.metadata(metadataBuilder); + return clusterStateBuilder.build(); + }); + int expectedMinimumRetention = minRetention.get() == Long.MAX_VALUE ? 0 : minRetention.intValue(); + int expectedMaximumRetention = maxRetention.get() == Long.MIN_VALUE ? 0 : maxRetention.intValue(); + double expectedAverageRetention = count.get() == 0 ? 0.0 : totalRetentionTimes.doubleValue() / count.get(); + assertUsageResults(count.intValue(), expectedMinimumRetention, expectedMaximumRetention, expectedAverageRetention); + } + + @SuppressWarnings("unchecked") + private void assertUsageResults(int count, int minimumRetention, int maximumRetention, double averageRetention) throws Exception { + XPackUsageFeatureResponse response = client().execute(DATA_LIFECYCLE, new XPackUsageRequest()).get(); + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder = response.getUsage().toXContent(builder, ToXContent.EMPTY_PARAMS); + Tuple> tuple = XContentHelper.convertToMap( + BytesReference.bytes(builder), + true, + XContentType.JSON + ); + + Map map = tuple.v2(); + assertThat(map.get("available"), equalTo(true)); + assertThat(map.get("enabled"), equalTo(true)); + assertThat(map.get("count"), equalTo(count)); + assertThat(map.get("rollover_config"), notNullValue()); + Map retentionMap = (Map) map.get("retention"); + assertThat(retentionMap.size(), equalTo(3)); + assertThat(retentionMap.get("minimum_millis"), equalTo(minimumRetention)); + assertThat(retentionMap.get("maximum_millis"), equalTo(maximumRetention)); + assertThat(retentionMap.get("average_millis"), equalTo(averageRetention)); + } + + /* + * Updates the cluster state in the internal cluster using the provided function + */ + protected static void updateClusterState(final Function updater) throws Exception { + final PlainActionFuture future = PlainActionFuture.newFuture(); + final ClusterService clusterService = internalCluster().getCurrentMasterNodeInstance(ClusterService.class); + clusterService.submitUnbatchedStateUpdateTask("test", new ClusterStateUpdateTask() { + @Override + public ClusterState execute(ClusterState currentState) { + return updater.apply(currentState); + } + + @Override + public void onFailure(Exception e) { + future.onFailure(e); + } + + @Override + public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { + future.onResponse(null); + } + }); + future.get(); + } + + /* + * This plugin exposes the DataLifecycleUsageTransportAction. + */ + public static final class TestDateLifecycleUsagePlugin extends XPackClientPlugin { + @Override + public List> getActions() { + List> actions = new ArrayList<>(); + actions.add(new ActionPlugin.ActionHandler<>(DATA_LIFECYCLE, DataLifecycleUsageTransportAction.class)); + return actions; + } + } +} From 786cf2142e5cce64202738885556c4ccad5be0b9 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Tue, 16 May 2023 16:59:19 -0500 Subject: [PATCH 05/13] cleanup --- docs/reference/rest-api/usage.asciidoc | 13 +++++++++++++ .../org/elasticsearch/xpack/usage/XPackUsageIT.java | 6 +----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/reference/rest-api/usage.asciidoc b/docs/reference/rest-api/usage.asciidoc index 82ce4d4a7d471..c0f8f243aa4f6 100644 --- a/docs/reference/rest-api/usage.asciidoc +++ b/docs/reference/rest-api/usage.asciidoc @@ -328,6 +328,19 @@ GET /_xpack/usage "data_streams" : 0, "indices_count" : 0 }, + "data_lifecycle" : { + "available": true, + "enabled": true, + "lifecycle": { + "count": 0, + "rollover_config": "{\"max_age\":\"30s\",\"min_docs\":1,\"max_primary_shard_docs\":200000000,\"max_primary_shard_size\":\"50gb\"}", + "retention": { + "minimum_millis": 0, + "maximum_millis": 0, + "average_millis": 0.0 + } + } + }, "data_tiers" : { "available" : true, "enabled" : true, diff --git a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java index 9f4869d944465..2e7d40073e722 100644 --- a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java +++ b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java @@ -61,7 +61,7 @@ private void assertDataLifecycleUsageResults(int count, int minimumRetention, in throws Exception { Response response = client().performRequest(new Request("GET", "/_xpack/usage")); assertThat(response.getStatusLine().getStatusCode(), is(200)); - Map responseMap = toMap(response); + Map responseMap = entityAsMap(response); Map dataLifecycleMap = (Map) responseMap.get("data_lifecycle"); assertThat(dataLifecycleMap.get("available"), equalTo(true)); assertThat(dataLifecycleMap.get("enabled"), equalTo(true)); @@ -129,8 +129,4 @@ private void createDataStream(String name, String lifecycle) throws Exception { private void deleteDataStream(String name) throws Exception { client().performRequest(new Request("DELETE", "_data_stream/" + name)); } - - protected static Map toMap(Response response) throws IOException { - return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false); - } } From 56ca4a12d19bd279aef8a95fd6e6ee489a5ad7b2 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Tue, 16 May 2023 17:07:01 -0500 Subject: [PATCH 06/13] spotlessApply --- .../java/org/elasticsearch/xpack/usage/XPackUsageIT.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java index 2e7d40073e722..2c26e5c5dc024 100644 --- a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java +++ b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java @@ -7,19 +7,15 @@ package org.elasticsearch.xpack.usage; -import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; -import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.core.TimeValue; import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.xcontent.json.JsonXContent; -import java.io.IOException; import java.util.Map; import static org.hamcrest.Matchers.equalTo; From 8a3a42103d45a7f58e5113eae99f287b12236320 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 18 May 2023 14:32:47 -0500 Subject: [PATCH 07/13] putting DLM telemetry behind the feature flag --- .../xpack/core/XPackClientPlugin.java | 15 ++++++++++++--- .../org/elasticsearch/xpack/core/XPackPlugin.java | 5 ++++- .../core/action/XPackUsageFeatureAction.java | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) 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 3f0d8efce7805..a6cbc37c89f4d 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 @@ -10,6 +10,7 @@ import org.elasticsearch.action.ActionType; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.NamedDiff; +import org.elasticsearch.cluster.metadata.DataLifecycle; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Setting; @@ -235,6 +236,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; +import java.util.stream.Stream; // TODO: merge this into XPackPlugin public class XPackClientPlugin extends Plugin implements ActionPlugin, NetworkPlugin { @@ -415,7 +418,7 @@ public List> getClientActions() { @Override public List getNamedWriteables() { - return Arrays.asList( + return Stream.of( // graph new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.GRAPH, GraphFeatureSetUsage::new), // logstash @@ -546,7 +549,13 @@ public List getNamedWriteables() { ), // Data Streams new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.DATA_STREAMS, DataStreamFeatureSetUsage::new), - new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.DATA_LIFECYCLE, DataLifecycleFeatureSetUsage::new), + DataLifecycle.isEnabled() + ? new NamedWriteableRegistry.Entry( + XPackFeatureSet.Usage.class, + XPackField.DATA_LIFECYCLE, + DataLifecycleFeatureSetUsage::new + ) + : null, // Data Tiers new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.DATA_TIERS, DataTiersFeatureSetUsage::new), // Archive @@ -563,7 +572,7 @@ public List getNamedWriteables() { XPackField.ENTERPRISE_SEARCH, EnterpriseSearchFeatureSetUsage::new ) - ); + ).filter(Objects::nonNull).toList(); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index 80fc9695e74d7..f3130ed3d0142 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java @@ -17,6 +17,7 @@ import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.DataLifecycle; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -356,7 +357,9 @@ public Collection createComponents( actions.add(new ActionHandler<>(XPackUsageFeatureAction.DATA_TIERS, DataTiersUsageTransportAction.class)); actions.add(new ActionHandler<>(XPackUsageFeatureAction.DATA_STREAMS, DataStreamUsageTransportAction.class)); actions.add(new ActionHandler<>(XPackInfoFeatureAction.DATA_STREAMS, DataStreamInfoTransportAction.class)); - actions.add(new ActionHandler<>(XPackUsageFeatureAction.DATA_LIFECYCLE, DataLifecycleUsageTransportAction.class)); + if (DataLifecycle.isEnabled()) { + actions.add(new ActionHandler<>(XPackUsageFeatureAction.DATA_LIFECYCLE, DataLifecycleUsageTransportAction.class)); + } actions.add(new ActionHandler<>(XPackUsageFeatureAction.HEALTH, HealthApiUsageTransportAction.class)); actions.add(new ActionHandler<>(XPackUsageFeatureAction.REMOTE_CLUSTERS, RemoteClusterUsageTransportAction.class)); return actions; 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 fda06bd491a37..8ddcdfd2e9e24 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 @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.core.action; import org.elasticsearch.action.ActionType; +import org.elasticsearch.cluster.metadata.DataLifecycle; import org.elasticsearch.transport.TcpTransport; import org.elasticsearch.xpack.core.XPackField; @@ -58,7 +59,7 @@ public class XPackUsageFeatureAction extends ActionType Date: Thu, 18 May 2023 15:43:35 -0500 Subject: [PATCH 08/13] exposing default_rollover_used rather than rollover_config --- docs/reference/rest-api/usage.asciidoc | 2 +- .../DataLifecycleUsageTransportActionIT.java | 29 +++++++++++++++---- .../DataLifecycleUsageTransportAction.java | 2 +- .../DataLifecycleFeatureSetUsage.java | 18 ++++++------ .../DataLifecycleFeatureSetUsageTests.java | 12 ++++---- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/docs/reference/rest-api/usage.asciidoc b/docs/reference/rest-api/usage.asciidoc index c0f8f243aa4f6..4b1801be044cc 100644 --- a/docs/reference/rest-api/usage.asciidoc +++ b/docs/reference/rest-api/usage.asciidoc @@ -333,7 +333,7 @@ GET /_xpack/usage "enabled": true, "lifecycle": { "count": 0, - "rollover_config": "{\"max_age\":\"30s\",\"min_docs\":1,\"max_primary_shard_docs\":200000000,\"max_primary_shard_size\":\"50gb\"}", + "default_rollover_used": true, "retention": { "minimum_millis": 0, "maximum_millis": 0, diff --git a/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportActionIT.java b/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportActionIT.java index b45596234ecad..7ca5b12462a8e 100644 --- a/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportActionIT.java +++ b/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportActionIT.java @@ -18,6 +18,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.core.Tuple; import org.elasticsearch.index.Index; @@ -43,7 +44,6 @@ import static org.elasticsearch.xpack.core.action.XPackUsageFeatureAction.DATA_LIFECYCLE; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; public class DataLifecycleUsageTransportActionIT extends ESIntegTestCase { /* @@ -55,7 +55,7 @@ protected Collection> nodePlugins() { } @After - private void removeDataStreamsFromClusterState() throws Exception { + private void cleanup() throws Exception { updateClusterState(clusterState -> { ClusterState.Builder clusterStateBuilder = new ClusterState.Builder(clusterState); Metadata.Builder metadataBuilder = Metadata.builder(clusterState.metadata()); @@ -63,15 +63,20 @@ private void removeDataStreamsFromClusterState() throws Exception { clusterStateBuilder.metadata(metadataBuilder); return clusterStateBuilder.build(); }); + updateClusterSettings(Settings.builder().put(DataLifecycle.CLUSTER_DLM_DEFAULT_ROLLOVER_SETTING.getKey(), (String) null)); } @SuppressWarnings("unchecked") public void testAction() throws Exception { - assertUsageResults(0, 0, 0, 0.0); + assertUsageResults(0, 0, 0, 0.0, true); AtomicLong count = new AtomicLong(0); AtomicLong totalRetentionTimes = new AtomicLong(0); AtomicLong minRetention = new AtomicLong(Long.MAX_VALUE); AtomicLong maxRetention = new AtomicLong(Long.MIN_VALUE); + boolean useDefaultRolloverConfig = randomBoolean(); + if (useDefaultRolloverConfig == false) { + updateClusterSettings(Settings.builder().put(DataLifecycle.CLUSTER_DLM_DEFAULT_ROLLOVER_SETTING.getKey(), "min_docs=33")); + } /* * We now add a number of simulated data streams to the cluster state. Some have lifecycles, some don't. The ones with lifecycles * have varying retention periods. After adding them, we make sure the numbers add up. @@ -124,11 +129,23 @@ public void testAction() throws Exception { int expectedMinimumRetention = minRetention.get() == Long.MAX_VALUE ? 0 : minRetention.intValue(); int expectedMaximumRetention = maxRetention.get() == Long.MIN_VALUE ? 0 : maxRetention.intValue(); double expectedAverageRetention = count.get() == 0 ? 0.0 : totalRetentionTimes.doubleValue() / count.get(); - assertUsageResults(count.intValue(), expectedMinimumRetention, expectedMaximumRetention, expectedAverageRetention); + assertUsageResults( + count.intValue(), + expectedMinimumRetention, + expectedMaximumRetention, + expectedAverageRetention, + useDefaultRolloverConfig + ); } @SuppressWarnings("unchecked") - private void assertUsageResults(int count, int minimumRetention, int maximumRetention, double averageRetention) throws Exception { + private void assertUsageResults( + int count, + int minimumRetention, + int maximumRetention, + double averageRetention, + boolean defaultRolloverUsed + ) throws Exception { XPackUsageFeatureResponse response = client().execute(DATA_LIFECYCLE, new XPackUsageRequest()).get(); XContentBuilder builder = XContentFactory.jsonBuilder(); builder = response.getUsage().toXContent(builder, ToXContent.EMPTY_PARAMS); @@ -142,7 +159,7 @@ private void assertUsageResults(int count, int minimumRetention, int maximumRete assertThat(map.get("available"), equalTo(true)); assertThat(map.get("enabled"), equalTo(true)); assertThat(map.get("count"), equalTo(count)); - assertThat(map.get("rollover_config"), notNullValue()); + assertThat(map.get("default_rollover_used"), equalTo(defaultRolloverUsed)); Map retentionMap = (Map) map.get("retention"); assertThat(retentionMap.size(), equalTo(3)); assertThat(retentionMap.get("minimum_millis"), equalTo(minimumRetention)); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportAction.java index ca01f35653b33..7b0babc73a724 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataLifecycleUsageTransportAction.java @@ -69,7 +69,7 @@ protected void masterOperation( minRetention, maxRetention, averageRetention, - rolloverConfigString + DataLifecycle.CLUSTER_DLM_DEFAULT_ROLLOVER_SETTING.getDefault(null).toString().equals(rolloverConfigString) ); final DataLifecycleFeatureSetUsage usage = new DataLifecycleFeatureSetUsage(stats); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsage.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsage.java index 5fec3e66698e9..f6a64ac97e510 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsage.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsage.java @@ -47,7 +47,7 @@ public TransportVersion getMinimalSupportedVersion() { protected void innerXContent(XContentBuilder builder, Params params) throws IOException { super.innerXContent(builder, params); builder.field("count", lifecycleStats.dataStreamsWithLifecyclesCount); - builder.field("rollover_config", lifecycleStats.rolloverConfigString); + builder.field("default_rollover_used", lifecycleStats.defaultRolloverUsed); builder.startObject("retention"); builder.field("minimum_millis", lifecycleStats.minRetentionMillis); builder.field("maximum_millis", lifecycleStats.maxRetentionMillis); @@ -82,20 +82,20 @@ public static class LifecycleStats implements Writeable { final long minRetentionMillis; final long maxRetentionMillis; final double averageRetentionMillis; - final String rolloverConfigString; + final boolean defaultRolloverUsed; public LifecycleStats( long dataStreamsWithLifecyclesCount, long minRetention, long maxRetention, double averageRetention, - String rolloverConfigString + boolean defaultRolloverUsed ) { this.dataStreamsWithLifecyclesCount = dataStreamsWithLifecyclesCount; this.minRetentionMillis = minRetention; this.maxRetentionMillis = maxRetention; this.averageRetentionMillis = averageRetention; - this.rolloverConfigString = rolloverConfigString; + this.defaultRolloverUsed = defaultRolloverUsed; } public LifecycleStats(StreamInput in) throws IOException { @@ -104,13 +104,13 @@ public LifecycleStats(StreamInput in) throws IOException { this.minRetentionMillis = in.readVLong(); this.maxRetentionMillis = in.readVLong(); this.averageRetentionMillis = in.readDouble(); - this.rolloverConfigString = in.readString(); + this.defaultRolloverUsed = in.readBoolean(); } else { this.dataStreamsWithLifecyclesCount = 0; this.minRetentionMillis = 0; this.maxRetentionMillis = 0; this.averageRetentionMillis = 0.0; - this.rolloverConfigString = null; + this.defaultRolloverUsed = false; } } @@ -121,7 +121,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeVLong(minRetentionMillis); out.writeVLong(maxRetentionMillis); out.writeDouble(averageRetentionMillis); - out.writeString(rolloverConfigString); + out.writeBoolean(defaultRolloverUsed); } } @@ -132,7 +132,7 @@ public int hashCode() { minRetentionMillis, maxRetentionMillis, averageRetentionMillis, - rolloverConfigString + defaultRolloverUsed ); } @@ -146,7 +146,7 @@ public boolean equals(Object obj) { && minRetentionMillis == other.minRetentionMillis && maxRetentionMillis == other.maxRetentionMillis && averageRetentionMillis == other.averageRetentionMillis - && Objects.equals(rolloverConfigString, other.rolloverConfigString); + && defaultRolloverUsed == other.defaultRolloverUsed; } } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsageTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsageTests.java index fadc1bdbf8b41..19d27fc038fa8 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsageTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsageTests.java @@ -21,7 +21,7 @@ protected DataLifecycleFeatureSetUsage createTestInstance() { randomNonNegativeLong(), randomNonNegativeLong(), randomDouble(), - randomAlphaOfLength(10) + randomBoolean() ) ); } @@ -35,7 +35,7 @@ protected DataLifecycleFeatureSetUsage mutateInstance(DataLifecycleFeatureSetUsa instance.lifecycleStats.minRetentionMillis, instance.lifecycleStats.maxRetentionMillis, instance.lifecycleStats.averageRetentionMillis, - instance.lifecycleStats.rolloverConfigString + instance.lifecycleStats.defaultRolloverUsed ) ); case 1 -> new DataLifecycleFeatureSetUsage( @@ -44,7 +44,7 @@ protected DataLifecycleFeatureSetUsage mutateInstance(DataLifecycleFeatureSetUsa randomValueOtherThan(instance.lifecycleStats.minRetentionMillis, ESTestCase::randomLong), instance.lifecycleStats.maxRetentionMillis, instance.lifecycleStats.averageRetentionMillis, - instance.lifecycleStats.rolloverConfigString + instance.lifecycleStats.defaultRolloverUsed ) ); case 2 -> new DataLifecycleFeatureSetUsage( @@ -53,7 +53,7 @@ protected DataLifecycleFeatureSetUsage mutateInstance(DataLifecycleFeatureSetUsa instance.lifecycleStats.minRetentionMillis, randomValueOtherThan(instance.lifecycleStats.maxRetentionMillis, ESTestCase::randomLong), instance.lifecycleStats.averageRetentionMillis, - instance.lifecycleStats.rolloverConfigString + instance.lifecycleStats.defaultRolloverUsed ) ); case 3 -> new DataLifecycleFeatureSetUsage( @@ -62,7 +62,7 @@ protected DataLifecycleFeatureSetUsage mutateInstance(DataLifecycleFeatureSetUsa instance.lifecycleStats.minRetentionMillis, instance.lifecycleStats.maxRetentionMillis, randomValueOtherThan(instance.lifecycleStats.averageRetentionMillis, ESTestCase::randomDouble), - instance.lifecycleStats.rolloverConfigString + instance.lifecycleStats.defaultRolloverUsed ) ); case 4 -> new DataLifecycleFeatureSetUsage( @@ -71,7 +71,7 @@ protected DataLifecycleFeatureSetUsage mutateInstance(DataLifecycleFeatureSetUsa instance.lifecycleStats.minRetentionMillis, instance.lifecycleStats.maxRetentionMillis, instance.lifecycleStats.averageRetentionMillis, - randomValueOtherThan(instance.lifecycleStats.rolloverConfigString, () -> randomAlphaOfLength(20)) + instance.lifecycleStats.defaultRolloverUsed == false ) ); default -> throw new RuntimeException("unreachable"); From fd15459ba61971f3a9d3954f0c97aa1e24d1ed32 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 18 May 2023 16:25:41 -0500 Subject: [PATCH 09/13] exposing default_rollover_used rather than rollover_config --- .../java/org/elasticsearch/xpack/usage/XPackUsageIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java index 2c26e5c5dc024..f34d59baf3c42 100644 --- a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java +++ b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java @@ -62,7 +62,7 @@ private void assertDataLifecycleUsageResults(int count, int minimumRetention, in assertThat(dataLifecycleMap.get("available"), equalTo(true)); assertThat(dataLifecycleMap.get("enabled"), equalTo(true)); assertThat(dataLifecycleMap.get("count"), equalTo(count)); - assertThat(dataLifecycleMap.get("rollover_config"), notNullValue()); + assertThat(dataLifecycleMap.get("default_rollover_used"), equalTo(true)); Map retentionMap = (Map) dataLifecycleMap.get("retention"); assertThat(retentionMap.size(), equalTo(3)); assertThat(retentionMap.get("minimum_millis"), equalTo(minimumRetention)); From 2350562b144c0cbb98ef8aafaf78290685ff19ec Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 18 May 2023 16:30:51 -0500 Subject: [PATCH 10/13] spotlessApply --- .../java/org/elasticsearch/xpack/usage/XPackUsageIT.java | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java index f34d59baf3c42..72ab9d8e3be7b 100644 --- a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java +++ b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java @@ -20,7 +20,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; /* * This class is meant to test the _xpack/usage API. That API pulls in code from various plugins so it cannot be integration tested From 93a33eecb7ca70a330a53217d09a21bb11cf3f42 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 25 May 2023 17:11:07 -0500 Subject: [PATCH 11/13] replacing XPackUsageIT with a yaml rest test --- .../rest-api-spec/test/dlm/10_usage.yml | 81 +++++++++++ .../xpack/usage/XPackUsageIT.java | 127 ------------------ 2 files changed, 81 insertions(+), 127 deletions(-) create mode 100644 x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/dlm/10_usage.yml delete mode 100644 x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/dlm/10_usage.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/dlm/10_usage.yml new file mode 100644 index 0000000000000..bad01b09b896b --- /dev/null +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/dlm/10_usage.yml @@ -0,0 +1,81 @@ +--- +"Test DLM usage stats": + - skip: + version: "- 8.8.99" + reason: "the dlm stats were only added to the usage api in 8.9" + + - do: + xpack.usage: {} + + - match: { data_lifecycle.available: true } + - match: { data_lifecycle.enabled: true } + - match: { data_lifecycle.count: 0 } + - match: { data_lifecycle.default_rollover_used: true } + - match: { data_lifecycle.retention.minimum_millis: 0 } + - match: { data_lifecycle.retention.maximum_millis: 0 } + - match: { data_lifecycle.retention.average_millis: 0 } + + - do: + indices.put_index_template: + name: my-template-1 + body: + index_patterns: [foo-*] + template: + mappings: + properties: + '@timestamp': + type: date + lifecycle: + data_retention: 10d + data_stream: {} + + - do: + indices.create_data_stream: + name: foo-foobar + - is_true: acknowledged + + - do: + indices.put_index_template: + name: my-template-2 + body: + index_patterns: [bar-*] + template: + mappings: + properties: + '@timestamp': + type: date + lifecycle: + data_retention: 5d + data_stream: {} + + - do: + indices.create_data_stream: + name: bar-foobar + - is_true: acknowledged + + - do: + xpack.usage: {} + + - match: { data_lifecycle.available: true } + - match: { data_lifecycle.enabled: true } + - match: { data_lifecycle.count: 2 } + - match: { data_lifecycle.default_rollover_used: true } + - match: { data_lifecycle.retention.minimum_millis: 432000000 } + - match: { data_lifecycle.retention.maximum_millis: 864000000 } + - match: { data_lifecycle.retention.average_millis: 648000000 } + + - do: + indices.delete_data_stream: + name: foo-foobar + - is_true: acknowledged + + - do: + xpack.usage: {} + + - match: { data_lifecycle.available: true } + - match: { data_lifecycle.enabled: true } + - match: { data_lifecycle.count: 1 } + - match: { data_lifecycle.default_rollover_used: true } + - match: { data_lifecycle.retention.minimum_millis: 432000000 } + - match: { data_lifecycle.retention.maximum_millis: 432000000 } + - match: { data_lifecycle.retention.average_millis: 432000000 } diff --git a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java b/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java deleted file mode 100644 index 72ab9d8e3be7b..0000000000000 --- a/x-pack/qa/usage/src/javaRestTest/java/org/elasticsearch/xpack/usage/XPackUsageIT.java +++ /dev/null @@ -1,127 +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.usage; - -import org.elasticsearch.client.Request; -import org.elasticsearch.client.Response; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.settings.SecureString; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.ThreadContext; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.test.rest.ESRestTestCase; - -import java.util.Map; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; - -/* - * This class is meant to test the _xpack/usage API. That API pulls in code from various plugins so it cannot be integration tested - * within x-pack/plugin/core. - */ -public class XPackUsageIT extends ESRestTestCase { - static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("rest_user", new SecureString("rest-user-password".toCharArray())); - - @Override - protected Settings restClientSettings() { - return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", BASIC_AUTH_VALUE).build(); - } - - /* - * This method checks the data_lifecyle portion of the usage API response. - */ - public void testDataLifecycle() throws Exception { - // Make sure that everything is zero when there are no datastreams: - assertDataLifecycleUsageResults(0, 0, 0, 0.0); - createDataStream("ds1", TimeValue.timeValueMillis(10000)); - assertDataLifecycleUsageResults(1, 10000, 10000, 10000.0); - createDataStream("ds2", TimeValue.timeValueMillis(5000)); - assertDataLifecycleUsageResults(2, 5000, 10000, 7500.0); - // Make sure the counters don't change if we add a datastream that has no lifecycle: - createDataStreamNoLifecycle("ds3"); - assertDataLifecycleUsageResults(2, 5000, 10000, 7500.0); - // Make sure that deleting a datastream takes it out of the numbers: - deleteDataStream("ds1"); - assertDataLifecycleUsageResults(1, 5000, 5000, 5000.0); - } - - @SuppressWarnings("unchecked") - private void assertDataLifecycleUsageResults(int count, int minimumRetention, int maximumRetention, double averageRetention) - throws Exception { - Response response = client().performRequest(new Request("GET", "/_xpack/usage")); - assertThat(response.getStatusLine().getStatusCode(), is(200)); - Map responseMap = entityAsMap(response); - Map dataLifecycleMap = (Map) responseMap.get("data_lifecycle"); - assertThat(dataLifecycleMap.get("available"), equalTo(true)); - assertThat(dataLifecycleMap.get("enabled"), equalTo(true)); - assertThat(dataLifecycleMap.get("count"), equalTo(count)); - assertThat(dataLifecycleMap.get("default_rollover_used"), equalTo(true)); - Map retentionMap = (Map) dataLifecycleMap.get("retention"); - assertThat(retentionMap.size(), equalTo(3)); - assertThat(retentionMap.get("minimum_millis"), equalTo(minimumRetention)); - assertThat(retentionMap.get("maximum_millis"), equalTo(maximumRetention)); - assertThat(retentionMap.get("average_millis"), equalTo(averageRetention)); - } - - private void createDataStream(String name, TimeValue retention) throws Exception { - String lifecycle = Strings.format(""" - , - "lifecycle": { - "data_retention":"%s" - } - """, retention); - this.createDataStream(name, lifecycle); - } - - private void createDataStreamNoLifecycle(String name) throws Exception { - this.createDataStream(name, ""); - } - - private void createDataStream(String name, String lifecycle) throws Exception { - Request componentTemplateRequest = new Request("PUT", "_component_template/mappings_" + name); - componentTemplateRequest.setJsonEntity(Strings.format(""" - { - "template": { - "mappings": { - "properties": { - "@timestamp": { - "type": "date", - "format": "date_optional_time||epoch_millis" - }, - "message": { - "type": "wildcard" - } - } - }%s - } - } - """, lifecycle)); - client().performRequest(componentTemplateRequest); - Request indexTemplateRequest = new Request("PUT", "_index_template/index-template-" + name); - indexTemplateRequest.setJsonEntity(Strings.format(""" - { - "index_patterns": ["%s*"], - "data_stream": { }, - "composed_of": [ "mappings_%s" ] - }""", name, name)); - client().performRequest(indexTemplateRequest); - Request bulkRequest = new Request("PUT", name + "/_bulk"); - bulkRequest.setJsonEntity(""" - { "create":{ } } - { "@timestamp": "2099-05-06T16:21:15.000Z", "message": "192.0.2.42 - - [06/May/2099:16:21:15 +0000] message1" } - { "create":{ } } - { "@timestamp": "2099-05-06T16:25:42.000Z", "message": "192.0.2.255 - - [06/May/2099:16:25:42 +0000] message2" } - """); - client().performRequest(bulkRequest); - } - - private void deleteDataStream(String name) throws Exception { - client().performRequest(new Request("DELETE", "_data_stream/" + name)); - } -} From 2a22ead04bcc11376424aab589947b651e21c490 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Fri, 26 May 2023 08:50:08 -0500 Subject: [PATCH 12/13] removing now-unused files --- x-pack/qa/usage/build.gradle | 25 ------------------- .../elasticsearch/xpack/usage/UsageQA.java | 12 --------- 2 files changed, 37 deletions(-) delete mode 100644 x-pack/qa/usage/build.gradle delete mode 100644 x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java diff --git a/x-pack/qa/usage/build.gradle b/x-pack/qa/usage/build.gradle deleted file mode 100644 index f4cd05fe11e05..0000000000000 --- a/x-pack/qa/usage/build.gradle +++ /dev/null @@ -1,25 +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 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -apply plugin: 'elasticsearch.base-internal-es-plugin' -apply plugin: 'elasticsearch.legacy-java-rest-test' - -esplugin { - name 'usage-qa' - description 'Plugin for performing QA of xpack usage' - classname 'org.elasticsearch.xpack.usage.UsageQA' - licenseFile rootProject.file('licenses/SSPL-1.0+ELASTIC-LICENSE-2.0.txt') - noticeFile rootProject.file('NOTICE.txt') -} - -testClusters.configureEach { - testDistribution = 'DEFAULT' - setting 'xpack.security.enabled', 'true' - setting 'xpack.security.autoconfiguration.enabled', 'false' - user username: 'rest_user', password: 'rest-user-password' -} diff --git a/x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java b/x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java deleted file mode 100644 index b59a85a8ca4c8..0000000000000 --- a/x-pack/qa/usage/src/main/java/org/elasticsearch/xpack/usage/UsageQA.java +++ /dev/null @@ -1,12 +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.usage; - -import org.elasticsearch.plugins.Plugin; - -public class UsageQA extends Plugin {} From e3f4bc294193fe1eb1180687ceac5faaf14edfd6 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Fri, 26 May 2023 08:52:27 -0500 Subject: [PATCH 13/13] Updating TransportVersion Co-authored-by: Mary Gouseti --- .../core/datastreams/DataLifecycleFeatureSetUsage.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsage.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsage.java index f6a64ac97e510..8e92e9631ff14 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsage.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datastreams/DataLifecycleFeatureSetUsage.java @@ -40,7 +40,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public TransportVersion getMinimalSupportedVersion() { - return TransportVersion.V_8_500_004; + return TransportVersion.V_8_500_006; } @Override @@ -99,7 +99,7 @@ public LifecycleStats( } public LifecycleStats(StreamInput in) throws IOException { - if (in.getTransportVersion().onOrAfter(TransportVersion.V_8_500_004)) { + if (in.getTransportVersion().onOrAfter(TransportVersion.V_8_500_006)) { this.dataStreamsWithLifecyclesCount = in.readVLong(); this.minRetentionMillis = in.readVLong(); this.maxRetentionMillis = in.readVLong(); @@ -116,7 +116,7 @@ public LifecycleStats(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { - if (out.getTransportVersion().onOrAfter(TransportVersion.V_8_500_004)) { + if (out.getTransportVersion().onOrAfter(TransportVersion.V_8_500_006)) { out.writeVLong(dataStreamsWithLifecyclesCount); out.writeVLong(minRetentionMillis); out.writeVLong(maxRetentionMillis);