Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Fix edge case where entities found for preview is empty #296

Conversation

yizheliu-amazon
Copy link
Contributor

@yizheliu-amazon yizheliu-amazon commented Oct 27, 2020

Issue #, if available:

Description of changes:
Fix edge case where entities found for preview is empty.

Have verified on test domain that empty result is returned with this fix.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Oct 27, 2020

Codecov Report

Merging #296 into master will increase coverage by 0.17%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #296      +/-   ##
============================================
+ Coverage     71.11%   71.29%   +0.17%     
+ Complexity     1873     1869       -4     
============================================
  Files           195      194       -1     
  Lines          9063     9018      -45     
  Branches        766      766              
============================================
- Hits           6445     6429      -16     
+ Misses         2251     2226      -25     
+ Partials        367      363       -4     
Flag Coverage Δ Complexity Δ
#cli 79.27% <ø> (ø) 0.00 <ø> (ø)
#plugin 70.59% <0.00%> (+0.18%) 1869.00 <0.00> (-4.00) ⬆️

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

Impacted Files Coverage Δ Complexity Δ
...stroforelasticsearch/ad/AnomalyDetectorRunner.java 7.50% <0.00%> (-0.20%) 1.00 <0.00> (ø)
...port/SearchAnomalyDetectorInfoTransportAction.java 54.54% <0.00%> (-9.10%) 4.00% <0.00%> (ø%)
...arch/ad/transport/IndexAnomalyDetectorRequest.java 46.80% <0.00%> (-0.26%) 11.00% <0.00%> (-1.00%)
...transport/IndexAnomalyDetectorTransportAction.java 76.47% <0.00%> (ø) 6.00% <0.00%> (ø%)
...asticsearch/ad/transport/SearchAnomalyRequest.java
...search/ad/rest/RestIndexAnomalyDetectorAction.java 46.93% <0.00%> (+0.93%) 3.00% <0.00%> (ø%)
...opendistroforelasticsearch/ad/util/ParseUtils.java 55.97% <0.00%> (+1.13%) 24.00% <0.00%> (+2.00%)
...forelasticsearch/ad/rest/AbstractSearchAction.java 25.00% <0.00%> (+1.47%) 2.00% <0.00%> (ø%)
...stroforelasticsearch/ad/AnomalyDetectorPlugin.java 94.91% <0.00%> (+1.47%) 13.00% <0.00%> (ø%)
...asticsearch/ad/cluster/ADClusterEventListener.java 94.00% <0.00%> (+2.00%) 15.00% <0.00%> (+1.00%)
... and 3 more

@yizheliu-amazon yizheliu-amazon added the bug Something isn't working label Oct 27, 2020
@@ -72,6 +72,9 @@ public void executeDetector(AnomalyDetector detector, Instant startTime, Instant
if (categoryField != null && !categoryField.isEmpty()) {
featureManager.getPreviewEntities(detector, startTime.toEpochMilli(), endTime.toEpochMilli(), ActionListener.wrap(entities -> {

if (entities == null || entities.isEmpty()) {
listener.onResponse(Collections.emptyList());
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Such failure will be caught and empty result is still returned instead in onFailure()

I think it is okay to just return empty result

Copy link
Member

Choose a reason for hiding this comment

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

Could you tell me why it would end up calling onFailure? listener is the rest channel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If entities is empty, code execution won't go into the for loop below, and listener has no chance to call onFailure or onResponse

Copy link
Member

Choose a reason for hiding this comment

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

I feel it is better to return some failure and show that on kibana than return empty result. Customers may wonder why it returns nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if empty list is returned, existing Kibana will show corresponding message.

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment explaining why we want to return empty responses instead of errors? It helps code readability.

@yizheliu-amazon yizheliu-amazon merged commit ff9e3bf into opendistro-for-elasticsearch:master Oct 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants