-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EQL: Add integration tests harness to test EQL feature parity with original implementation #52248
Changes from 1 commit
47aaef7
8631384
cd4a55d
7edf6c7
b6b7f53
595f316
9f3da81
09260e6
2d6111f
6db4617
384cfd8
54035b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.eql.action; | ||
|
||
import org.elasticsearch.action.ActionRequestBuilder; | ||
import org.elasticsearch.client.ElasticsearchClient; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
|
||
public class EqlSearchRequestBuilder extends ActionRequestBuilder<EqlSearchRequest, EqlSearchResponse> { | ||
public EqlSearchRequestBuilder(ElasticsearchClient client, EqlSearchAction action) { | ||
super(client, action, new EqlSearchRequest()); | ||
} | ||
|
||
public EqlSearchRequestBuilder indices(String... indices) { | ||
request.indices(indices); | ||
return this; | ||
} | ||
|
||
public EqlSearchRequestBuilder query(QueryBuilder query) { | ||
request.query(query); | ||
return this; | ||
} | ||
|
||
public EqlSearchRequestBuilder timestampField(String timestampField) { | ||
request.timestampField(timestampField); | ||
return this; | ||
} | ||
|
||
public EqlSearchRequestBuilder eventTypeField(String eventTypeField) { | ||
request.eventTypeField(eventTypeField); | ||
return this; | ||
} | ||
|
||
public EqlSearchRequestBuilder implicitJoinKeyField(String implicitJoinKeyField) { | ||
request.implicitJoinKeyField(implicitJoinKeyField); | ||
return this; | ||
} | ||
|
||
public EqlSearchRequestBuilder fetchSize(int size) { | ||
request.fetchSize(size); | ||
return this; | ||
} | ||
|
||
public EqlSearchRequestBuilder searchAfter(Object[] values) { | ||
request.searchAfter(values); | ||
return this; | ||
} | ||
|
||
public EqlSearchRequestBuilder rule(String rule) { | ||
request.rule(rule); | ||
return this; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,15 @@ | |
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.env.NodeEnvironment; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.plugins.ActionPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.rest.RestController; | ||
import org.elasticsearch.rest.RestHandler; | ||
import org.elasticsearch.script.ScriptService; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.watcher.ResourceWatcherService; | ||
import org.elasticsearch.xpack.core.XPackPlugin; | ||
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction; | ||
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction; | ||
import org.elasticsearch.xpack.eql.EqlInfoTransportAction; | ||
|
@@ -39,12 +41,13 @@ | |
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
public class EqlPlugin extends Plugin implements ActionPlugin { | ||
|
||
private final boolean enabled; | ||
|
||
private static final boolean EQL_FEATURE_FLAG_REGISTERED; | ||
|
||
static { | ||
|
@@ -69,6 +72,10 @@ public class EqlPlugin extends Plugin implements ActionPlugin { | |
Setting.Property.NodeScope | ||
); | ||
|
||
public EqlPlugin(final Settings settings) { | ||
this.enabled = EQL_ENABLED_SETTING.get(settings); | ||
} | ||
|
||
@Override | ||
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, | ||
ResourceWatcherService resourceWatcherService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, | ||
|
@@ -83,17 +90,6 @@ private Collection<Object> createComponents(Client client, String clusterName, N | |
return Arrays.asList(planExecutor); | ||
} | ||
|
||
|
||
@Override | ||
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() { | ||
return Arrays.asList( | ||
new ActionHandler<>(EqlSearchAction.INSTANCE, TransportEqlSearchAction.class), | ||
new ActionHandler<>(EqlStatsAction.INSTANCE, TransportEqlStatsAction.class), | ||
new ActionHandler<>(XPackUsageFeatureAction.EQL, EqlUsageTransportAction.class), | ||
new ActionHandler<>(XPackInfoFeatureAction.EQL, EqlInfoTransportAction.class) | ||
); | ||
} | ||
|
||
/** | ||
* The settings defined by EQL plugin. | ||
* | ||
|
@@ -103,9 +99,21 @@ private Collection<Object> createComponents(Client client, String clusterName, N | |
public List<Setting<?>> getSettings() { | ||
if (isSnapshot() || EQL_FEATURE_FLAG_REGISTERED) { | ||
return List.of(EQL_ENABLED_SETTING); | ||
} else { | ||
return List.of(); | ||
} | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused about why the method was moved... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consistent with other plugins. can undo |
||
if (enabled) { | ||
return List.of( | ||
new ActionHandler<>(EqlSearchAction.INSTANCE, TransportEqlSearchAction.class), | ||
new ActionHandler<>(EqlStatsAction.INSTANCE, TransportEqlStatsAction.class), | ||
new ActionHandler<>(XPackUsageFeatureAction.EQL, EqlUsageTransportAction.class), | ||
new ActionHandler<>(XPackInfoFeatureAction.EQL, EqlInfoTransportAction.class) | ||
); | ||
} | ||
return List.of(); | ||
} | ||
|
||
boolean isSnapshot() { | ||
|
@@ -126,9 +134,12 @@ public List<RestHandler> getRestHandlers(Settings settings, | |
IndexNameExpressionResolver indexNameExpressionResolver, | ||
Supplier<DiscoveryNodes> nodesInCluster) { | ||
|
||
if (isEnabled(settings) == false) { | ||
return Collections.emptyList(); | ||
if (enabled) { | ||
return List.of(new RestEqlSearchAction(), new RestEqlStatsAction()); | ||
} | ||
return Arrays.asList(new RestEqlSearchAction(), new RestEqlStatsAction()); | ||
return List.of(); | ||
} | ||
|
||
// overridable by tests | ||
protected XPackLicenseState getLicenseState() { return XPackPlugin.getSharedLicenseState(); } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,10 @@ | |
|
||
package org.elasticsearch.xpack.eql; | ||
|
||
import org.elasticsearch.common.collect.Tuple; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.xpack.eql.session.Configuration; | ||
import org.elasticsearch.xpack.ql.util.StringUtils; | ||
|
||
import static org.elasticsearch.test.ESTestCase.randomAlphaOfLength; | ||
import static org.elasticsearch.test.ESTestCase.randomBoolean; | ||
|
@@ -31,4 +33,17 @@ public static Configuration randomConfiguration() { | |
randomBoolean(), | ||
randomAlphaOfLength(16)); | ||
} | ||
|
||
public static Tuple<String, String> pathAndName(String string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this method used anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer used indeed, will remove |
||
String folder = StringUtils.EMPTY; | ||
String file = string; | ||
int lastIndexOf = string.lastIndexOf("/"); | ||
if (lastIndexOf > 0) { | ||
folder = string.substring(0, lastIndexOf - 1); | ||
if (lastIndexOf + 1 < string.length()) { | ||
file = string.substring(lastIndexOf + 1); | ||
} | ||
} | ||
return new Tuple<>(folder, file); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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.eql.action; | ||
|
||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.license.LicenseService; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.xpack.core.XPackSettings; | ||
import org.elasticsearch.xpack.eql.plugin.EqlPlugin; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; | ||
|
||
@ESIntegTestCase.ClusterScope(scope = SUITE, numDataNodes = 0, numClientNodes = 0, maxNumDataNodes = 0) | ||
public abstract class AbstractEqlIntegTestCase extends ESIntegTestCase { | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOrdinal) { | ||
Settings.Builder settings = Settings.builder().put(super.nodeSettings(nodeOrdinal)); | ||
settings.put(XPackSettings.SECURITY_ENABLED.getKey(), false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At one point we'll have to test EQL in a security enabled context as well, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably. Was following AbstractSqlIntegTestCase as example in this case. |
||
settings.put(XPackSettings.MONITORING_ENABLED.getKey(), false); | ||
settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false); | ||
settings.put(XPackSettings.GRAPH_ENABLED.getKey(), false); | ||
settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false); | ||
settings.put(EqlPlugin.EQL_ENABLED_SETTING.getKey(), true); | ||
settings.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "trial"); | ||
return settings.build(); | ||
} | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return Collections.singletonList(LocalStateEqlXPackPlugin.class); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either we use
enabled
or this method. On one handenabled
checks the property presence statically but this method tries to do it dynamic when a class is instantiated.There's there are multiple pieces of
isSnapshot
in this class that need simplification.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried to follow the autoscaling plugin pattern, that I was told should be an example of handling the feature flag.