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

[Extensions] Migrates Search, SearchResults and SearchADTasks action to extensions #849

Merged

Conversation

owaiskazi19
Copy link
Member

@owaiskazi19 owaiskazi19 commented Mar 29, 2023

Description

This PR migrates SearchDetector, SearchResultAnomalyDetector and SearchADTasks to extension for GET and POST request.

  • Tested Search Detector for GET and POST.
GET /_extensions/_ad-extension/detectors/_search
POST /_extensions/_ad-extension/detectors/_search
POST /_extensions/_ad-extension/detectors/results/_search/
POST /_extensions/_ad-extension/detectors/results/_search/<custom_result_index>
POST /_extensions/_ad-extension/detectors/results/_search/<custom_result_index>?only_query_custom_result_index=false
POST /_extensions/_ad-extension/detectors/results/_search/<custom_result_index>?only_query_custom_result_index=true
  • Tested Search AD Tasks
GET _plugins/_anomaly_detection/detectors/tasks/_search
POST _plugins/_anomaly_detection/detectors/tasks/_search

Issues Resolved

Part of opensearch-project/opensearch-sdk-java#376, opensearch-project/opensearch-sdk-java#377 and opensearch-project/opensearch-sdk-java#380

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@Override
public RestResponse buildResponse(SearchResponse response) throws Exception {
protected ExtensionRestResponse search(ExtensionRestRequest request, SearchResponse response) throws IOException {
// return new RestResponseListener<SearchResponse>(channel) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@dbwiddis need some suggestion here. Do we require a Transport API for RestResponseListener or CompletableFuture should be enough?

Copy link
Member

Choose a reason for hiding this comment

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

@owaiskazi19 I'm not sure I understand the question here. Is this a situation where we have a long-running request?

My initial thoughts are "wait some reasonable timeout for a fast request, if it's done send the search response, if not, send a response containing information to access the results later".

Copy link
Member Author

Choose a reason for hiding this comment

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

Does that mean CompletableFuture should be enough to handle the RestResponseListener here?

@owaiskazi19 owaiskazi19 force-pushed the search-detectors branch 4 times, most recently from 6d065ec to fd57c8c Compare April 5, 2023 19:00
@owaiskazi19 owaiskazi19 force-pushed the search-detectors branch 3 times, most recently from f57529f to bc315cd Compare April 8, 2023 00:53
@codecov-commenter
Copy link

codecov-commenter commented Apr 8, 2023

Codecov Report

Merging #849 (42e9dcc) into feature/extensions (8b31c13) will decrease coverage by 0.05%.
The diff coverage is 1.66%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Impacted file tree graph

@@                   Coverage Diff                    @@
##             feature/extensions     #849      +/-   ##
========================================================
- Coverage                 35.96%   35.91%   -0.05%     
- Complexity                 1916     1917       +1     
========================================================
  Files                       299      299              
  Lines                     17615    17645      +30     
  Branches                   1862     1861       -1     
========================================================
+ Hits                       6335     6337       +2     
- Misses                    10825    10854      +29     
+ Partials                    455      454       -1     
Flag Coverage Δ
plugin 35.91% <1.66%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...va/org/opensearch/ad/AnomalyDetectorExtension.java 0.00% <0.00%> (ø)
...a/org/opensearch/ad/rest/AbstractSearchAction.java 0.00% <0.00%> (ø)
...rg/opensearch/ad/rest/RestSearchADTasksAction.java 0.00% <ø> (ø)
...earch/ad/rest/RestSearchAnomalyDetectorAction.java 0.00% <ø> (ø)
...nsearch/ad/rest/RestSearchAnomalyResultAction.java 0.00% <0.00%> (ø)
...rch/ad/transport/SearchADTasksTransportAction.java 0.00% <0.00%> (ø)
...ransport/SearchAnomalyDetectorTransportAction.java 0.00% <0.00%> (ø)
.../transport/SearchAnomalyResultTransportAction.java 0.00% <0.00%> (ø)
...ensearch/ad/transport/handler/ADSearchHandler.java 69.56% <100.00%> (ø)

... and 1 file with indirect coverage changes

@owaiskazi19 owaiskazi19 marked this pull request as ready for review April 12, 2023 22:06
@owaiskazi19 owaiskazi19 requested a review from a team April 12, 2023 22:06
@joshpalis joshpalis self-requested a review April 14, 2023 17:44
public class SearchAnomalyDetectorAction extends ActionType<SearchResponse> {
// External Action which used for public facing RestAPIs.
public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "detector/search";
public static final SearchAnomalyDetectorAction INSTANCE = new SearchAnomalyDetectorAction();

@Inject
Copy link
Member

Choose a reason for hiding this comment

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

Im curious about the purpose of adding an inject annotation to a no arg constructor

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call out. Removed it.

public class SearchAnomalyResultAction extends ActionType<SearchResponse> {
// External Action which used for public facing RestAPIs.
public static final String NAME = CommonValue.EXTERNAL_ACTION_PREFIX + "result/search";
public static final SearchAnomalyResultAction INSTANCE = new SearchAnomalyResultAction();

@Inject
Copy link
Member

Choose a reason for hiding this comment

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

same here

private volatile Boolean filterEnabled;

public ADSearchHandler(Settings settings, ClusterService clusterService, Client client) {
@Inject
Copy link
Member

Choose a reason for hiding this comment

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

I see that we're returning this object as part of create components, there's no need to add this inject annotation here. I may be wrong though, for my own learnings, what's the reason for this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right. Removed it. I'm a beginner in Guice and learning it step by step. 😄

@owaiskazi19 owaiskazi19 force-pushed the search-detectors branch 4 times, most recently from e465480 to 64f0abb Compare April 15, 2023 00:27
Copy link
Member

@joshpalis joshpalis left a comment

Choose a reason for hiding this comment

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

Other than a minor nit, looks good to me

Settings settings = Settings.EMPTY;
List<Setting<?>> settingsList = List.of(AnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW, AnomalyDetectorSettings.PAGE_SIZE);
clusterService = mock(SDKClusterService.class);
;
Copy link
Member

Choose a reason for hiding this comment

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

seems like a stray semicolon :)

@owaiskazi19 owaiskazi19 merged commit 86b1084 into opensearch-project:feature/extensions Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants