Skip to content
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

Introduce async search status API #62947

Merged
merged 6 commits into from
Nov 3, 2020

Conversation

mayya-sharipova
Copy link
Contributor

@mayya-sharipova mayya-sharipova commented Sep 28, 2020

Introduce async search status API

GET /_async_search/status/

The API is restricted to the monitoring_user role.


Revised version:

For a running async search, the response is:

{
  "id" : <id>,
  "is_running" : true,
  "is_partial" : true,
  "start_time_in_millis" : 1583945890986,
  "expiration_time_in_millis" : 1584377890986,
  "_shards" : {
      "total" : 562,
      "successful" : 188,
      "skipped" : 0,
      "failed" : 0
  }
}

For a completed async search, an additional
completion_status fields is added.

{
  "id" : <id>,
  "is_running" : false,
  "is_partial" : false,
  "start_time_in_millis" : 1583945890986,
  "expiration_time_in_millis" : 1584377890986,
  "_shards" : {
      "total" : 562,
      "successful" : 562,
      "skipped" : 0,
      "failed" : 0
  },
 "completion_status" : 200
}

Old version:

For a running async search, the response is:

{
  "id" : <id>,
  "is_running" : true,
  "start_time_in_millis" : 1583945890986,
  "expiration_time_in_millis" : 1584377890986,
  "_shards" : {
      "total" : 562,
      "successful" : 188,
      "skipped" : 0,
      "failed" : 0
  }
}

For a completed async search, the response is:

{
  "id" : <id>
  "is_running" : false,
  "expiration_time_in_millis" : 1584377890986
}

Techincal details:
We first try to retrieve the status of the async search from tasks.
If this doesn't succeed, we retrieve it from an index: .async-search.
In case of retrieving from the index, we assume that the async search is
completed, and a shorter response for the status is returned.

Closes #57537

@mayya-sharipova mayya-sharipova added the :Search/Search Search-related issues that do not fall into other categories label Sep 28, 2020
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Sep 28, 2020
@mayya-sharipova mayya-sharipova added v8.0.0 v7.10.0 >feature and removed Team:Search Meta label for search team labels Sep 28, 2020
Introduce async search status API

GET /_async_search/status/<id>

The API is restricted to the monitoring_user role.

For a running async search, the response is:

```js
{
  "id" : <id>,
  "is_running" : true,
  "start_time_in_millis" : 1583945890986,
  "expiration_time_in_millis" : 1584377890986,
  "_shards" : {
      "total" : 562,
      "successful" : 188,
      "skipped" : 0,
      "failed" : 0
  }
}
```

For a completed async search, the response is:

```js
{
  "id" : <id>
  "is_running" : false,
  "expiration_time_in_millis" : 1584377890986
}
```

----
Techincal details:
We first try to retrieve the status of the async search from tasks.
If this doesn't succeed, we retrieve it from an index: .async-search.
In case of retrieving from the index, we assume that the async search is
completed, and a shorter response for the status is returned.

Closes elastic#57537
@mayya-sharipova
Copy link
Contributor Author

mayya-sharipova commented Sep 28, 2020

@lizozom I am interested in your feedback on the API above. It returns a more detailed status response for a running async search, and a shorter version for a completed search. Will it suit your needs?

@andreidan andreidan added v7.11.0 and removed v7.10.0 labels Oct 7, 2020
Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

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

Sorry for the late review @mayya-sharipova , I did a first pass and left some comments.

* @param expirationTime – expiration time of async search request
* @return response representing the status of async search
*/
AsyncStatusResponse toStatusResponse(String asyncExecutionId, long startTime, long expirationTime) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method should be synchronized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Jim, good comment. I have made some variables volatile and I believe it doesn't need synchronization any more.

* is registered in the task manager, <code>null</code> otherwise.
*
*/
<T extends AsyncTask> T getTaskStatus(TaskManager taskManager, AsyncExecutionId asyncExecutionId, Class<T> tClass) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add an option on getTask instead to enable/disable the authentication check ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment, @jimczi . I have talked to @albertzaharovits about this sometime ago, and he suggested me from a security point of view to use a separate method instead of adding a parameter to enable/disable authentication.

I ended up moving the logic of this method to TransportGetAsyncStatusAction in order to avoid parametrized function arguments.

* @param listener – listener to report result to
*/
public void getStatusResponse(
AsyncExecutionId asyncExecutionId, BiFunction<String, Long, R> completedStatusProducer, ActionListener<R> listener) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we reuse getEncodedResponse ? We'd need to disable the authentication check but that can be an option on the function directly ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similarly to a previous comment, I opted out to have a separate method for this . Please let me know if we still want to have a single method.

docs/reference/search/async-search.asciidoc Show resolved Hide resolved
@mayya-sharipova
Copy link
Contributor Author

mayya-sharipova commented Oct 20, 2020

@jimczi Jim, thanks for your review, I will go through it, and address it.

I have another question. It seems that @lizozom and her team are interested in the BULK API for status. I remember we've discussed it, and we came to the conclusion that since we don't have a bulk API for _async_search, we did not want to introduce a bulk API for _async_search/status.
But thinking about this again, it is unlikely that a user ever wants to use a bulk API for _async_search, while a bulk API for _async_search/status seems to be very useful for Kibana.

@jimczi WDYT? Should we reconsider and add a bulk API for _async_search/status?

The API can look like this:

GET /_async_search/status/
{
  "ids" : [<id1>, <id2>]
}

If we decide to go for a bulk version, we can remove a single version where id is provided in the URL.

@jimczi
Copy link
Contributor

jimczi commented Oct 20, 2020

Should we reconsider and add a bulk API for _async_search/status?

I think that we should first agreed on the metadata that we output for a single status. Once the format is settled, we can discuss whether a bulk format is needed or not but for now I think it's ok to focus on the API to get the status for a single search.

@mayya-sharipova
Copy link
Contributor Author

@lizozom @jimczi Thank you for your feedback, I have tried to address them in the last commit. Please continue the review when you have time

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

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

The change looks good but I left some comments that need to be addressed.

docs/reference/search/async-search.asciidoc Outdated Show resolved Hide resolved
private final int successfulShards;
private final int skippedShards;
private final int failedShards;
private final RestStatus completionStatus;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can return the status for partial response too ?

@mayya-sharipova
Copy link
Contributor Author

@jimczi Thanks for another round of feedback. I have tried to address all your comments in 1e427d5 , except the status of a partial search response, which is up for discussion.

Copy link
Contributor

@jimczi jimczi 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 @mayya-sharipova!

if (queryFailures == null) {
return 0;
}
int count = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can do return queryFailures.asList().size() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jimczi Thanks for the suggestion. It seems that asList() method creates a additional list object. Instead, in 39dafa9, I've added AtomicArray::nonNullLength method.

@mayya-sharipova
Copy link
Contributor Author

@lizozom I am wondering if you are ok with the format of the revised version of status response?

Copy link

@lizozom lizozom 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 for the revision

@mayya-sharipova mayya-sharipova merged commit 074f7d2 into elastic:master Nov 3, 2020
@mayya-sharipova mayya-sharipova deleted the async-metadata branch November 3, 2020 16:35
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this pull request Nov 3, 2020
Introduce async search status API

GET /_async_search/status/<id>

The API is restricted to the monitoring_user role.

For a running async search, the response is:

```js
{
  "id" : <id>,
  "is_running" : true,
  "is_partial" : true,
  "start_time_in_millis" : 1583945890986,
  "expiration_time_in_millis" : 1584377890986,
  "_shards" : {
      "total" : 562,
      "successful" : 188,
      "skipped" : 0,
      "failed" : 0
  }
}
```

For a completed async search, an additional
`completion_status` fields is added.

```js
{
  "id" : <id>,
  "is_running" : false,
  "is_partial" : false,
  "start_time_in_millis" : 1583945890986,
  "expiration_time_in_millis" : 1584377890986,
  "_shards" : {
      "total" : 562,
      "successful" : 562,
      "skipped" : 0,
      "failed" : 0
  },
 "completion_status" : 200
}
```

Closes elastic#57537
Backport for elastic#62947
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this pull request Nov 3, 2020
mayya-sharipova added a commit that referenced this pull request Nov 3, 2020
Introduce async search status API

GET /_async_search/status/<id>

The API is restricted to the monitoring_user role.

For a running async search, the response is:

```js
{
  "id" : <id>,
  "is_running" : true,
  "is_partial" : true,
  "start_time_in_millis" : 1583945890986,
  "expiration_time_in_millis" : 1584377890986,
  "_shards" : {
      "total" : 562,
      "successful" : 188,
      "skipped" : 0,
      "failed" : 0
  }
}
```

For a completed async search, an additional
`completion_status` fields is added.

```js
{
  "id" : <id>,
  "is_running" : false,
  "is_partial" : false,
  "start_time_in_millis" : 1583945890986,
  "expiration_time_in_millis" : 1584377890986,
  "_shards" : {
      "total" : 562,
      "successful" : 562,
      "skipped" : 0,
      "failed" : 0
  },
 "completion_status" : 200
}
```

Closes #57537
Backport for #62947
@pugnascotia pugnascotia changed the title Async search status Introduce async search status API Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature :Search/Search Search-related issues that do not fall into other categories v7.11.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose _async_search metadata to kibana admin user
6 participants