Skip to content

Swallows errors on ml lookups that we know might fail#25783

Merged
jasonrhodes merged 2 commits intoelastic:masterfrom
jasonrhodes:swallow-ml-error
Nov 17, 2018
Merged

Swallows errors on ml lookups that we know might fail#25783
jasonrhodes merged 2 commits intoelastic:masterfrom
jasonrhodes:swallow-ml-error

Conversation

@jasonrhodes
Copy link
Copy Markdown
Member

Closes #23463

Summary

Updated this function to swallow its own errors, and not just 404 status code errors. (Still deciding if this should swallow all or just 4xx errors...)

Adds a test as well.

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

}
throw e;
// swallow error because there are lots of reasons
// the ml index lookup may fail
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm split on leaving it like this, or changing it to:

if (e.statusCode >= 400 && e.statusCode < 500) {
  return null;
}
throw e;

Copy link
Copy Markdown
Contributor

@sorenlouv sorenlouv Nov 16, 2018

Choose a reason for hiding this comment

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

Yeah, blindly swallowing all errors might be a bit much. I think I like your suggestion with only swallowing 4xx errors.

A middle ground could be swallowing all http errors:

if (e.statusCode > 0) {
  return null;
}
throw e;

Promise.reject(new Error('anomaly lookup failed'))
);

expect(getAnomalyAggs({ client: failClient })).resolves.toEqual(null);
Copy link
Copy Markdown
Contributor

@sorenlouv sorenlouv Nov 16, 2018

Choose a reason for hiding this comment

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

Async jest tests are crazy deceiving. You need to return or await your expectation when doing this.

Suggested change
expect(getAnomalyAggs({ client: failClient })).resolves.toEqual(null);
return expect(getAnomalyAggs({ client: failClient })).resolves.toEqual(null);

If you don't return/await the test will always pass regardless. Eg. This tests should not pass but it does:

const failClient = jest.fn(() => Promise.resolve('I am for sure not null'));
expect(getAnomalyAggs({ client: failClient })).resolves.toEqual(null);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ahhh yes, I used to be so good about this but switched to async/await for all my tests and then forgot about it. Will fix, good catch.

@sorenlouv
Copy link
Copy Markdown
Contributor

All comments made

@jasonrhodes
Copy link
Copy Markdown
Member Author

@sqren this should be all set now

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@jasonrhodes jasonrhodes merged commit d188597 into elastic:master Nov 17, 2018
@jasonrhodes jasonrhodes deleted the swallow-ml-error branch November 17, 2018 02:44
jasonrhodes added a commit to jasonrhodes/kibana that referenced this pull request Nov 17, 2018
* Swallows errors on ml lookups that we know can fail

* Adjusts when we swallow ml lookup errors, fixes async test
jasonrhodes added a commit that referenced this pull request Nov 17, 2018
* Swallows errors on ml lookups that we know can fail

* Adjusts when we swallow ml lookup errors, fixes async test
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.

3 participants