diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/telemetry/FeatureMetric.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/telemetry/FeatureMetric.java index 3a36f5b0d7c04..c55996a1e3be1 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/telemetry/FeatureMetric.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/telemetry/FeatureMetric.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.esql.telemetry; +import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException; import org.elasticsearch.xpack.esql.plan.logical.Aggregate; import org.elasticsearch.xpack.esql.plan.logical.Dissect; import org.elasticsearch.xpack.esql.plan.logical.Drop; @@ -15,15 +16,24 @@ import org.elasticsearch.xpack.esql.plan.logical.Eval; import org.elasticsearch.xpack.esql.plan.logical.Filter; import org.elasticsearch.xpack.esql.plan.logical.Grok; +import org.elasticsearch.xpack.esql.plan.logical.InlineStats; +import org.elasticsearch.xpack.esql.plan.logical.Insist; import org.elasticsearch.xpack.esql.plan.logical.Keep; +import org.elasticsearch.xpack.esql.plan.logical.Limit; import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; +import org.elasticsearch.xpack.esql.plan.logical.Lookup; import org.elasticsearch.xpack.esql.plan.logical.MvExpand; import org.elasticsearch.xpack.esql.plan.logical.OrderBy; +import org.elasticsearch.xpack.esql.plan.logical.Project; import org.elasticsearch.xpack.esql.plan.logical.Rename; import org.elasticsearch.xpack.esql.plan.logical.Row; +import org.elasticsearch.xpack.esql.plan.logical.UnresolvedRelation; +import org.elasticsearch.xpack.esql.plan.logical.join.LookupJoin; +import org.elasticsearch.xpack.esql.plan.logical.local.EsqlProject; import org.elasticsearch.xpack.esql.plan.logical.show.ShowInfo; import java.util.BitSet; +import java.util.List; import java.util.Locale; import java.util.function.Predicate; @@ -42,7 +52,21 @@ public enum FeatureMetric { FROM(EsRelation.class::isInstance), DROP(Drop.class::isInstance), KEEP(Keep.class::isInstance), - RENAME(Rename.class::isInstance); + RENAME(Rename.class::isInstance), + LOOKUP_JOIN(LookupJoin.class::isInstance), + LOOKUP(Lookup.class::isInstance), + INLINESTATS(InlineStats.class::isInstance), + INSIST(Insist.class::isInstance); + + /** + * List here plans we want to exclude from telemetry + */ + private static final List> excluded = List.of( + UnresolvedRelation.class, + EsqlProject.class, + Project.class, + Limit.class // LIMIT is managed in another way, see above + ); private Predicate planCheck; @@ -61,6 +85,13 @@ public static void set(LogicalPlan plan, BitSet bitset) { return; } } + if (explicitlyExcluded(plan) == false) { + throw new EsqlIllegalArgumentException("Command not mapped for telemetry [{}]", plan.getClass().getSimpleName()); + } + } + + private static boolean explicitlyExcluded(LogicalPlan plan) { + return excluded.stream().anyMatch(x -> x.isInstance(plan)); } public static boolean set(LogicalPlan plan, BitSet bitset, FeatureMetric metric) { diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml index 4e2215e0f9300..4221e4383b88b 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml @@ -37,7 +37,7 @@ setup: - do: {xpack.usage: {}} - match: { esql.available: true } - match: { esql.enabled: true } - - length: { esql.features: 15 } + - length: { esql.features: 19 } - set: {esql.features.dissect: dissect_counter} - set: {esql.features.drop: drop_counter} - set: {esql.features.eval: eval_counter} @@ -53,6 +53,10 @@ setup: - set: {esql.features.sort: sort_counter} - set: {esql.features.stats: stats_counter} - set: {esql.features.where: where_counter} + - set: {esql.features.lookup_join: lookup_join_counter} + - set: {esql.features.lookup: lookup_counter} + - set: {esql.features.inlinestats: inlinestats_counter} + - set: {esql.features.insist: insist_counter} - length: { esql.queries: 3 } - set: {esql.queries.rest.total: rest_total_counter} - set: {esql.queries.rest.failed: rest_failed_counter} @@ -81,6 +85,10 @@ setup: - gt: {esql.features.sort: $sort_counter} - gt: {esql.features.stats: $stats_counter} - gt: {esql.features.where: $where_counter} + - match: {esql.features.lookup_join: $lookup_join_counter} + - match: {esql.features.lookup: $lookup_counter} + - match: {esql.features.inlinestats: $inlinestats_counter} + - match: {esql.features.insist: $insist_counter} - gt: {esql.queries.rest.total: $rest_total_counter} - match: {esql.queries.rest.failed: $rest_failed_counter} - match: {esql.queries.kibana.total: $kibana_total_counter} @@ -109,7 +117,7 @@ setup: - do: {xpack.usage: {}} - match: { esql.available: true } - match: { esql.enabled: true } - - length: { esql.features: 15 } + - length: { esql.features: 19 } - set: {esql.features.dissect: dissect_counter} - set: {esql.features.drop: drop_counter} - set: {esql.features.eval: eval_counter} @@ -125,6 +133,10 @@ setup: - set: {esql.features.sort: sort_counter} - set: {esql.features.stats: stats_counter} - set: {esql.features.where: where_counter} + - set: {esql.features.lookup_join: lookup_join_counter} + - set: {esql.features.lookup: lookup_counter} + - set: {esql.features.inlinestats: inlinestats_counter} + - set: {esql.features.insist: insist_counter} - length: { esql.queries: 3 } - set: {esql.queries.rest.total: rest_total_counter} - set: {esql.queries.rest.failed: rest_failed_counter} @@ -153,6 +165,10 @@ setup: - gt: {esql.features.sort: $sort_counter} - gt: {esql.features.stats: $stats_counter} - gt: {esql.features.where: $where_counter} + - match: {esql.features.lookup_join: $lookup_join_counter} + - match: {esql.features.lookup: $lookup_counter} + - match: {esql.features.inlinestats: $inlinestats_counter} + - match: {esql.features.insist: $insist_counter} - gt: {esql.queries.rest.total: $rest_total_counter} - match: {esql.queries.rest.failed: $rest_failed_counter} - match: {esql.queries.kibana.total: $kibana_total_counter}