From b387bdc9917c28c0c16be21b99cdb86da15b9243 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 30 Oct 2024 18:32:31 -0700 Subject: [PATCH] WIP - tel --- docs/reference/rest-api/info.asciidoc | 4 ++ docs/reference/rest-api/usage.asciidoc | 6 +++ .../xpack/core/XPackClientPlugin.java | 3 +- .../xpack/core/XPackFeatures.java | 4 +- .../application}/LogsDBFeatureSetUsage.java | 4 +- .../xpack/logsdb/LogsDBPlugin.java | 16 ++++++- .../logsdb/LogsDBUsageTransportAction.java | 1 + .../resources/rest-api-spec/test/60_usage.yml | 43 +++++++++++++++++++ .../rest-api-spec/test/logsdb/10_usage.yml | 40 +++++++++++++++++ 9 files changed, 116 insertions(+), 5 deletions(-) rename x-pack/plugin/{logsdb/src/main/java/org/elasticsearch/xpack/logsdb => core/src/main/java/org/elasticsearch/xpack/core/application}/LogsDBFeatureSetUsage.java (95%) create mode 100644 x-pack/plugin/logsdb/src/yamlRestTest/resources/rest-api-spec/test/60_usage.yml create mode 100644 x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/logsdb/10_usage.yml diff --git a/docs/reference/rest-api/info.asciidoc b/docs/reference/rest-api/info.asciidoc index 28b6df215a18d..602b532be3fc6 100644 --- a/docs/reference/rest-api/info.asciidoc +++ b/docs/reference/rest-api/info.asciidoc @@ -172,6 +172,10 @@ Example response: "universal_profiling": { "available": true, "enabled": true + }, + "logsdb": { + "available": true, + "enabled": true } }, "tagline" : "You know, for X" diff --git a/docs/reference/rest-api/usage.asciidoc b/docs/reference/rest-api/usage.asciidoc index 27cc1723265c9..27bb3bca86ef9 100644 --- a/docs/reference/rest-api/usage.asciidoc +++ b/docs/reference/rest-api/usage.asciidoc @@ -518,6 +518,12 @@ GET /_xpack/usage "universal_profiling" : { "available" : true, "enabled" : true + }, + "logsdb": { + "available": true, + "enabled": true, + "indices_count": 0, + "indices_with_synthetic_source": 0 } } ------------------------------------------------------------ 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 9004239478bdf..201690a310c3a 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 @@ -305,7 +305,8 @@ public List getNamedWriteables() { PersistentTaskParams.class, SecurityMigrationTaskParams.TASK_NAME, SecurityMigrationTaskParams::new - ) + ), + new NamedWriteableRegistry.Entry(XPackFeatureUsage.class, XPackField.LOGSDB, LogstashFeatureSetUsage::new) ).filter(Objects::nonNull).toList(); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackFeatures.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackFeatures.java index 13404772e79a9..a7cf878511d78 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackFeatures.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackFeatures.java @@ -20,12 +20,14 @@ * Provides the XPack features that this version of the code supports */ public class XPackFeatures implements FeatureSpecification { + public static final NodeFeature LOGSDB_TELEMETRY = new NodeFeature("logsdb_telemetry"); @Override public Set getFeatures() { return Set.of( NodesDataTiersUsageTransportAction.LOCALLY_PRECALCULATED_STATS_FEATURE, // Added in 8.12 - License.INDEPENDENT_TRIAL_VERSION_FEATURE // 8.14.0 + License.INDEPENDENT_TRIAL_VERSION_FEATURE, // 8.14.0 + LOGSDB_TELEMETRY ); } diff --git a/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBFeatureSetUsage.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/application/LogsDBFeatureSetUsage.java similarity index 95% rename from x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBFeatureSetUsage.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/application/LogsDBFeatureSetUsage.java index b8395399588d4..22f14ec256646 100644 --- a/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBFeatureSetUsage.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/application/LogsDBFeatureSetUsage.java @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -package org.elasticsearch.xpack.logsdb; +package org.elasticsearch.xpack.core.application; import org.elasticsearch.TransportVersion; import org.elasticsearch.TransportVersions; @@ -17,7 +17,7 @@ import java.io.IOException; import java.util.Objects; -public class LogsDBFeatureSetUsage extends XPackFeatureUsage { +public final class LogsDBFeatureSetUsage extends XPackFeatureUsage { private final int indicesCount; private final int indicesWithSyntheticSource; diff --git a/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBPlugin.java b/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBPlugin.java index 4bb329c980a7e..0eb0754985c94 100644 --- a/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBPlugin.java +++ b/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBPlugin.java @@ -7,19 +7,25 @@ package org.elasticsearch.xpack.logsdb; +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexSettingProvider; +import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.xpack.core.XPackPlugin; +import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction; +import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import static org.elasticsearch.xpack.logsdb.SyntheticSourceLicenseService.FALLBACK_SETTING; -public class LogsDBPlugin extends Plugin { +public class LogsDBPlugin extends Plugin implements ActionPlugin { private final Settings settings; private final SyntheticSourceLicenseService licenseService; @@ -66,4 +72,12 @@ public Collection getAdditionalIndexSettingProviders(Index public List> getSettings() { return List.of(FALLBACK_SETTING, CLUSTER_LOGSDB_ENABLED); } + + @Override + public List> getActions() { + List> actions = new ArrayList<>(); + actions.add(new ActionPlugin.ActionHandler<>(XPackUsageFeatureAction.LOGSDB, LogsDBUsageTransportAction.class)); + actions.add(new ActionPlugin.ActionHandler<>(XPackInfoFeatureAction.LOGSDB, LogsDBInfoTransportAction.class)); + return actions; + } } diff --git a/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBUsageTransportAction.java b/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBUsageTransportAction.java index 18d2997d6e6e2..f3d99051994cb 100644 --- a/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBUsageTransportAction.java +++ b/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBUsageTransportAction.java @@ -22,6 +22,7 @@ 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.application.LogsDBFeatureSetUsage; import static org.elasticsearch.index.mapper.SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING; diff --git a/x-pack/plugin/logsdb/src/yamlRestTest/resources/rest-api-spec/test/60_usage.yml b/x-pack/plugin/logsdb/src/yamlRestTest/resources/rest-api-spec/test/60_usage.yml new file mode 100644 index 0000000000000..95c97e73206d3 --- /dev/null +++ b/x-pack/plugin/logsdb/src/yamlRestTest/resources/rest-api-spec/test/60_usage.yml @@ -0,0 +1,43 @@ +--- +logsdb usage: + - requires: + cluster_features: ["logsdb_telemetry"] + reason: "requires logsdb telemetry" + - do: + indices.create: + index: test1 + body: + settings: + index: + mode: logsdb + + - do: {xpack.usage: {}} + - match: { logsdb.available: true } + - match: { logsdb.enabled: true } + - match: { logsdb.indices_count: 1 } + - match: { logsdb.indices_with_synthetic_source: 1 } + + - do: + indices.create: + index: test2 + + - do: {xpack.usage: {}} + - match: { logsdb.available: true } + - match: { logsdb.enabled: true } + - match: { logsdb.indices_count: 2 } + - match: { logsdb.indices_with_synthetic_source: 1 } + + - do: + indices.create: + index: test3 + body: + settings: + index: + mode: logsdb + mapping.source.mode: stored + + - do: {xpack.usage: {}} + - match: { logsdb.available: true } + - match: { logsdb.enabled: true } + - match: { logsdb.indices_count: 2 } + - match: { logsdb.indices_with_synthetic_source: 1 } diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/logsdb/10_usage.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/logsdb/10_usage.yml new file mode 100644 index 0000000000000..e63c98e55e93f --- /dev/null +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/logsdb/10_usage.yml @@ -0,0 +1,40 @@ +--- +logsdb usage: + - do: + indices.create: + index: test1 + body: + settings: + index: + mode: logsdb + + - do: {xpack.usage: {}} + - match: { logsdb.available: true } + - match: { logsdb.enabled: true } + - match: { logsdb.indices_count: 1 } + - match: { logsdb.indices_with_synthetic_source: 1 } + + - do: + indices.create: + index: test2 + + - do: {xpack.usage: {}} + - match: { logsdb.available: true } + - match: { logsdb.enabled: true } + - match: { logsdb.indices_count: 2 } + - match: { logsdb.indices_with_synthetic_source: 1 } + + - do: + indices.create: + index: test3 + body: + settings: + index: + mode: logsdb + mapping.source.mode: stored + + - do: {xpack.usage: {}} + - match: { logsdb.available: true } + - match: { logsdb.enabled: true } + - match: { logsdb.indices_count: 2 } + - match: { logsdb.indices_with_synthetic_source: 1 }