-
Notifications
You must be signed in to change notification settings - Fork 25.3k
ESQL: List/get query API #124832
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
ESQL: List/get query API #124832
Changes from 1 commit
d6b0a92
d961e27
55e7625
8ad4d6d
fd08751
f1aab5d
af2b5ee
1d95cbc
cb4ec47
2fa0085
ff0fe90
758319a
894dad6
30f5ef1
9bcdb10
6686702
9847add
1d0d15c
9fe9243
f786222
6134a8e
789362f
0cedb9a
09dc300
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* 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.esql.action; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.xpack.esql.plugin.EsqlGetQueryResponse; | ||
|
||
public class EsqlGetQueryAction extends ActionType<EsqlGetQueryResponse> { | ||
public static final EsqlGetQueryAction INSTANCE = new EsqlGetQueryAction(); | ||
public static final String NAME = "cluster:data/read/esql/query"; | ||
|
||
private EsqlGetQueryAction() { | ||
super(NAME); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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.esql.action; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
public class EsqlGetQueryRequest extends ActionRequest { | ||
private final String id; | ||
|
||
public EsqlGetQueryRequest(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String id() { | ||
return id; | ||
} | ||
|
||
public EsqlGetQueryRequest(StreamInput streamInput) throws IOException { | ||
super(streamInput); | ||
id = streamInput.readString(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(id); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* 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.esql.action; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.xpack.esql.plugin.EsqlListQueriesResponse; | ||
|
||
public class EsqlListQueriesAction extends ActionType<EsqlListQueriesResponse> { | ||
public static final EsqlListQueriesAction INSTANCE = new EsqlListQueriesAction(); | ||
public static final String NAME = "cluster:data/read/esql/queries"; | ||
|
||
private EsqlListQueriesAction() { | ||
super(NAME); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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.esql.action; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
|
||
import java.io.IOException; | ||
|
||
public class EsqlListQueriesRequest extends ActionRequest { | ||
public EsqlListQueriesRequest() {} | ||
|
||
public EsqlListQueriesRequest(StreamInput streamInput) throws IOException { | ||
super(streamInput); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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.esql.action; | ||
|
||
import org.elasticsearch.client.internal.node.NodeClient; | ||
import org.elasticsearch.logging.LogManager; | ||
import org.elasticsearch.logging.Logger; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.Scope; | ||
import org.elasticsearch.rest.ServerlessScope; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.rest.RestRequest.Method.GET; | ||
|
||
@ServerlessScope(Scope.PUBLIC) | ||
public class RestEsqlListQueriesAction extends BaseRestHandler { | ||
private static final Logger LOGGER = LogManager.getLogger(RestEsqlListQueriesAction.class); | ||
|
||
@Override | ||
public String getName() { | ||
return "esql_list_queries"; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of(new Route(GET, "/_query/queries/{id}"), new Route(GET, "/_query/queries")); | ||
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. The repetition in the endpoint looks surprising to me. Why not 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. 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. For the time being we're looking to keep the ESQL APIs under the ESQL prefix( 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. Let's sort this one out after this PR. 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. We can move this - we haven't finalized this API. |
||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
return restChannelConsumer(request, client); | ||
} | ||
|
||
private static RestChannelConsumer restChannelConsumer(RestRequest request, NodeClient client) { | ||
LOGGER.debug("Beginning execution of ESQL list queries."); | ||
|
||
String id = request.param("id"); | ||
return id != null | ||
? (channel -> client.execute(EsqlGetQueryAction.INSTANCE, new EsqlGetQueryRequest(id), new RestToXContentListener<>(channel))) | ||
: (channel -> client.execute( | ||
EsqlListQueriesAction.INSTANCE, | ||
new EsqlListQueriesRequest(), | ||
new RestToXContentListener<>(channel) | ||
)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.esql.plugin; | ||
|
||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class EsqlGetQueryResponse extends ActionResponse implements ToXContentObject { | ||
// This is rather limited at the moment, as we don't extract information such as CPU and memory usage, owning user, etc. for the task. | ||
public record DetailedQuery( | ||
String id, | ||
long startTimeMillis, | ||
long runningTimeNanos, | ||
String query, | ||
String coordinatingNode, | ||
List<String> dataNodes | ||
) implements Writeable, ToXContentObject { | ||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(id); | ||
out.writeLong(startTimeMillis); | ||
out.writeLong(runningTimeNanos); | ||
out.writeString(query); | ||
out.writeString(coordinatingNode); | ||
out.writeStringCollection(dataNodes); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field("id", id); | ||
builder.field("startTimeMillis", startTimeMillis); | ||
builder.field("runningTimeNanos", runningTimeNanos); | ||
builder.field("query", query); | ||
builder.field("coordinatingNode", coordinatingNode); | ||
builder.field("dataNodes", dataNodes); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} | ||
|
||
private final DetailedQuery query; | ||
|
||
public EsqlGetQueryResponse(DetailedQuery query) { | ||
this.query = query; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeWriteable(query); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return query.toXContent(builder, params); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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.esql.plugin; | ||
|
||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class EsqlListQueriesResponse extends ActionResponse implements ToXContentObject { | ||
private final List<Query> queries; | ||
|
||
public record Query(String id, long startTimeMillis, long runningTimeNanos, String query) implements Writeable, ToXContentObject { | ||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(id); | ||
out.writeLong(startTimeMillis); | ||
out.writeLong(runningTimeNanos); | ||
out.writeString(query); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field("id", id); | ||
builder.field("startTimeMillis", startTimeMillis); | ||
builder.field("runningTimeNanos", runningTimeNanos); | ||
builder.field("query", query); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} | ||
|
||
public EsqlListQueriesResponse(List<Query> queries) { | ||
this.queries = queries; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeCollection(queries); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject("queries"); | ||
idegtiarenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// for (Query query : queries) { | ||
// query.toXContent(builder, params); | ||
// } | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
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.
I wonder if we should rely on org.elasticsearch.transport.EmptyRequest instead?
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.
It looks like that's a test class... is it used in production?