Skip to content

Initial EQL rest API implementation #49768

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

Merged
merged 3 commits into from
Jan 3, 2020

Conversation

aleksmaus
Copy link
Contributor

It's my first PR, need a bit of feedback on the code shape and direction.
Specifically had to poke through RBACEngine.java and “mark” the request with CompositeIndicesRequest interface, not sure if this is the right approach.

@aleksmaus aleksmaus requested a review from costin December 2, 2019 15:23
@@ -212,6 +212,7 @@ private static boolean shouldAuthorizeIndexActionNameOnly(String action, Transpo
case "indices:data/write/reindex":
case "indices:data/read/sql":
case "indices:data/read/sql/translate":
case "indices:data/read/eql":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was not sure if there is a better approach instead of this ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we need this here. I don't see a scenario when we are going to resolve the index name based on the content of the request itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this change, replacing with more suitable solution after discussion with Igor.

@aleksmaus aleksmaus added the WIP label Dec 2, 2019
@aleksmaus aleksmaus force-pushed the feature/eql_rest branch 2 times, most recently from a32e29a to bcf861b Compare December 3, 2019 21:25
@aleksmaus aleksmaus removed the WIP label Dec 18, 2019
@aleksmaus aleksmaus requested a review from imotov December 18, 2019 02:55
@aleksmaus aleksmaus marked this pull request as ready for review December 18, 2019 02:55
@@ -887,7 +887,7 @@ public boolean equals(Object obj) {
&& Objects.equals(seqNo, other.seqNo)
&& Objects.equals(primaryTerm, other.primaryTerm)
&& Objects.equals(source, other.source)
&& Objects.equals(fields, other.fields)
&& Objects.equals(getFields(), other.getFields())
Copy link
Contributor Author

@aleksmaus aleksmaus Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A possible fix for equals as a separate commit here, can remove if not appropriate or should be it's own separate PR.
Sharing the same SearchHit structures in the eql resful API implementation, and the equality checks would fail without this change in place.
Following the same thing that was done a line below with highlightFields accessors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a bit cleaner to make this a separate PR to master and 7.x and then merge it in. In any case, I think this requires a modification to SearchHitTests that would trigger the issue that you are trying to fix here.

Copy link
Contributor Author

@aleksmaus aleksmaus Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, will update this PR once this change goes through the master.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file change is removed now from PR.

@aleksmaus aleksmaus added the WIP label Dec 18, 2019
@aleksmaus aleksmaus changed the title Initial EQL rest API stub Initial EQL rest API implementation Dec 18, 2019
@aleksmaus
Copy link
Contributor Author

  • Removed the SearchHit.java change. It will go through master branch.
  • Updated the unit test for now to always create SearchHit with fields.
  • Squashed and force pushed.

@aleksmaus
Copy link
Contributor Author

aleksmaus commented Dec 18, 2019

Pulled the latest master to feature/eql and rebased my PR against it, cause of build failures due to java version
21:07:03 Caused by: org.gradle.api.GradleException: JAVA13_HOME required to run task: 21:07:03 task ':distribution:bwc:minor:buildBwcOssLinuxTar'

master branch was on Java 13 already

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/EQL)

Copy link
Contributor

@imotov imotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add a rest client and add some rest level tests to make sure it works end-to-end?

public class EqlPlugin extends Plugin implements ActionPlugin {
@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return Arrays.asList(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably replace it with Collections.singletonList() here and below since we don't anticipate more actions here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought there was a possibility of one more "translate" action down the road.


@Override
public ActionRequestValidationException validate() {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we rely on the fact that index, timestampField, eventTypeField, etc cannot be null and fetchSize cannot be negative, we should validate that it's indeed the case. We could also make serialization more forgiving and avoid serializing the same default values on every request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add validation code

@@ -212,6 +212,7 @@ private static boolean shouldAuthorizeIndexActionNameOnly(String action, Transpo
case "indices:data/write/reindex":
case "indices:data/read/sql":
case "indices:data/read/sql/translate":
case "indices:data/read/eql":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we need this here. I don't see a scenario when we are going to resolve the index name based on the content of the request itself.

// Not sure yet if we will always have index in the path or not
// TODO: finalize the endpoints
controller.registerHandler(GET, "/{index}/_eql/search", this);
controller.registerHandler(GET, "/_eql/search", this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most cases, if the index name is not specified on the URL we search all indices or use index specified inside the request. In this case I don't think we will ever search all indices and I don't see any provisions from specifying the index name inside the request. So, I think we can remove this version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there was like going back-n-forth on this, so included both versions. Will remove the latter.

@@ -49,15 +49,15 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
* {@link XContent} outputs we can't use {@link RestToXContentListener}
* like everything else. We want to stick as closely as possible to
* Elasticsearch's defaults though, while still layering in ways to
* control the output more easilly.
* control the output more easily.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this file into a separate trivial PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will revert this file change from this PR.

@aleksmaus
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/1

Copy link
Contributor

@imotov imotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@aleksmaus aleksmaus merged commit c0f048a into elastic:feature/eql Jan 3, 2020
aleksmaus added a commit to aleksmaus/elasticsearch that referenced this pull request Jan 27, 2020
@aleksmaus aleksmaus mentioned this pull request Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/EQL EQL querying
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants